USE [DBADI]
GO
/****** Object:  UserDefinedFunction [dbo].[Brut]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Function [dbo].[Brut](@Net DECIMAL(14,2),@KGVM  DECIMAL(14,2),@SGKMatrah DECIMAL(14,2), @YIL INT, @FIRMAID INT)
Returns DECIMAL(14,2)
As
Begin
DECLARE @Hesapla1  DECIMAL(14,2)
DECLARE @Hesapla2  DECIMAL(14,2)
DECLARE @COUNT INT = 1
DECLARE @BRUT  DECIMAL(14,2)

SET @Hesapla1 = @Net*2

WHILE @COUNT < 100
BEGIN
SET @Hesapla2 = dbo.NetBul(@Hesapla1, @KGVM, @SGKMatrah,@YIL,@FIRMAID)
IF(@Hesapla2 = @Net )
BEGIN
SET @BRUT = @Hesapla1
END
ELSE
BEGIN
SET @Hesapla1 = @Hesapla1 - (@Hesapla2-@Net)
END
SET @COUNT += 1;
END
SET @BRUT=@Hesapla1
return @BRUT
End
GO
/****** Object:  UserDefinedFunction [dbo].[FN_AYADI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_AYADI]  
  (@AY INTEGER)    RETURNS NVARCHAR(20) AS  

   BEGIN  

    RETURN  

      CASE @AY        WHEN  1 THEN ' 1:Oca'  

                      WHEN  2 THEN ' 2:Şub'  

                      WHEN  3 THEN ' 3:Mar'  

                      WHEN  4 THEN ' 4:Nis'  

                      WHEN  5 THEN ' 5:May'  

                      WHEN  6 THEN ' 6:Haz'  

                      WHEN  7 THEN ' 7:Tem'  

                      WHEN  8 THEN ' 8:Ağu'  

                      WHEN  9 THEN ' 9:Eyl'  

                      WHEN 10 THEN '10:Eki'  

                      WHEN 11 THEN '11:Kas'  

                      WHEN 12 THEN '12:Ara'  

      END  

   END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_AYISMI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_AYISMI]  
  (@AY INTEGER)    RETURNS NVARCHAR(20)   AS  BEGIN     RETURN     CASE @AY    

       WHEN 1 THEN '01 Ocak'      

           WHEN 2 THEN '02 Şubat'    

                WHEN 3 THEN '03 Mart'    

                     WHEN 4 THEN '04 Nisan'  

                            WHEN 5 THEN '05 Mayıs'      

                               WHEN 6 THEN '06 Haziran'       

                                 WHEN 7 THEN '07 Temmuz'     

                                     WHEN 8 THEN '08 Ağustos'     

                                         WHEN 9 THEN '09 Eylül'      

                                             WHEN 10 THEN '10 Ekim'    

                                                  WHEN 11 THEN '11 Kasım'   

                                                        WHEN 12 THEN '12 Aralık'     END  END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_BARKODBUL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_BARKODBUL]  
 (@FIRMAID INT)
 RETURNS  NVARCHAR(10)
 AS
 BEGIN
 DECLARE @SONBARKOD INT
	SELECT @SONBARKOD=BARKOD FROM FIRMABARKOD WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0
	RETURN ISNULL(CAST(@SONBARKOD AS NVARCHAR(10)),'')
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_BARKODBUL2]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_BARKODBUL2]  
 (@FIRMAID INT, @TUR NVARCHAR(10))
 RETURNS  NVARCHAR(20)
 AS
 BEGIN
 DECLARE @SONBARKOD BIGINT
	SELECT @SONBARKOD=(CASE WHEN LEN(BARKOD)=7 THEN CAST(BARKOD AS NVARCHAR(7))+dbo.FN_EAN8KONTROL(BARKOD) ELSE BARKOD END) 
	FROM FIRMABARKOD WHERE TUR=@TUR AND FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0
	RETURN ISNULL(CAST(@SONBARKOD AS NVARCHAR(20)),'')
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_EAN8KONTROL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_EAN8KONTROL] (@BARKOD NVARCHAR(7))
 RETURNS  NVARCHAR(10)
 AS
 BEGIN
	DECLARE
	@TEK INT,
	@CIFT INT,
	@SONUC INT,
	@DEGER NVARCHAR(10)
	SET @CIFT=CAST(CAST(SUBSTRING(@BARKOD,2,1) AS INT)+CAST(SUBSTRING(@BARKOD,4,1) AS INT)+ CAST(SUBSTRING(@BARKOD,6,1) AS INT) AS INT)
	SET @TEK=CAST(CAST(SUBSTRING(@BARKOD,1,1) AS INT)+CAST(SUBSTRING(@BARKOD,3,1) AS INT)+CAST(SUBSTRING(@BARKOD,5,1) AS INT)+CAST(SUBSTRING(@BARKOD,7,1) AS INT) AS INT)
	/*SET @SONUC=10-((@TEK*3+@CIFT) % 10) */
    SET @SONUC=     ( 10 -  (3 * @TEK + @CIFT) % 10  ) % 10
	If @SONUC=10 
		BEGIN
			SET @DEGER='0' 
		END
	Else 
		BEGIN
			SET @DEGER=CAST(@SONUC AS NVARCHAR(10))
		END
	RETURN @DEGER
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_ETSKDOLDUR]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_ETSKDOLDUR]  
 (@FC NVARCHAR(20))   
 RETURNS  
 NVARCHAR (20) 
 AS 
 BEGIN 
 DECLARE @I AS INT 
 DECLARE @SONUC AS NVARCHAR(20) 
 SET @I =0 
 SELECT @SONUC =@FC 
 WHILE @I < 15-LEN(@FC) 
    BEGIN 
     SELECT @I=@I+1 
     SELECT @SONUC = '0'+@SONUC      
    END 
 RETURN @SONUC 
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_HESAPBAKIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_HESAPBAKIYE]  
(
  @TAR1 DATETIME,
  @TAR2 DATETIME,
  @HESAPKODU NVARCHAR(250)
)
RETURNS
@QMUHHESAP TABLE
(
   SIRANO INT,
   SUBEID INT,
   BAKIYE FLOAT,
   DBAKIYE FLOAT
)
AS
BEGIN
	INSERT INTO  @QMUHHESAP (SIRANO,SUBEID, BAKIYE, DBAKIYE)
	SELECT SIRANO,SUBEID, BORC-ALACAK, DBORC-DALACAK FROM QMUH_HESAPISL2
	WHERE TARIH BETWEEN @TAR1 AND @TAR2
	       AND (HESAPKODU = @HESAPKODU OR
		        HESAPKODU LIKE @HESAPKODU + '.%')

	RETURN
END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_LPUNOVER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FN_LPUNOVER]  
 (@FIRMAID INT, @TUR NVARCHAR(10))
 RETURNS  NVARCHAR(20)
 AS
 BEGIN
 DECLARE @SONPLU BIGINT
	SELECT @SONPLU=BARKOD FROM FIRMABARKOD WHERE TUR=@TUR AND FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0
	RETURN ISNULL(CAST(@SONPLU AS NVARCHAR(20)),'')
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_MASRAFMERKEZIBUL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_MASRAFMERKEZIBUL]  
 (@FIRMAID INT, @MASMERADI NVARCHAR(30))
 RETURNS  INT
 AS
 BEGIN
 DECLARE @MASMERID INT
	SELECT @MASMERID=GRUPID FROM MUH_GRUP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND GRUPADI=@MASMERADI AND ISNULL(SIL,0)=0
	RETURN @MASMERID
 END
GO
/****** Object:  UserDefinedFunction [dbo].[fn_ParayiYaziyaCevir]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[fn_ParayiYaziyaCevir]  
(@num AS numeric(18,2), @isMoney as bit) RETURNS varchar(255)  BEGIN 

 DECLARE @Split tinyint 

 DECLARE @iSplit tinyint 

 DECLARE @sNum varchar(20) 

 DECLARE @NumSet varchar(3) 

 DECLARE @Char char(1) 

 DECLARE @NumText varchar(255) 

 DECLARE @SetText varchar(100) 

 DECLARE @HunText varchar(100) 

 DECLARE @CharText varchar(50) 

 DECLARE @Match bit 

 DECLARE @Point tinyint 

 DECLARE @Cents varchar(2) 

 DECLARE @CentText varchar(100) 

 DECLARE @NumStrings TABLE (Num int, NumStr varchar(20)) 

 INSERT INTO @NumStrings 

 SELECT 1, 'Bir' 

 UNION SELECT 2, 'İki' 

 UNION SELECT 3, 'Üç' 

 UNION SELECT 4, 'Dört' 

 UNION SELECT 5, 'Beş' 

 UNION SELECT 6, 'Altı' 

 UNION SELECT 7, 'Yedi' 

 UNION SELECT 8, 'Sekiz' 

 UNION SELECT 9, 'Dokuz' 

 UNION SELECT 10, 'On' 

 UNION SELECT 11, 'Onbir' 

 UNION SELECT 12, 'Oniki' 

 UNION SELECT 13, 'Onüç' 

 UNION SELECT 14, 'Ondört' 

 UNION SELECT 15, 'Onbeş' 

 UNION SELECT 16, 'Onaltı' 

 UNION SELECT 17, 'Onyedi' 

 UNION SELECT 18, 'Onsekiz' 

 UNION SELECT 19, 'Ondokuz' 

 UNION SELECT 20, 'Yirmi' 

 UNION SELECT 30, 'Otuz' 

 UNION SELECT 40, 'Kırk' 

 UNION SELECT 50, 'Elli' 

 UNION SELECT 60, 'Altmış' 

 UNION SELECT 70, 'Yetmiş' 

 UNION SELECT 80, 'Seksen' 

 UNION SELECT 90, 'Doksan' 

 SET @sNum = cast(@num as varchar(20)) 

 --convert any cent text first, then the 

 -- whole number 

 SET @Point = charindex('.', @sNum) 

 IF @Point > 0 

 BEGIN 

 SET @Cents = substring(@sNum, @Point + 1, 2) 

 SET @sNum = left(@sNum, @Point-1) 

 --if isMoney THEN combine the two digits (eg 11 = eleven) 

 IF @isMoney = 1 

 BEGIN --look FOR matches WITH the RIGHT İki characters 

 SET @Match = (select count(*) FROM @NumStrings WHERE Num = @Cents) 

 IF @Match <> 0 

 BEGIN 

 SET @CentText = (select NumStr FROM @NumStrings WHERE Num = @Cents) 

 END 

 ELSE 

 BEGIN 

 SET @CentText = isnull((select NumStr FROM @NumStrings WHERE Num = left(@Cents, 1) + '0'),'') + (select NumStr from @NumStrings where Num = right(@Cents, 1)) 

 END 

 END 

 ELSE --if NOT isMBiry THEN treat each digit seperately (eg 11 = Bir Bir) 

 BEGIN 

 SET @CentText = isnull((select NumStr FROM @NumStrings WHERE Num = left(@Cents, 1)),'') + isnull((select NumStr from @NumStrings where Num = right(@Cents, 1)),'') 

 END 

 END 

 IF @CentText IS NULL 

 SET @CentText = '' 

 --break the number into blocks of 3 characters 

 SET @Split = ((len(@sNum)-1) / 3) + 1 

 SET @iSplit = 0 

 SET @NumText = '' 

 WHILE @iSplit < @Split 

 BEGIN 

 SET @CharText = '' 

 SET @HunText = '' 

 SET @SetText = '' 

 SET @NumSet = right(left(@sNum, len(@sNum) - @iSplit * 3), 3) 

 IF len(@Numset) = 3 --Calculate ANY hundreds 

 BEGIN 

 SET @Char = left(@NumSet, 1) 

 if @Char='1'  

 SET @HunText = 'Yüz' 

 ELSE 

 SET @HunText = isnull((select NumStr FROM @NumStrings WHERE Num = @Char) + 'Yüz', '') 

 SET @SetText = @HunText 

 END 

 --look FOR matches WITH the RIGHT two characters 

 SET @Match = (select count(*) FROM @NumStrings WHERE Num = right(@NumSet, 2)) 

 IF @Match <> 0 

 BEGIN 

 SET @CharText = (select NumStr FROM @NumStrings WHERE Num = right(@NumSet, 2)) 

 END 

 ELSE 

 BEGIN 

 SET @CharText = isnull((select NumStr FROM @NumStrings WHERE Num = left(right(@NumSet, 2), 1) + '0'),'') + (select NumStr from @NumStrings where Num = right(@NumSet, 1)) 

 END 

 --make sure there IS something in @CharText AND @SetText (ie IF @NumSet = x00, x000) 

 IF @CharText IS NULL SET @CharText = '' 

 IF @SetText IS NULL set @SetText = '' 

 --seperate ANY hundreds FROM Ons/units WITH an 'and' 

 IF @HunText <> '' AND @CharText <> '' 

 SET @SetText = @SetText + '' 

 --if there are no hundreds, it's the smallest SET AND there are other sets, ADD an 'and' before 

 IF @HunText = '' AND @CharText <> '' and @iSplit = 0 and @Split > 1 and @CentText = '' 

 SET @SetText = '' + @SetText 

 SET @SetText = @SetText + @CharText 

 --append the SET suffix text. ADD a ',' AS long as there IS something in the lowest set 

 if @iSplit = 1 AND @SetText='Bir' BEGIN  

 SET @SetText='' 

 SET @SetText = @SetText + CASE @iSplit 

 WHEN 0 THEN '' 

 WHEN 1 THEN 'Bin' 

 WHEN 2 THEN 'Milyon' 

 WHEN 3 THEN 'Milyar' 

 WHEN 4 THEN 'Trilyon' 

 WHEN 5 THEN 'Katrilyon' 

 END + CASE WHEN len(@NumText) > 0 THEN '' ELSE '' end 

 END 

 ELSE 

 BEGIN 

 IF @SetText <> '' 

 SET @SetText = @SetText + CASE @iSplit 

 WHEN 0 THEN '' 

 WHEN 1 THEN 'Bin' 

 WHEN 2 THEN 'Milyon' 

 WHEN 3 THEN 'Milyar' 

 WHEN 4 THEN 'Trilyon' 

 WHEN 5 THEN 'Katrilyon' 

 END + CASE WHEN len(@NumText) > 0 THEN '' ELSE '' end 

 END 

 SET @NumText = @SetText + @NumText 

 SET @iSplit = @iSplit + 1 

 END 

 --add any dollars and cent text 

 IF @isMoney = 1 AND @NumText <> '' and rtrim(ltrim(@NumText)) <> 'Bir' 

 SET @NumText = @NumText + ' TL' 

 IF @isMoney = 1 AND rtrim(ltrim(@NumText)) = 'Bir' 

 SET @NumText = @NumText + ' TL' 

 IF @isMoney = 1 AND @CentText <> '' and rtrim(ltrim(@CentText)) <> 'Bir' 

 SET @CentText = @CentText + ' kuruş' 

 IF @isMoney = 1 AND rtrim(ltrim(@CentText)) = 'Bir' 

 SET @CentText = @CentText + ' kuruş' 

 IF @isMoney = 0 AND @CentText <> '' 

 SET @CentText = ' Point' + @CentText 

 IF @isMoney = 1 AND @NumText <> '' and @CentText <> '' 

 SET @CentText = ' ' + @CentText 

 --combine dollars and cents 

 SET @NumText = @NumText + @CentText 

 --add 'Minus' for negative numbers 

 IF left(@sNum, 1) = '-' 

 SET @NumText = 'virgül' + @NumText 

 RETURN @NumText 

 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_POZITIF]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_POZITIF]  
(@SAYI AS FLOAT) 
 RETURNS FLOAT AS  
 BEGIN  
   RETURN CASE WHEN @SAYI>0 THEN @SAYI ELSE 0 END  
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_READEXEINI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_READEXEINI]  
(@PROGNAME NVARCHAR(50), @SECTIONSTR NVARCHAR(50), @KEYNAME NVARCHAR(200))     RETURNS NVARCHAR(200) AS    BEGIN  DECLARE @VALUESTR   AS NVARCHAR(200)       SELECT TOP 1 @VALUESTR=ISNULL(VALUESTR,'')    FROM CONFIG      WHERE       PROGNAME = @PROGNAME       AND SECTIONSTR = @SECTIONSTR       AND KEYNAME = @KEYNAME       RETURN @VALUESTR    END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_READEXEINI_HESAPID]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_READEXEINI_HESAPID]   
 (@PROGNAME NVARCHAR(50), @SECTIONSTR NVARCHAR(50), @KEYNAME NVARCHAR(200))    RETURNS INT AS    BEGIN    DECLARE @HESAPID AS INT    SELECT @HESAPID = HESAPID FROM HESAP WHERE KODU =   (     SELECT TOP 1 ISNULL(VALUESTR,'')        FROM CONFIG     WHERE       PROGNAME = @PROGNAME       AND SECTIONSTR = @SECTIONSTR       AND KEYNAME = @KEYNAME  )     RETURN @HESAPID  END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_SPLIT_STRING]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_SPLIT_STRING]  
 (  

     @string NVARCHAR(MAX),  

     @delimiter CHAR(1)  

 )  

 RETURNS @output TABLE(splitdata NVARCHAR(MAX)  

 )  

 BEGIN  

     DECLARE @start INT, @end INT  

     SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)  

     WHILE @start < LEN(@string) + 1 BEGIN  

         IF @end = 0   

             SET @end = LEN(@string) + 1 

         

         INSERT INTO @output (splitdata)   

         VALUES(SUBSTRING(@string, @start, @end - @start))  

         SET @start = @end + 1  

         SET @end = CHARINDEX(@delimiter, @string, @start) 

          

     END  

     RETURN  

 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_SUREBUL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_SUREBUL]  
 (@ILKTARIH DATETIME,@SONTARIH DATETIME)
 RETURNS  NVARCHAR(100)
 AS
 BEGIN
	DECLARE @SURE INT
	DECLARE @SURET NVARCHAR(10)
	SET @SURET='00:00'
	SET @SURE=CAST(DATEDIFF(MINUTE,@ILKTARIH,@SONTARIH) AS INT)
	IF @SURE>0
		BEGIN
			IF @SURE<60  SET @SURET='00:'+CAST((@SURE) AS NVARCHAR(10))
			IF @SURE>=60 SET @SURET='01:'+CAST((@SURE-60) AS NVARCHAR(10))
			IF @SURE>120 SET @SURET='02:'+CAST((@SURE-120) AS NVARCHAR(10))
			IF @SURE>180 SET @SURET='03:'+CAST((@SURE-180) AS NVARCHAR(10))
			IF @SURE>240 SET @SURET='04:'+CAST((@SURE-240) AS NVARCHAR(10))
			IF @SURE>300 SET @SURET='05:'+CAST((@SURE-300) AS NVARCHAR(10))
			IF @SURE>360 SET @SURET='06:'+CAST((@SURE-360) AS NVARCHAR(10))
			IF @SURE>420 SET @SURET='07:'+CAST((@SURE-420) AS NVARCHAR(10))
			IF @SURE>480 SET @SURET='08:'+CAST((@SURE-480) AS NVARCHAR(10))
			IF @SURE>540 SET @SURET='09:'+CAST((@SURE-540) AS NVARCHAR(10))
			IF @SURE>600 SET @SURET='10:'+CAST((@SURE-600) AS NVARCHAR(10))
			IF @SURE>660 SET @SURET='11:'+CAST((@SURE-660) AS NVARCHAR(10))
			IF @SURE>720 SET @SURET='12:'+CAST((@SURE-720) AS NVARCHAR(10))
			IF @SURE>780 SET @SURET='13:'+CAST((@SURE-780) AS NVARCHAR(10))
			IF @SURE>840 SET @SURET='14:'+CAST((@SURE-840) AS NVARCHAR(10))
		
			IF LEN(@SURET)<5 SET @SURET=SUBSTRING(@SURET,1,3)+'0'+SUBSTRING(@SURET,4,4)
		END
	ELSE
		BEGIN
			SET @SURET=''
		END
	RETURN @SURET
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_TURKCELE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FN_TURKCELE]  
 (@VERI NVARCHAR(100) )   
   RETURNS NVARCHAR(100)   AS   
   BEGIN      
   DECLARE @YENIVERI varchar(100) 
          SELECT @YENIVERI = Replace(@VERI ,'Ç','C') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'Ş','S') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'Ğ','Ğ') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'Ö','O') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'Ü','U') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'İ','I')   
          SELECT @YENIVERI = Replace(@YENIVERI ,'ç','c') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'ş','s')  
          SELECT @YENIVERI = Replace(@YENIVERI ,'ğ','g') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'ö','o') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'ü','u') 
          SELECT @YENIVERI = Replace(@YENIVERI ,'ı','i')                   
   RETURN  @YENIVERI  
             
   END
GO
/****** Object:  UserDefinedFunction [dbo].[fn_UpcE0_CK]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE   FUNCTION [dbo].[fn_UpcE0_CK]
(
    @Yedi CHAR(7)   -- örn: '0000001'
)
RETURNS CHAR(1)
AS
BEGIN
    DECLARE
        @D1 CHAR(1) = SUBSTRING(@Yedi,2,1),
        @D2 CHAR(1) = SUBSTRING(@Yedi,3,1),
        @D3 CHAR(1) = SUBSTRING(@Yedi,4,1),
        @D4 CHAR(1) = SUBSTRING(@Yedi,5,1),
        @D5 CHAR(1) = SUBSTRING(@Yedi,6,1),
        @D6 CHAR(1) = SUBSTRING(@Yedi,7,1);
 
    -- D6 kuralıyla UPC-A'nın 11 haneli tabanını oluştur
    DECLARE @Base CHAR(11) =
        CASE @D6
            WHEN '0' THEN '0'+@D1+@D2+'0'+'00000'+@D3+@D4+@D5
            WHEN '1' THEN '0'+@D1+@D2+'1'+'00000'+@D3+@D4+@D5
            WHEN '2' THEN '0'+@D1+@D2+'2'+'00000'+@D3+@D4+@D5
            WHEN '3' THEN '0'+@D1+@D2+@D3+'000000'+@D4+@D5
            WHEN '4' THEN '0'+@D1+@D2+@D3+@D4+'0000000'+@D5
            ELSE           '0'+@D1+@D2+@D3+@D4+@D5+'00000'+@D6
        END;
 
    -- GS1 kontrol hanesi: tek pozisyon ×3, çift ×1
    DECLARE @sum INT = 0, @i INT = 1;
    WHILE @i <= 11
    BEGIN
        SET @sum += CAST(SUBSTRING(@Base,@i,1) AS INT)
                  * CASE WHEN @i % 2 = 1 THEN 3 ELSE 1 END;
        SET @i += 1;
    END
 
    RETURN CAST((10 - @sum % 10) % 10 AS CHAR(1));
END
GO
/****** Object:  UserDefinedFunction [dbo].[FN_USTHESAPKONTROLET]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FN_USTHESAPKONTROLET]  
(@STRKODU AS NVARCHAR(50)) 
      RETURNS @OLMAYANHESAPLAR TABLE
      (
        HESAPKODU NVARCHAR(50),
        ALTHESABI NVARCHAR(50)
      )
      AS
      BEGIN
      DECLARE @KODU AS NVARCHAR(50)
      DECLARE @TMPKODU AS NVARCHAR(50)
      DECLARE @HESAP_CURSOR CURSOR

      IF ISNULL(@STRKODU,'')=''
        SET @HESAP_CURSOR = CURSOR FAST_FORWARD FOR
          SELECT KODU FROM MUH_HESAP (NOLOCK) WHERE ISNULL(UCHESAP,0) =1 ORDER BY KODU,SEVIYE
      ELSE
        SET @HESAP_CURSOR = CURSOR FAST_FORWARD FOR
          SELECT @STRKODU AS KODU
      BEGIN
      OPEN @HESAP_CURSOR
      FETCH NEXT FROM @HESAP_CURSOR INTO @KODU
      WHILE @@FETCH_STATUS = 0
      BEGIN

         SET @TMPKODU=REVERSE(@KODU)
         IF  CHARINDEX('.',@KODU)>0
          SET @TMPKODU=REVERSE(SUBSTRING(@TMPKODU,CHARINDEX('.',@TMPKODU)+1,LEN(@TMPKODU)-CHARINDEX('.',@TMPKODU)))
         ELSE 
          SET @TMPKODU=REVERSE(@TMPKODU)
   
         IF NOT EXISTS(SELECT TOP 1 KODU FROM MUH_HESAP WHERE KODU=@TMPKODU)
         BEGIN
          INSERT INTO @OLMAYANHESAPLAR 
        SELECT @TMPKODU,@KODU
          IF  CHARINDEX('.',@TMPKODU)>0
        INSERT INTO @OLMAYANHESAPLAR 
        SELECT * FROM dbo.FN_USTHESAPKONTROLET(@TMPKODU)
         END
         FETCH NEXT FROM @HESAP_CURSOR INTO @KODU
      END

      CLOSE @HESAP_CURSOR
      DEALLOCATE @HESAP_CURSOR
      END
      RETURN
      END
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SONHESAPKODU]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SONHESAPKODU] (@FIRMAID INT,@HESAPKODU NVARCHAR(30)) RETURNS NVARCHAR(30)
AS
BEGIN
DECLARE @KODUZUNLUGU INT
DECLARE @YENIKOD NVARCHAR(30)
DECLARE @ANAKOD NVARCHAR(20)
DECLARE @MAXKOD INT
DECLARE @SAYAC INT
DECLARE @ALFABET NVARCHAR(50)
DECLARE @SAYACX INT=1
DECLARE @SAY INT=0
SET @ALFABET='QWERTYUIOPĞÜİŞLKJHGFDSAZXCVBNMÖÇiğşüöç'

WHILE (@SAYACX<=LEN(@ALFABET))
	BEGIN 
	  IF CHARINDEX(SUBSTRING(@ALFABET,@SAYACX,1),RTRIM(@HESAPKODU))>0 SET  @SAY=1
	  SET @SAYACX=@SAYACX+1
	END

IF @SAY<=0 
	BEGIN
			SELECT @ANAKOD=LEFT(CASE WHEN CHARINDEX('.',RTRIM(@HESAPKODU))>0 THEN RTRIM(REVERSE(RIGHT(REVERSE(RTRIM(@HESAPKODU)), LEN(RTRIM(@HESAPKODU))-CHARINDEX('.',REVERSE(RTRIM(@HESAPKODU))) )))  ELSE RTRIM(@HESAPKODU) END,30)+'.'
			FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND KODU=@HESAPKODU

			SELECT @KODUZUNLUGU=LEN(LEFT(CASE WHEN CHARINDEX('.',RTRIM(@HESAPKODU))>0 THEN RTRIM(REVERSE(SUBSTRING(REVERSE(RTRIM(@HESAPKODU)),1,CHARINDEX('.',REVERSE(RTRIM(@HESAPKODU)))-1))) ELSE '' END,30))
			FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND  FIRMAID=@FIRMAID AND KODU=@HESAPKODU

			SELECT  @MAXKOD=MAX(LEFT(CASE WHEN CHARINDEX('.',RTRIM(KODU))>0 THEN RTRIM(REVERSE(SUBSTRING(REVERSE(RTRIM(KODU)),1,CHARINDEX('.',REVERSE(RTRIM(KODU)))-1))) ELSE '' END,30))+1 
			FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND  FIRMAID=@FIRMAID AND KODU LIKE @ANAKOD+'%'

			SET @SAYAC=0
			SET @YENIKOD=''
				WHILE (@SAYAC<=(@KODUZUNLUGU-1)-LEN(@MAXKOD))
						BEGIN
						  SET @YENIKOD=@YENIKOD+'0'
						  SET @SAYAC=@SAYAC+1
						END
			SET @YENIKOD=@ANAKOD+@YENIKOD+CAST(@MAXKOD AS NVARCHAR(10))
		/*RETURN @YENIKOD */

	END
ELSE
	BEGIN
		SET @YENIKOD=@HESAPKODU+'?'
		/*RETURN @YENIKOD */
	END
RETURN @YENIKOD
END
GO
/****** Object:  UserDefinedFunction [dbo].[FNETS_MEDISOFT_FATURA_ODEMETURLERI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION  [dbo].[FNETS_MEDISOFT_FATURA_ODEMETURLERI]  
 (@FATID as Integer)   
 RETURNS NVARCHAR(100) AS   
 BEGIN  
 DECLARE @ODEMETURU AS NVARCHAR(20),@ODEMETURUADI AS NVARCHAR(100) 
  
 SET @ODEMETURUADI = ''  
  
 DECLARE FATURA_ODEME_CURSOR CURSOR 
 FOR SELECT ODEMETURUADI FROM ODEMEISL INNER JOIN TODEMETURU ON (ODEMEISL.ODEMETURUID=TODEMETURU.ODEMETURUID)  
                WHERE (ODEMEISL.HSTHFATISLID = @FATID OR ODEMEISL.KRMHFATISLID=@FATID OR ODEMEISL.SGFATID=@FATID)  AND IPTAL=0 
 OPEN FATURA_ODEME_CURSOR  
 FETCH NEXT FROM FATURA_ODEME_CURSOR  INTO @ODEMETURU 
  
 WHILE @@FETCH_STATUS = 0 
 BEGIN 
     IF @ODEMETURU IS NULL SET @ODEMETURU='' 
     IF @ODEMETURUADI ='' SET @ODEMETURUADI = @ODEMETURU  
     ELSE  
     SET @ODEMETURUADI= @ODEMETURUADI+','+@ODEMETURU  
     FETCH NEXT FROM FATURA_ODEME_CURSOR  INTO @ODEMETURU 
 END 
  
 IF Cursor_Status('variable', 'FATURA_ODEME_CURSOR')<>-1  
                CLOSE FATURA_ODEME_CURSOR 
 DEALLOCATE FATURA_ODEME_CURSOR 
  
 RETURN @ODEMETURUADI 
 END
GO
/****** Object:  UserDefinedFunction [dbo].[FNETS_SATIR_KDV]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

 CREATE FUNCTION [dbo].[FNETS_SATIR_KDV]  
(@FATID INT) 

 RETURNS FLOAT  

 BEGIN  

  DECLARE @KDV FLOAT  

  SELECT @KDV=ISNULL((SUM(NTUTAR)),0) FROM FNCQ_FATISL(@FATID) WHERE HESAPID IN (SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE '191%' OR KODU LIKE '391%')

  RETURN @KDV 

 END
GO
/****** Object:  UserDefinedFunction [dbo].[FNETS_YILDONEM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FNETS_YILDONEM]  
 (@AY INT)   
   RETURNS INTEGER  AS   
   BEGIN   
   RETURN      
   CASE  
   WHEN @AY BETWEEN 10 AND 12 THEN 4 
   WHEN @AY BETWEEN 7 AND 9 THEN 3  
   WHEN @AY BETWEEN 4 AND 6 THEN 2  
   WHEN @AY BETWEEN 1 AND 3 THEN 1 END   
   END
GO
/****** Object:  UserDefinedFunction [dbo].[FNM_Bekleyen]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNM_Bekleyen]
(
    @FISCOUNTER int
)
RETURNS VARCHAR(250)
AS
BEGIN
    DECLARE @URUNLER varchar(250)
    SELECT @URUNLER = COALESCE(@URUNLER + ',', '') + ISNULL(S.ADI+'x'+cast(ADET as nvarchar(8)),'')
    FROM ADSSATIR AS ADS INNER JOIN STOK AS S ON ADS.STOKID=S.STOKID WHERE BEKLET>0 AND FISCOUNTER=@FISCOUNTER ORDER BY S.ADI
 
    RETURN @URUNLER
END
GO
/****** Object:  UserDefinedFunction [dbo].[FNMUH_FISNO_VER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNMUH_FISNO_VER]  
  (@FSUBEID NVARCHAR(50),@FFISTURU NVARCHAR(150),@ATARIH NVARCHAR(20))  
  RETURNS NVARCHAR(MAX)   
AS BEGIN
      --ATARIHI PARSE ET
      DECLARE @GUN INT,@AY INT,@YIL INT
      SELECT @GUN = DAY(@ATARIH),@AY = MONTH(@ATARIH),@YIL = YEAR(@ATARIH)
      --MMDD SEKLINDE FORMATLA
      DECLARE @MMDD NVARCHAR(4)
      SELECT @MMDD = CASE WHEN @AY < 10 THEN '0' ELSE '' END + CONVERT(NVARCHAR,@AY)+
      CASE WHEN @GUN< 10 THEN '0' ELSE '' END + CONVERT(NVARCHAR,@GUN)
      --VARIABLELARI TANIMLA 
      DECLARE 
		@RS INT, @RESULT NVARCHAR(MAX), @YFISNO NVARCHAR(MAX), @FNO INT, 
		@FIS_SAYAC_NO NVARCHAR(50), @FIS_SAYAC_LEN INT, @RC INT

	  SELECT @FIS_SAYAC_NO = ISNULL(dbo.FN_READEXEINI('NOVA','Fis','FisNo Başlangıç Sayaç Numarası'),'0000000')
	  SELECT @FIS_SAYAC_LEN = LEN(@FIS_SAYAC_NO)
      IF ISNULL(DBO.FN_READEXEINI('NOVA','Fis','FisNo aagg001 formatında olsun')  ,  '0') = '1'  
      BEGIN  
 		  SELECT @RESULT = ISNULL(MAX(RIGHT(FISNO,(@FIS_SAYAC_LEN-4)))+1,1),@RC = COUNT(*) FROM MUH_FIS (nolock) 
 		  WHERE ISNULL(SIL,0)=0 AND CONVERT(NVARCHAR,SUBEID)=ISNULL(@FSUBEID,'0')   
 		  AND YEAR(TARIH) = @YIL   
 		  AND FISNO LIKE @MMDD+'%'  AND LEN(FISNO)=@FIS_SAYAC_LEN      
 		   WHILE LEN(@RESULT) < (@FIS_SAYAC_LEN-4) 
 		     SELECT @RESULT  = '0'+@RESULT               
 		     SELECT @RESULT  = @MMDD+@RESULT          
      END
      ELSE  
		SELECT 
			@RESULT = RIGHT(@FIS_SAYAC_NO+CONVERT(NVARCHAR,ISNULL(MAX(FISNO)+1,1)),@FIS_SAYAC_LEN) FROM MUH_FIS (nolock) 
 		WHERE ISNULL(SIL,0)=0 AND  
			YEAR(TARIH) = @YIL AND
 			CONVERT(NVARCHAR,SUBEID)=ISNULL(@FSUBEID,'0')  AND ISNUMERIC(FISNO)=1
      RETURN @RESULT
  END
GO
/****** Object:  UserDefinedFunction [dbo].[FNSUBELER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[FNSUBELER]  
 (    
     @SUBEID int   
 )    
 RETURNS VARCHAR(50)    
 AS   
 BEGIN   
     DECLARE @Subeler varchar(50)    
     SELECT @Subeler = COALESCE(@Subeler + ',', '') + (ISNULL(MT.SUBEKODU,'') + '-'+ ISNULL(MT.SUBEADI,'')) 
     FROM SUBELER MT WHERE MT.SUBEID=@SUBEID    
    
     RETURN @Subeler    
 END
GO
/****** Object:  UserDefinedFunction [dbo].[GV]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE Function [dbo].[GV](@KMatrah DECIMAL(14,2),@VMatrah  DECIMAL(14,2), @YIL INT, @FIRMAID INT)
Returns DECIMAL(14,2)
As
Begin
DECLARE @Dilim1  DECIMAL(14,2)
DECLARE @Dilim2 DECIMAL(14,2)
DECLARE @Dilim3 DECIMAL(14,2)
DECLARE @Dilim4 DECIMAL(14,2)
DECLARE @Dilim5 DECIMAL(14,2)

DECLARE @Oran1 DECIMAL(14,2)
DECLARE @Oran2 DECIMAL(14,2)
DECLARE @Oran3 DECIMAL(14,2)
DECLARE @Oran4 DECIMAL(14,2)
DECLARE @Oran5 DECIMAL(14,2)

DECLARE @GV1 DECIMAL(14,2)
DECLARE @GV2 DECIMAL(14,2)
DECLARE @GV3 DECIMAL(14,2)
DECLARE @GV4 DECIMAL(14,2)
DECLARE @GV5 DECIMAL(14,2)

DECLARE @TMATRAH DECIMAL(14,2)

SELECT @Dilim1=GV1_MATRAH,@Oran1=GV1_ORAN FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID
SELECT @Dilim2=GV2_MATRAH,@Oran2=GV2_ORAN FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID
SELECT @Dilim3=GV3_MATRAH,@Oran3=GV3_ORAN FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID
SELECT @Dilim4=GV4_MATRAH,@Oran4=GV4_ORAN FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID
SELECT @Dilim5=GV5_MATRAH,@Oran5=GV5_ORAN FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID

SET @TMATRAH = (@KMatrah+@VMatrah) 

IF(@KMatrah>=@Dilim1 AND @KMatrah<@Dilim2)
BEGIN
IF(@TMATRAH>=@Dilim1 AND @TMATRAH<@Dilim2)
BEGIN
SET @GV1 = @VMatrah * @Oran1/100
END
ELSE
BEGIN 
SET @GV1=0
END
END

IF(@TMATRAH>=@Dilim2 AND @TMATRAH<@Dilim3)
BEGIN
SET @GV2 = ((@Dilim2-@KMatrah)*@Oran1/100)+((@VMatrah - (@Dilim2-@KMatrah))*@Oran2/100)
END
ELSE
BEGIN 
SET @GV2=0
END

IF(@TMATRAH>=@Dilim3 AND @TMATRAH<@Dilim4)
BEGIN
SET @GV3 = ((@Dilim2-@KMatrah)*@Oran1/100)+((@Dilim3-@Dilim2) * @Oran2/100) + ((@VMatrah - (@Dilim3 - @KMatrah))*@Oran3/100)
END
ELSE
BEGIN 
SET @GV3=0
END

IF(@TMATRAH>=@Dilim4 AND @TMATRAH<@Dilim5)
BEGIN
SET @GV4 = ((@Dilim2-@KMatrah)*@Oran1/100)+((@Dilim3-@Dilim2) * @Oran2/100) + ((@Dilim4-@Dilim3)*@Oran3/100) + ((@VMatrah-(@Dilim4 - @KMatrah)) * @Oran4/100)
END
ELSE
BEGIN 
SET @GV4=0
END

IF(@TMATRAH>=@Dilim5)
BEGIN
SET @GV5 = ((@Dilim2-@KMatrah)*@Oran1/100)+((@Dilim3-@Dilim2) * @Oran2/100) + ((@Dilim4-@Dilim3)*@Oran3/100) + ((@Dilim5-@Dilim4)*@Oran4/100) + ((@VMatrah-(@Dilim5 - @KMatrah)) * @Oran5/100)
END
ELSE
BEGIN 
SET @GV5=0
END

IF(@KMatrah >= @Dilim2 AND @KMatrah < @Dilim3)
BEGIN
SET @GV1=0
IF(@TMATRAH>= @Dilim2 AND @TMATRAH<@Dilim3)
BEGIN
SET @GV2= @VMatrah * @Oran2/100 
END
ELSE
BEGIN
SET @GV2=0
END
END

IF(@TMATRAH >=@Dilim3 AND @TMATRAH < @Dilim4)
BEGIN
SET @GV3 = ((@Dilim3 - @KMatrah)* @Oran2/100)+((@VMatrah - (@Dilim3 - @KMatrah)) * @Oran3 /100)
END
ELSE
BEGIN
SET @GV3=0
END

IF(@TMATRAH >=@Dilim4 AND @TMATRAH < @Dilim5)
BEGIN
SET @GV4 = ((@Dilim3 - @KMatrah)* @Oran2/100)+((@Dilim4 - @Dilim3)* @Oran3/100)+((@VMatrah - (@Dilim4 - @KMatrah)) * @Oran4 /100)
END
ELSE
BEGIN
SET @GV4=0
END

IF(@TMATRAH >=@Dilim5)
BEGIN
SET @GV5 = ((@Dilim3 - @KMatrah)* @Oran2/100)+((@Dilim4 - @Dilim3)* @Oran3/100)+((@Dilim5 - @Dilim4)* @Oran4/100)+((@VMatrah - (@Dilim5 - @KMatrah)) * @Oran5 /100)
END
ELSE
BEGIN
SET @GV5=0
END

IF(@KMatrah >= @Dilim3 AND @KMatrah<@Dilim4)
BEGIN
SET @GV1=0
SET @GV2=0
END

IF(@TMATRAH>= @Dilim3 AND @TMATRAH < @Dilim4)
BEGIN
SET @GV3 = @VMatrah * @Oran3 / 100
END
ELSE
BEGIN
SET @GV3=0
END

IF(@TMATRAH>= @Dilim4 AND @TMATRAH < @Dilim5)
BEGIN
SET @GV4 = ((@Dilim4 - @KMatrah)*@Oran3/100) + ((@VMatrah - (@Dilim4-@KMatrah))*@Oran4/100)
END
ELSE
BEGIN
SET @GV4=0
END

IF(@TMATRAH>= @Dilim4 AND @TMATRAH < @Dilim5)
BEGIN
SET @GV4 = ((@Dilim4 - @KMatrah)*@Oran3/100) + ((@VMatrah - (@Dilim4-@KMatrah))*@Oran4/100)
END
ELSE
BEGIN
SET @GV4=0
END

IF(@TMATRAH>= @Dilim5)
BEGIN
SET @GV5 = ((@Dilim4 - @KMatrah)*@Oran3/100) +((@Dilim5 - @Dilim4)*@Oran4/100) + ((@VMatrah - (@Dilim5-@KMatrah))*@Oran5/100)
END
ELSE
BEGIN
SET @GV5=0
END

IF(@KMatrah >= @Dilim4 AND @KMatrah <@Dilim5)
BEGIN
SET @GV1 = 0
SET @GV2 = 0
SET @GV3 = 0
END

IF(@TMATRAH >= @Dilim4 AND @TMATRAH <@Dilim5)
BEGIN
SET @GV4 = @VMatrah * @Oran4 / 100
END
ELSE
BEGIN
SET @GV4 = 0
END

IF(@TMATRAH >= @Dilim5)
BEGIN
SET @GV5=((@Dilim5-@KMatrah)*@Oran4/100) + ((@VMatrah - (@Dilim5-@KMatrah))*@Oran5/100)
END
ELSE
BEGIN
SET @GV5=0
END

IF(@KMatrah >= @Dilim5)
BEGIN
SET @GV1=0
SET @GV2=0
SET @GV3=0
SET @GV4=0
END

IF(@TMATRAH >= @Dilim5)
BEGIN
SET @GV5 = @VMatrah * @Oran5/100
END
ELSE
BEGIN
SET @GV5 = 0
END
RETURN  @GV1 + @GV2 + @GV3 + @GV4 + @GV5
End
GO
/****** Object:  UserDefinedFunction [dbo].[GV_MATRAH]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE Function [dbo].[GV_MATRAH](@BRUT DECIMAL(14,2), @YIL INT, @FIRMAID INT)
Returns DECIMAL(14,2)
As
Begin
DECLARE @GV_MATRAH DECIMAL(15,4)=0
DECLARE @SSK_ISCI_PRIMI INT = (SELECT TOP 1 SSK_ISCI_PRIMI FROM PERSSKPARAMETRE WHERE FIRMAID=@FIRMAID AND YIL=@YIL)
DECLARE @SSK_ISCI DECIMAL(15,4) = (SELECT @BRUT*@SSK_ISCI_PRIMI/100)
DECLARE @ISSIZLIK_ISCI_PRIMI DECIMAL(15,4) = (SELECT TOP 1 ISSIZLIK_ISCI_PRIMI FROM PERSSKPARAMETRE WHERE FIRMAID=@FIRMAID AND YIL=@YIL) 
DECLARE @SSK_ISCI_ISSIZLIK DECIMAL(15,4) = (SELECT @BRUT*@ISSIZLIK_ISCI_PRIMI/100)

SET @GV_MATRAH=@BRUT-(@SSK_ISCI+@SSK_ISCI_ISSIZLIK)
return @GV_MATRAH
End
GO
/****** Object:  UserDefinedFunction [dbo].[index_name]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[index_name] (@object_id int, @index_id int)
RETURNS sysname
AS
BEGIN
RETURN(SELECT name FROM sys.indexes WHERE
 
 object_id = @object_id and index_id = @index_id)
END;
GO
/****** Object:  UserDefinedFunction [dbo].[NetBul]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Function [dbo].[NetBul](@BRUT DECIMAL(14,2),@KMATRAH  DECIMAL(14,2),@SGKMatrah DECIMAL(14,2), @YIL INT, @FIRMAID INT)
Returns DECIMAL(14,2)
As
Begin
--HESAP YAPILACAK BÜTÜN DERĞERLER DEĞİŞKENLER ÜZERİNDEN YAPILMIŞTIR.
DECLARE @SGKPrimi  DECIMAL(14,2)
DECLARE @DamgaVergisi  DECIMAL(14,2)
DECLARE @GelirVergisi  DECIMAL(14,2)
DECLARE @NetBul  DECIMAL(14,2)
DECLARE @DAMGA_VERGISI_MATRAHI  DECIMAL(14,5)=(SELECT TOP 1 DAMGA_VERGISI/1000 FROM PERSSKPARAMETRE WHERE YIL=@YIL AND FIRMAID=@FIRMAID)

SET @SGKPrimi		= dbo.SGKM(@SGKMatrah, @BRUT)*15 / 100
SET @DamgaVergisi	= (@BRUT*@DAMGA_VERGISI_MATRAHI)
SET @GelirVergisi	= dbo.GV(@KMATRAH, (@BRUT - @SGKPrimi),@YIL, @FIRMAID)
SET @NetBul = @Brut - (@SGKPrimi + @DamgaVergisi + @GelirVergisi)
RETURN @NetBul
End
GO
/****** Object:  UserDefinedFunction [dbo].[PARAYUVARLA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[PARAYUVARLA]  
 (@Tutar as float) RETURNS NUMERIC(18,2) AS BEGIN    return ROUND(CAST(@Tutar AS NUMERIC(18,6)),2) END
GO
/****** Object:  UserDefinedFunction [dbo].[SGKM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Function [dbo].[SGKM](@KSMatrah DECIMAL(14,2),@SMatrah  DECIMAL(14,2))
Returns DECIMAL(14,2)
As
Begin
DECLARE @IS_VEREN_PAY_ORANI  DECIMAL(14,2)=20.5
DECLARE @ISCI_ISSIZLIK_ORANI  DECIMAL(14,2)=1.00
DECLARE @ISVEREN_ISSIZLIK_ORANI  DECIMAL(14,2)=2.00
DECLARE @SGKM  DECIMAL(14,2)
DECLARE @TMATRAH  DECIMAL(14,2)
DECLARE @SGKTAVANI DECIMAL(14,2) = 26831.25

IF(@KSMatrah >= @SGKTAVANI)
BEGIN
SET @SGKM = 0
END
ELSE
BEGIN
SET @TMATRAH = @KSMatrah + @SMatrah
END
IF(@TMATRAH < @SGKTAVANI)
BEGIN 
SET @SGKM=@SMatrah
END
ELSE
BEGIN
SET @SGKM=(@SGKTAVANI - @KSMatrah)
END

RETURN @SGKM
End
GO
/****** Object:  UserDefinedFunction [dbo].[SplitPos]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION  [dbo].[SplitPos]  
 (@String varchar(8000), @Delimiter char(1))   
  returns @temptable TABLE (id int identity(1,1),items varchar(100))         
  as
  begin
      declare @idx int
      declare @slice varchar(8000)
	  declare @pos int

	  set @pos = 0

      select @idx = 1
          if len(@String)<1 or @String is null  return
      while @idx!= 0
      begin
          set @idx = charindex(@Delimiter,@String)
          if @idx!=0
              set @slice = left(@String,@idx - 1)
          else
              set @slice = @String
          if(len(@slice)>0)
          begin
		    set @pos += LEN(@slice)
		    insert into @temptable(items) values(@pos)
          end

          set @String = right(@String,len(@String) - @idx)
          if len(@String) = 0 break
      end
  return
  end
GO
/****** Object:  UserDefinedFunction [dbo].[TARIHAL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[TARIHAL]  
(@Tarih as datetime) RETURNS datetime AS BEGIN return cast(FLOOR(cast(@Tarih as FLOAT)) as datetime) END
GO
/****** Object:  Table [dbo].[SUBELER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBELER](
	[SUBEID] [int] IDENTITY(1,1) NOT NULL,
	[SUBEKODU] [nvarchar](10) NULL,
	[SUBEADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[ADRES1] [nvarchar](50) NULL,
	[ADRES2] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[YAZUNVANI] [nvarchar](150) NULL,
	[GENELMUDUR] [nvarchar](50) NULL,
	[MUHASEBE] [nvarchar](50) NULL,
	[SATINALMA] [nvarchar](50) NULL,
	[ONBURO] [nvarchar](50) NULL,
	[COST] [nvarchar](50) NULL,
	[PERSONEL] [nvarchar](50) NULL,
	[ORTAK] [nvarchar](50) NULL,
	[LOGO] [image] NULL,
	[HOTELCONNSTR] [nvarchar](500) NULL,
	[SIRKETKODU] [nvarchar](50) NULL,
	[PERSONELCONNSTR] [nvarchar](500) NULL,
	[SUBEIPNO] [nvarchar](20) NULL,
	[ETSCONNSTR] [nvarchar](500) NULL,
	[SUBEVD] [nvarchar](20) NULL,
	[SUBEVDNO] [nvarchar](20) NULL,
	[KILITTARIHI] [datetime] NULL,
	[SAYIMKILITTARIHI] [datetime] NULL,
	[TRANSFERHESAPID] [int] NULL,
	[SUBEADRES] [nvarchar](250) NULL,
	[SUBEIL] [nvarchar](50) NULL,
	[SUBEILCE] [nvarchar](50) NULL,
	[SUBEPKODU] [nvarchar](10) NULL,
	[TSICILNO] [nvarchar](50) NULL,
	[MERSISNO] [nvarchar](50) NULL,
	[IL] [nvarchar](50) NULL,
	[ILCE] [nvarchar](50) NULL,
	[EFATURA_GONETIKET] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[SUBEFAX] [nvarchar](20) NULL,
	[SUBETEL] [nvarchar](20) NULL,
	[FIRMAID] [int] NULL,
	[MEDISOFTCONNSTR] [nvarchar](500) NULL,
	[EFATURA_WSDL] [nvarchar](250) NULL,
	[EFATURA_KULLANICI] [nvarchar](50) NULL,
	[EFATURA_PAROLA] [nvarchar](50) NULL,
	[EFATURA_PREFIKS] [nvarchar](3) NULL,
	[WEB] [nvarchar](200) NULL,
	[EMAIL] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[MERKEZSUBEID] [int] NULL,
	[EFATURA_SUBEKODU] [nvarchar](20) NULL,
	[EFATURA_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_KASAKODU] [nvarchar](20) NULL,
	[EARSIV_WSDL] [nvarchar](250) NULL,
	[EARSIV_KULLANICI] [nvarchar](30) NULL,
	[EARSIV_PAROLA] [nvarchar](30) NULL,
	[EFATURA_AUTWSDL] [nvarchar](250) NULL,
	[EDONUSUMTARIH] [smalldatetime] NULL,
	[EIRSALIYE_WSDL] [nvarchar](250) NULL,
	[EIRSALIYE_KULLANICI] [nvarchar](30) NULL,
	[EIRSALIYE_PAROLA] [nvarchar](30) NULL,
	[EIRSALIYE_PREFIKS] [nvarchar](3) NULL,
	[EMUSTAHSIL_WSDL] [nvarchar](250) NULL,
	[EMUSTAHSIL_KULLANICI] [nvarchar](30) NULL,
	[EMUSTAHSIL_PAROLA] [nvarchar](30) NULL,
	[EMUSTAHSIL_PREFIKS] [nvarchar](3) NULL,
	[ESMM_WSDL] [nvarchar](250) NULL,
	[ESMM_KULLANICI] [nvarchar](30) NULL,
	[ESMM_PAROLA] [nvarchar](30) NULL,
	[ESMM_PREFIKS] [nvarchar](3) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[IKSUBEID] [int] NULL,
	[EIRSALIYE_GONETIKET] [nvarchar](50) NULL,
	[EIRSALIYE_PKUTUSU] [nvarchar](50) NULL,
	[UZAKHOTELCONNSTR] [nvarchar](500) NULL,
	[BANKAIBAN] [nvarchar](26) NULL,
	[OLDSUBEID] [int] NULL,
	[SUBESQLIP] [nvarchar](50) NULL,
	[SUBESQLUSER] [nvarchar](30) NULL,
	[SUBESQLPASS] [nvarchar](30) NULL,
	[SUBESQLDB] [nvarchar](30) NULL,
 CONSTRAINT [PK_SUBELER] PRIMARY KEY CLUSTERED 
(
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_SUBELER] UNIQUE NONCLUSTERED 
(
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  View [dbo].[QMUH_FISTUR]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







 CREATE VIEW [dbo].[QMUH_FISTUR]  AS 
   SELECT -1 AS FISTURID,'Gelir Bütçesi' AS FISTURADI,6 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,0 BELGETURUID  
   UNION ALL
   SELECT -11 AS FISTURID,'Satış' AS FISTURADI,6 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,0 BELGETURUID  
   UNION ALL    SELECT -2 AS FISTURID,'Gider Bütçesi' AS FISTURADI,7 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,0    UNION ALL    SELECT -3 AS FISTURID,'Geçen Yıl Gelir' AS FISTURADI,6 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,0   UNION ALL    SELECT -4 AS FISTURID,'Geçen Yıl Gider' AS FISTURADI,7 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,0    UNION ALL    SELECT 1 AS FISTURID,'Kasaya Tahsilat' AS FISTURADI,100 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,9    UNION ALL    SELECT 2 AS FISTURID,'Kasadan Ödeme' AS FISTURADI,100 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,10   UNION ALL    SELECT 3 AS FISTURID,'Bankaya Tahsilat' AS FISTURADI,102 AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,4    UNION ALL    SELECT 4 AS FISTURID,'Bankadan Ödeme' AS FISTURADI,102 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,4    UNION ALL    
   SELECT 5 AS FISTURID,'Borç Dekontu' AS FISTURADI,NULL AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,17    UNION ALL    SELECT 6 AS FISTURID,'Alacak Dekontu' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,17  
   UNION ALL   SELECT 7 AS FISTURID,'Taksitli Tahsilatlar' AS FISTURADI,NULL AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,9    UNION ALL    SELECT 8 AS FISTURID,'Taksitli Ödemeler' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,10  UNION ALL   SELECT 9 AS FISTURID,'Virman' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,17  UNION ALL  SELECT 21 AS FISTURID,'Çek-Senet Giriş (Alınan Çek)',120,'ALACAK','-1',2 UNION ALL  SELECT 22 AS FISTURID,'Çek-Senet Giriş (Portfoye Geri Alındı)',320,'ALACAK','23,24,25,26,27,31,32',2 UNION ALL  SELECT 23 AS FISTURID,'Çek-Senet Çıkış (Tahsile Verildi)',101,'BORC',  '21,22',2    UNION ALL  SELECT 24 AS FISTURID,'Çek-Senet Çıkış (Teminata Verildi)',102,'BORC',  '21,22',2    UNION ALL  SELECT 25 AS 
FISTURID,'Çek-Senet Çıkış (Protesto Edildi)',NULL,'BORC',  '21,22',2    UNION ALL  SELECT 26 AS FISTURID,'Çek-Senet Çıkış (Adli Takipte)',NULL,'BORC',  '21,22',2    UNION ALL  SELECT 31 AS FISTURID,'Çek-Senet Çıkış (Verilen Çek)',320,'BORC',  '21,22',2   UNION ALL  SELECT 32 AS FISTURID,'Çek-Senet Çıkış (İade Edildi)',320,'BORC',  '21,22',2     UNION ALL  SELECT 33 AS FISTURID,'Çek-Senet Ödeme (Bankadan Ödendi)',102,'ALACAK','31',2 UNION ALL  SELECT 34 AS FISTURID,'Çek-Senet Ödeme (Kasadan Ödendi)',100,'ALACAK','31',2 UNION ALL  SELECT 35 AS FISTURID,'Çek-Senet Tahsil (Bankaya Tahsil)',102,'BORC',  '21,22,23',2   UNION ALL  SELECT 36 AS FISTURID,'Çek-Senet Tahsil (Kasaya Tahsil)',100,'BORC',  '21,22,23',2   UNION ALL   SELECT 41 AS FISTURID,'Mahsup',NULL                          ,'',   NULL,NULL   UNION ALL   SELECT 42 AS FISTURID,'Tahsil',null,'',   NULL,9   UNION ALL   SELECT 43 AS FISTURID,'Tediye',null,'', NULL,10   UNION ALL   SELECT 44 AS FISTURID,'Yansıtma',NULL,                          '',   NULL,NULL   UNION ALL    SELECT 45 AS FISTURID,'Kur Farkı',NULL,                          '',   NULL,15   UNION ALL    SELECT 48 AS FISTURID,'Kapanış',NULL,                          '',   NULL,NULL   UNION ALL    SELECT 49 AS FISTURID,'Açılış',NULL,                          '',   NULL,NULL   UNION ALL   SELECT 51 AS FISTURID,'Stok Alış Faturası',320,'ALACAK',NULL,1  UNION ALL  SELECT 52 AS FISTURID,'Stok Satış Faturası',120,'BORC',NULL,1  UNION ALL   SELECT 53 AS FISTURID,'Stok Alış İade Faturası',120,'BORC',NULL,1  UNION ALL  SELECT 54 AS FISTURID,'Stok Satış İade Faturası',320,'ALACAK',NULL,1  UNION ALL  SELECT 61 AS FISTURID,'Hizmet Alış Faturası',320,'ALACAK',NULL,1  UNION ALL  SELECT 62 AS FISTURID,'Hizmet Satış Faturası',120,'BORC',NULL,1  UNION ALL SELECT 63 AS FISTURID,'Hizmet Alış İade Faturası',120,'BORC',NULL,1  UNION ALL  SELECT 64 AS FISTURID,'Hizmet Satış İade Faturası',320,'ALACAK',NULL,1  UNION ALL  SELECT 50 AS FISTURID,'Fiyat Teklifi',120,'BORC',NULL,1  UNION ALL  SELECT 65 AS FISTURID,'Gider 
Pusulası',320,'ALACAK',NULL,6  UNION ALL  SELECT 66 AS FISTURID,'Serbest Meslek Makbuzu',120,'BORC',NULL,8  UNION ALL  SELECT 67 AS FISTURID,'Müstahsil Makbuzu',320,'ALACAK',NULL,7
GO
/****** Object:  Table [dbo].[MUH_HESAP]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAP](
	[HESAPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NOT NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](50) NULL,
	[VDNO] [nvarchar](40) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [datetime] NULL,
	[ISTENAYRILIS] [datetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[VADEUYAR] [bit] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[OLDHESAPID] [int] NULL,
	[KAMU] [bit] NULL,
	[ALTCARIKULLANIR] [bit] NULL,
	[RDOVIZ] [nvarchar](5) NULL,
	[KURZARARHESAPID] [int] NULL,
	[KURKARHESAPID] [int] NULL,
	[PROJEZORUNLU] [bit] NULL,
	[ISLEMGRUPID1ZORUNLU] [bit] NULL,
	[OZELKODIDZORUNLU] [bit] NULL,
	[ENG_HESAPADI] [nvarchar](100) NULL,
	[RUS_HESAPADI] [nvarchar](100) NULL,
	[DIG_HESAPADI] [nvarchar](100) NULL,
	[SOZLESMESIVAR] [bit] NULL,
 CONSTRAINT [PK_MUH_HESAP] PRIMARY KEY CLUSTERED 
(
	[HESAPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_HESAP_1] UNIQUE NONCLUSTERED 
(
	[KODU] ASC,
	[SUBEID] ASC,
	[FIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPO]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPO](
	[DEPOID] [int] IDENTITY(1,1) NOT NULL,
	[DEPOADI] [nvarchar](40) NOT NULL,
	[ANADEPO] [bit] NULL,
	[DEPOMUH] [int] NULL,
	[SKODU] [nvarchar](10) NULL,
	[KODU] [nvarchar](5) NOT NULL,
	[MUHKODU] [nvarchar](25) NULL,
	[MUHKODUSARF] [nvarchar](25) NULL,
	[MASMERID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[MASMERID2] [int] NULL,
	[MIKTARKONTROL] [bit] NULL,
	[SIL] [smallint] NULL,
	[SUBEFIYATKULLAN] [bit] NULL,
	[MERKEZDEPOID] [int] NULL,
	[NSATISHESAPID] [int] NULL,
	[KKSATISHESAPID] [int] NULL,
	[ACIKHESAPID] [int] NULL,
	[ACIKSUBEID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[OLDDEPOID] [int] NULL,
 CONSTRAINT [PK_DEPO] PRIMARY KEY CLUSTERED 
(
	[DEPOID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURA](
	[FATID] [int] IDENTITY(1,1) NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [datetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [datetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [datetime] NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [datetime] NULL,
	[IRSALIYENO] [nvarchar](50) NULL,
	[IRSALIYETARIHI] [datetime] NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[TINDEK] [float] NULL,
	[NTOPLAM] [float] NULL,
	[DNTOPLAM] [float] NULL,
	[FISTURADI] [nvarchar](30) NULL,
	[MODULID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[OLDFATID] [int] NULL,
 CONSTRAINT [PK_FATURA] PRIMARY KEY CLUSTERED 
(
	[FATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURADETAY]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURADETAY](
	[FATURADETAYID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[EFATNO] [nvarchar](16) NULL,
	[EFATURAACIKLAMA] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[EFATURA_KABULREDNOTU] [nvarchar](250) NULL,
	[EFATURA_ENTREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPTARIHI] [datetime] NULL,
	[EFATURA_CEVAPACK] [nvarchar](150) NULL,
	[EFATURAACIKLAMA2] [nvarchar](250) NULL,
	[EFATURA_CEVAP_UUID] [uniqueidentifier] NULL,
	[EFATURA_CEVAPNO] [nvarchar](50) NULL,
	[EFATURAINDYOK] [bit] NULL,
	[EFATURA_LOG] [nvarchar](250) NULL,
	[EFATURA_SONGONTAR] [datetime] NULL,
	[EFATTURU] [int] NULL,
	[EFATURADURUM] [int] NULL,
	[EDEVLETDURUM] [int] NULL,
	[EFATURAZARF] [uniqueidentifier] NULL,
	[UUID] [uniqueidentifier] NOT NULL,
	[EDEVLET_ILETIMYONTEMI] [nvarchar](20) NULL,
	[ONLINE] [bit] NULL,
	[ONLINE_WEBADRES] [nvarchar](50) NULL,
	[ONLINE_ODEMESEKLI] [nvarchar](20) NULL,
	[ONLINE_ODEME_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TASIYANTURU] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANKIMLIKNO] [nvarchar](15) NULL,
	[ONLINE_GONDERIM_TASIYANADI] [nvarchar](20) NULL,
	[EI_SATICIVKNO] [nvarchar](11) NULL,
	[EI_SATICIUNVAN] [nvarchar](150) NULL,
	[EI_ALICIVKNO] [nvarchar](20) NULL,
	[EI_ALICIUNVAN] [nvarchar](150) NULL,
	[EI_ISLEMBASLATANVKNO] [nvarchar](11) NULL,
	[EI_ISLEMBASLATANUNVAN] [nvarchar](150) NULL,
	[EI_TASIYICIVKNO] [nvarchar](11) NULL,
	[EI_TASIYICIUNVAN] [nvarchar](150) NULL,
	[EI_ARACPLAKA] [nvarchar](15) NULL,
	[EI_DORSEPLAKA] [nvarchar](20) NULL,
	[EI_ARACSOFORADISOYADI] [nvarchar](20) NULL,
	[EI_ARACSOFORID] [nvarchar](20) NULL,
	[EI_TESLIMATTANIM] [nvarchar](50) NULL,
	[EI_TESLIMATADRES] [nvarchar](250) NULL,
	[EI_TESLIMATILCE] [nvarchar](30) NULL,
	[EI_TESLIMATIL] [nvarchar](30) NULL,
	[EI_TESLIMATULKE] [nvarchar](50) NULL,
	[EFATURA_IBAN] [nvarchar](26) NULL,
	[EI_TASIYICIPOSTAKUTUSU] [nvarchar](10) NULL,
 CONSTRAINT [PK_FATURADETAY] PRIMARY KEY CLUSTERED 
(
	[FATURADETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_FATURADETAY] UNIQUE NONCLUSTERED 
(
	[FATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURAEK]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAEK](
	[FATURAEKID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[STOKID] [int] NULL,
	[GBEYANNO] [nvarchar](50) NULL,
	[GBEYANTARIHI] [smalldatetime] NULL,
	[GMAKBUZNO] [nvarchar](20) NULL,
	[GMAKBUZTARIHI] [smalldatetime] NULL,
	[GIRISGUMRUK] [nvarchar](150) NULL,
	[ALISYAPILANFIRMA] [nvarchar](150) NULL,
	[ALISFNO] [nvarchar](20) NULL,
	[ALISFTARIHI] [smalldatetime] NULL,
	[MODELYILI] [smallint] NULL,
	[SASINO] [nvarchar](30) NULL,
	[MOTORNO] [nvarchar](30) NULL,
	[RENK] [nvarchar](20) NULL,
	[SILINDIRHACMI] [nvarchar](20) NULL,
 CONSTRAINT [PK_FATURAEK] PRIMARY KEY CLUSTERED 
(
	[FATURAEKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATURA_IRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_FATURA_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
 RETURN
 SELECT      F.FISTURID, F.FISIVAR, F.AKTARIMSTATUID, F.FATID, F.TARIH, F.FISHESAPID CARIID,   F.DEPOID,F.UNVANI AS FATUNVANI, F.ADRES1,F.ADRES2,F.ADRES3,F.VD,F.VDNO,F.TEL,F.FAX,F.EMAIL,F.WEB,    

              F.FATNO, F.OZELKOD1, F.DOVIZ AS DOVIZ, F.KUR AS DOVIZKURU,F.ACIKLAMA,  F.IRSALIYETARIHI,F.IRSALIYENO,F.SIPARISNO, F.SIPARISTARIHI, F.VADE,F.KDVACIKLAMA,  

 			 FD.EFATNO,FD.EFATURAACIKLAMA,FD.EFATURAACIKLAMA2,  FD.EFATURA_ENTREFNO,FD.EFATURA_PKUTUSU, FD.EFATURA_KABULREDNOTU,   

              FD.EFATURA_CEVAPNO,FD.EFATURA_CEVAPACK,FD.EFATURA_CEVAPTARIHI,FD.EFATURA_CEVAPREFNO,FD.UUID,FD.EFATURA_CEVAP_UUID,  

              FD.EFATURAZARF, FD.EFATURAINDYOK,FD.EFATURA_LOG, FD.EFATURA_SONGONTAR,FD.EFATURADURUM,ISNULL(FD.EFATTURU,0) EFATTURU,  

              F.IND1,F.IND2,F.IND3,F.EK1,F.EK2,F.EK3,F.SIND, 

              F.TOPLAM+(ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)) AS TOPLAM,ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0) AS INDEKTOPLAM, 

              F.TOPLAM-(ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)) AS NTOPLAM, TEVKIFATTOPLAM,

              F.VERGITOPLAM, F.KDV, F.OTV, F.GTOPLAM, F.MUHFC, F.FISDURUMID AS DURUM,   

              C.HESAPID, C.KODU HESAPKODU, C.ACIKLAMA HESAPADI,C.KODU AS CARIKODU, C.ACIKLAMA UNVANI, C.KODU HESAPKODUALIS, C.ACIKLAMA HESAPADIALIS, 

              F.FIRMAID,SUBELER.SUBEID, SUBELER.SUBEKODU, SUBELER.SUBEADI,   

              MF.FISTURADI AS TURADI,  

              DEPO.DEPOADI, DEPO.ANADEPO,EDEVLET_ILETIMYONTEMI, EDEVLETDURUM,SAAT,KDVSIZLIKKODU,[ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI, 
			 FATURAEK.GBEYANNO, FATURAEK.GBEYANTARIHI, FATURAEK.GMAKBUZNO, FATURAEK.GMAKBUZTARIHI, FATURAEK.GIRISGUMRUK, FATURAEK.ALISYAPILANFIRMA,
			 FATURAEK.ALISFNO, FATURAEK.ALISFTARIHI, MODELYILI,SASINO,RENK,MOTORNO,
			 EI_SATICIVKNO	,EI_SATICIUNVAN	,EI_ALICIVKNO,EI_ALICIUNVAN	,EI_ISLEMBASLATANVKNO,
			 EI_ISLEMBASLATANUNVAN	,EI_TASIYICIVKNO	,EI_TASIYICIUNVAN	,EI_ARACPLAKA	,EI_DORSEPLAKA	,
			 EI_ARACSOFORADISOYADI ,EI_ARACSOFORID ,EI_TESLIMATTANIM,EI_TESLIMATADRES,EI_TESLIMATILCE,EI_TESLIMATIL,EI_TESLIMATULKE,EFATURA_IBAN,EI_TASIYICIPOSTAKUTUSU
  FROM        FATURA AS F WITH (NOLOCK) INNER JOIN  
			  FATURADETAY AS FD WITH (NOLOCK) ON F.FATID=FD.FATID INNER JOIN		
                        SUBELER ON F.SUBEID = SUBELER.SUBEID LEFT OUTER JOIN  

                        DEPO ON F.DEPOID = DEPO.DEPOID LEFT OUTER JOIN  

                        QMUH_FISTUR MF ON F.FISTURID = MF.FISTURID LEFT OUTER JOIN  

                        MUH_HESAP AS C ON F.FISHESAPID = C.HESAPID 
						
						LEFT JOIN FATURAEK ON F.FATID=FATURAEK.FATID 

  WHERE       (ISNULL(F.FISDURUMID, 0) = -1) AND F.FATID=@FATID
GO
/****** Object:  Table [dbo].[STOK]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK](
	[STOKID] [int] IDENTITY(1,1) NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](30) NULL,
	[EK2] [nvarchar](30) NULL,
	[EK3] [nvarchar](30) NULL,
	[EK4] [nvarchar](30) NULL,
	[EK5] [nvarchar](30) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[POSYAZICIID1] [int] NULL,
	[POSYAZICIID2] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](10) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[OZELKOD3] [nvarchar](50) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](50) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](20) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](20) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[KGSATILIR] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](20) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[GRUPID] [int] NULL,
	[BIRIM5] [nvarchar](20) NULL,
	[BIRIM5ID] [int] NULL,
	[KATSAYI5] [float] NULL,
	[BARKOD5] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDSTOKID] [int] NULL,
	[PLUNO] [nvarchar](20) NULL,
	[INDVERILIR] [bit] NULL,
	[SURE] [smallint] NULL,
	[AGIRLIK] [float] NULL,
	[KGFIYATI] [float] NULL,
	[MARKAID] [int] NULL,
	[URETICIID] [int] NULL,
	[REYONID] [int] NULL,
	[STOKRESIMYOLU] [nvarchar](100) NULL,
 CONSTRAINT [PK_STOK] PRIMARY KEY CLUSTERED 
(
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUKETIMFIS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUKETIMFIS](
	[DEPOFISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[TARIH] [datetime] NULL,
	[SAAT] [time](7) NULL,
	[YETKILI] [nvarchar](15) NULL,
	[USERID] [int] NULL,
	[ISLEM] [nvarchar](10) NULL,
	[ENO] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[GDEPOID] [int] NULL,
	[CDEPOID] [int] NULL,
	[TADET] [float] NULL,
	[TTUTAR] [float] NULL,
	[GSKODU] [nvarchar](10) NULL,
	[CSKODU] [nvarchar](10) NULL,
	[URUNFISID] [int] NULL,
	[URETILDI] [bit] NULL,
	[LOGOAKTAR] [int] NULL,
	[LOGODANGELDI] [bit] NULL,
	[ISLEMDETAY] [nvarchar](50) NULL,
	[SDEPART] [nvarchar](15) NULL,
	[ONAY] [bit] NULL,
	[MUHFISID] [int] NULL,
	[DURUMU] [int] NULL,
	[CSUBEID] [int] NULL,
	[GSUBEID] [int] NULL,
	[MUHFC] [int] NULL,
	[BARKODBASILDI] [bit] NULL,
	[BMALIYET] [float] NULL,
	[MUHASEBELESTIRME] [bit] NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[INDORAN] [float] NULL,
	[INDTUTAR] [float] NULL,
	[HESAPID] [int] NULL,
	[KHESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[NAKIT] [float] NULL,
	[KKARTI] [float] NULL,
	[ACIK] [float] NULL,
	[DKURU] [float] NULL,
	[DKODU] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[NAKITHESAPID] [int] NULL,
	[KKARTIHESAPID] [int] NULL,
	[GERCEKTARIH] [datetime] NULL,
	[VADESI] [smalldatetime] NULL,
	[CARIID] [int] NULL,
	[CALLSIPARISID] [int] NULL,
	[FTIPI] [tinyint] NULL,
	[DURUMID] [smallint] NULL,
	[FUNVANI] [nvarchar](120) NULL,
	[FVD] [nvarchar](20) NULL,
	[FVDNO] [nvarchar](20) NULL,
	[OKCFISNO] [nvarchar](20) NULL,
	[TICKET1] [float] NULL,
	[TICKET2] [float] NULL,
	[TICKET3] [float] NULL,
	[ALINANPARA] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[PROJEID] [int] NULL,
	[MODULID] [int] NULL,
	[TICKET4] [float] NULL,
	[TICKET5] [float] NULL,
	[DEPOFISUUID] [uniqueidentifier] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[GTOPLAM] [float] NULL,
	[SUBEID] [int] NULL,
 CONSTRAINT [PK_TUKETIMFIS] PRIMARY KEY CLUSTERED 
(
	[DEPOFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ARACKABUL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ARACKABUL](
	[ARACKABULID] [int] IDENTITY(1,1) NOT NULL,
	[FORMNO] [nvarchar](10) NULL,
	[TARIH] [smalldatetime] NULL,
	[DEPOID] [smallint] NULL,
	[SUBEID] [smallint] NULL,
	[FIRMAID] [smallint] NULL,
	[SAAT] [time](7) NULL,
	[TESLIMTARIH] [smalldatetime] NULL,
	[CARIID] [int] NULL,
	[ARACID] [int] NULL,
	[ARACMARKA] [nvarchar](50) NULL,
	[ARACMODEL] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](10) NULL,
	[RENK] [nvarchar](20) NULL,
	[KM] [float] NULL,
	[UNVANI] [nvarchar](150) NULL,
	[SASINO] [nvarchar](30) NULL,
	[MOTORNO] [nvarchar](30) NULL,
	[FIRMAYETKILI] [nvarchar](50) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](20) NULL,
	[ADRES] [nvarchar](250) NULL,
	[ARACTESLIMALAN] [nvarchar](50) NULL,
	[ARACTESLIMEDEN] [nvarchar](50) NULL,
	[MUSTERITALEBI] [nvarchar](500) NULL,
	[ARACARIZASI] [nvarchar](500) NULL,
	[YAPILANISLER] [nvarchar](500) NULL,
	[KAPORA] [float] NULL,
	[SERVISUCRETI] [float] NULL,
	[PARCAUCRETI] [float] NULL,
	[ROTBALANSUCRETI] [float] NULL,
	[ELEKTRIKCIUCRETI] [float] NULL,
	[KAPORTAUCRETI] [float] NULL,
	[BOYAUCRETI] [float] NULL,
	[TORNAUCRETI] [float] NULL,
	[TOPLAMTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [money] NULL,
	[FATID] [int] NULL,
	[SADECEPARCAAKTAR] [bit] NULL,
	[SADECEISCILIKAKTAR] [bit] NULL,
	[TUMUNUAKTAR] [bit] NULL,
	[INDIRIMY] [float] NULL,
	[INDIRIMT] [float] NULL,
	[NETTOPLAM] [float] NULL,
	[ACIKLAMALAR] [nvarchar](250) NULL,
	[SIL] [smallint] NULL,
	[ALTCARIID] [int] NULL,
	[USERID] [int] NULL,
	[DURUMID] [smallint] NULL,
	[PROJEID] [int] NULL,
 CONSTRAINT [PK_ARACKABUL] PRIMARY KEY CLUSTERED 
(
	[ARACKABULID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ARACKABULPARCA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ARACKABULPARCA](
	[ARACKABULPARCAID] [int] IDENTITY(1,1) NOT NULL,
	[ARACKABULID] [int] NULL,
	[STOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[INDY] [float] NULL,
	[INDT] [float] NULL,
	[TOPLAM] [float] NULL,
 CONSTRAINT [PK_ARACKABULPARCA] PRIMARY KEY CLUSTERED 
(
	[ARACKABULPARCAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOFIS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOFIS](
	[DEPOFISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[TARIH] [datetime] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[USERID] [int] NULL,
	[ISLEM] [nvarchar](10) NULL,
	[ENO] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[GDEPOID] [int] NULL,
	[CDEPOID] [int] NULL,
	[TADET] [float] NULL,
	[TTUTAR] [float] NULL,
	[GSKODU] [nvarchar](10) NULL,
	[CSKODU] [nvarchar](10) NULL,
	[URUNFISID] [int] NULL,
	[URETILDI] [bit] NULL,
	[LOGOAKTAR] [int] NULL,
	[LOGODANGELDI] [bit] NULL,
	[ISLEMDETAY] [nvarchar](15) NULL,
	[SDEPART] [nvarchar](15) NULL,
	[ONAY] [bit] NULL,
	[MUHFISID] [int] NULL,
	[DURUM] [int] NULL,
	[CSUBEID] [int] NULL,
	[EK2] [nvarchar](30) NULL,
	[EK1] [nvarchar](30) NULL,
	[MUHFC] [int] NULL,
	[SBOLUMID] [int] NULL,
	[BOLUM] [nvarchar](10) NULL,
	[BARKODBASILDI] [bit] NULL,
	[BMALIYET] [float] NULL,
	[MUHASEBELESTIRME] [bit] NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[EK2GOREV] [nvarchar](50) NULL,
	[EK2YETKI] [nvarchar](50) NULL,
	[GSUBEID] [int] NULL,
	[GERCEKTARIH] [datetime] NULL,
	[SIL] [smallint] NULL,
	[DURUMID] [smallint] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[PROJEID] [int] NULL,
	[MODULID] [int] NULL,
	[DEPOFISUUID] [uniqueidentifier] NULL,
	[SUBEID] [int] NULL,
 CONSTRAINT [PK_DEPOFIS] PRIMARY KEY CLUSTERED 
(
	[DEPOFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_DEPOFIS] UNIQUE NONCLUSTERED 
(
	[DEPOFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOFISISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOFISISL](
	[DEPOFISISLID] [int] IDENTITY(1,1) NOT NULL,
	[DEPOFISID] [int] NULL,
	[STOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[MARKAID] [int] NULL,
	[ISLREFID] [int] NULL,
	[FBFIYAT] [float] NULL,
	[URETSEVIYE] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[SKTARIHI] [datetime] NULL,
	[RGDEPOID] [int] NULL,
	[RCDEPOID] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[OTOTUKETISL] [bit] NULL,
	[TEMPITSID] [int] NULL,
	[ETSCARIID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[BMALIYET] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
 CONSTRAINT [PK_DEPOFISISL] PRIMARY KEY CLUSTERED 
(
	[DEPOFISISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_DEPOFISISL] UNIQUE NONCLUSTERED 
(
	[DEPOFISISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUKETIMFISISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUKETIMFISISL](
	[DEPOFISISLID] [int] IDENTITY(1,1) NOT NULL,
	[DEPOFISID] [int] NULL,
	[STOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[MARKAID] [int] NULL,
	[ISLREFID] [int] NULL,
	[FBFIYAT] [float] NULL,
	[URETSEVIYE] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[SKTARIHI] [datetime] NULL,
	[RGDEPOID] [int] NULL,
	[RCDEPOID] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[TEMPITSID] [int] NULL,
	[TUKETILEN] [int] NULL,
	[URETILEN] [int] NULL,
	[ETSCARIID] [int] NULL,
	[INDORAN] [float] NULL,
	[KDVORAN] [float] NULL,
	[DKURU] [float] NULL,
	[DTURU] [nvarchar](10) NULL,
	[ANASTOKID] [int] NULL,
	[SERILOTID] [int] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[KDV] [float] NULL,
	[BMALIYET] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[SATISZAMANI] [datetime] NULL,
	[SILINDI] [smallint] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
 CONSTRAINT [PK_TUKETIMFISISL] PRIMARY KEY CLUSTERED 
(
	[DEPOFISISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATISL](
	[FATISLID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NOT NULL,
	[BARKOD] [nvarchar](30) NULL,
	[IRSISLID] [int] NULL,
	[HESAPID] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[SATISTID] [int] NULL,
	[ADET] [float] NOT NULL,
	[BFIYAT] [float] NOT NULL,
	[SKTARIHI] [datetime] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[SATIRIND3] [float] NULL,
	[SATIRIND4] [float] NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FADET] [float] NOT NULL,
	[FBFIYAT] [float] NOT NULL,
	[VADE] [datetime] NULL,
	[KDV] [float] NULL,
	[IRSCOUNTER] [int] NULL,
	[IRSCOUNTERILK] [int] NULL,
	[SGRUPLA] [int] NULL,
	[SATIRINDT] [float] NULL,
	[DEPT] [nvarchar](5) NULL,
	[GELIRGRUP] [nvarchar](5) NULL,
	[FBTOPLAM] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[TEVORAN] [nvarchar](5) NULL,
	[KODU] [nvarchar](20) NULL,
	[FFARKI] [int] NULL,
	[RGDEPOID] [int] NULL,
	[SILINDI] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[DFBFIYAT] [float] NULL,
	[DBFIYAT] [float] NULL,
	[ISLREFID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[IRSADET] [float] NULL,
	[KDVTURU] [nvarchar](5) NULL,
	[MUHFC] [float] NULL,
	[SRMMRKID] [int] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[SATIRNO] [int] NULL,
	[KDVLIFIYAT] [float] NULL,
	[YAZILDI] [int] NULL,
	[DEMID] [int] NULL,
	[SIPYAZILDI] [int] NULL,
	[YAZICINO] [int] NULL,
	[BMALIYET] [float] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[BABSHARIC] [int] NULL,
	[TEMPITSID] [int] NULL,
	[SSIRA] [int] NULL,
	[KDV2] [float] NULL,
	[KNO] [int] NULL,
	[SERILOTID] [int] NULL,
	[GTARIHI] [smalldatetime] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[TEVKANUNKODU] [nvarchar](20) NULL,
	[TEVKANUNACIKLAMA] [nvarchar](200) NULL,
	[URETICIKODU] [nvarchar](10) NULL,
	[ALICIKODU] [nvarchar](10) NULL,
	[SATICIKODU] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[SIL] [smallint] NULL,
	[KDVDAHIL] [nvarchar](5) NULL,
	[FATFIRMAID] [int] NULL,
	[OLDFATID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FKARSIHESAPID] [int] NULL,
 CONSTRAINT [PK_FATISL] PRIMARY KEY CLUSTERED 
(
	[FATISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKBAKIYE_DEVRI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKBAKIYE_DEVRI] (@TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  F.TARIH,F.ADD_DATE AS ISLEMTARIH, 'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,STOK.GRUPID,
FI.STOKID,FI.RENKID,FI.BEDENID,STOK.KODU AS STOKKODU,FI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET, FI.BFIYAT, 
ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT,
F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH<@TARIH 
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,STOK.GRUPID,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT, DFI.BFIYAT AS NFIYAT, DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH  
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR*-1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH
 UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH  
/*SERVİS FORMU */
 UNION ALL
SELECT DF.TARIH,DF.TARIH AS ISLEMTARIH,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,STOK.GRUPID,
DFI.STOKID,NULL AS RENKID,NULL AS BEDENID,STOK.KODU AS STOKKODU,STOK.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH<@TARIH
GO
/****** Object:  Table [dbo].[MUH_FIS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_FIS](
	[FISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FISTURID] [int] NULL,
	[FISDURUMID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[TARIH] [datetime] NULL,
	[VADE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[FISTURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](30) NULL,
	[BELGEACIKLAMA] [nvarchar](250) NULL,
	[DETAYLIENTEGRE] [bit] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TOPLAM] [decimal](18, 2) NULL,
	[KAPANAN] [float] NULL,
	[DTOPLAM] [float] NULL,
	[OZELKOD1] [nvarchar](40) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[YETKIID] [int] NULL,
	[ENTKAYNAK] [nvarchar](30) NULL,
	[ENTKAYNAKID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[BABSTYPEID] [int] NULL,
	[OZELKOD4] [nvarchar](30) NULL,
	[PASIF] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[BABSTUTAR] [decimal](18, 2) NULL,
	[ODENMEYEN] [float] NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[ALTCARIID] [int] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[RFISNO] [nvarchar](50) NULL,
	[YAZDIRMASAYISI] [int] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[EXPORTEDILDI] [bit] NULL,
	[EXPORTDEGISTI] [bit] NULL,
	[BELGETURU] [int] NULL,
	[ODEMEYONTEMI] [nvarchar](300) NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[SIL] [smallint] NULL,
	[FISTANIMID] [int] NULL,
	[KARSIHESAPID] [int] NULL,
	[TMIKTAR] [float] NULL,
	[TBIRIM] [nvarchar](10) NULL,
	[TBIRIMFIYAT] [float] NULL,
	[MODULID] [int] NULL,
	[MODULEKRANID] [int] NULL,
	[FISDEPOID] [int] NULL,
	[OZELKODID] [int] NULL,
	[OPSTARIHI] [datetime] NULL,
 CONSTRAINT [PK_MUH_FIS] PRIMARY KEY CLUSTERED 
(
	[FISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_GRUP]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_GRUP](
	[GRUPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GRUPKODU] [nvarchar](30) NULL,
	[GRUPADI] [nvarchar](100) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TIPID] [int] NULL,
	[ANAGRUBU] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[SERI] [nvarchar](5) NULL,
	[SIRANO] [int] NULL,
	[PRIMORAN] [float] NULL,
	[PRIMDVZ] [nvarchar](10) NULL,
	[MAHALLE] [nvarchar](30) NULL,
	[ADA] [nvarchar](10) NULL,
	[PARSEL] [nvarchar](10) NULL,
	[ADRES] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[OKCSIFRE] [nvarchar](10) NULL,
	[GRUPSUBEID] [int] NULL,
	[GRUPDEPOID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[ANAGRUPID] [int] NULL,
	[SATICIHESAPID] [int] NULL,
	[KOMGELIRHESAPID] [int] NULL,
	[KOMGIDERHESAPID] [int] NULL,
	[STOKHESAPID] [int] NULL,
	[OLDGRUPID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[KAT] [nvarchar](10) NULL,
	[CEPHE] [nvarchar](20) NULL,
	[DURUM] [nvarchar](20) NULL,
	[GIRISTARIHI] [smalldatetime] NULL,
	[CIKISTARIHI] [smalldatetime] NULL,
	[TAPUTARIHI] [smalldatetime] NULL,
	[ELEKTRIKABONE] [nvarchar](20) NULL,
	[SUABONE] [nvarchar](20) NULL,
	[SIGORTAPOLICE] [nvarchar](50) NULL,
	[TAPUADI] [nvarchar](100) NULL,
	[EMLAKTURID] [int] NULL,
	[MALIYETI] [float] NULL,
	[SATISBEDELI] [float] NULL,
	[M2] [float] NULL,
	[DOVIZI] [nvarchar](5) NULL,
	[SOZLESMEID] [int] NULL,
	[GRUPADIENG] [nvarchar](30) NULL,
	[GRUPADIDEU] [nvarchar](30) NULL,
	[GRUPADIRUS] [nvarchar](30) NULL,
	[GRUPADIARP] [nvarchar](30) NULL,
	[MUSTERIHESAPID] [int] NULL,
 CONSTRAINT [PK_MUH_GRUP] PRIMARY KEY CLUSTERED 
(
	[GRUPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAP_ALTCARI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAP_ALTCARI](
	[ALTCARIID] [int] IDENTITY(1,1) NOT NULL,
	[HESAPID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](30) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [datetime] NULL,
	[ISTENAYRILIS] [datetime] NULL,
	[RISKLIMITI] [float] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[GRUPKODU] [nvarchar](50) NULL,
	[SERINO] [nvarchar](20) NULL,
	[CUZDANNO] [nvarchar](20) NULL,
	[DOGUMYERI] [nvarchar](20) NULL,
	[DOGUMTARIHI] [datetime] NULL,
	[ANNEADI] [nvarchar](20) NULL,
	[BABAADI] [nvarchar](20) NULL,
	[NKOIL] [nvarchar](20) NULL,
	[NKOILCE] [nvarchar](20) NULL,
	[NKOM] [nvarchar](20) NULL,
	[CILTNO] [nvarchar](20) NULL,
	[AILESIRANO] [nvarchar](20) NULL,
	[SIRANO] [nvarchar](20) NULL,
	[MHALI] [nvarchar](1) NULL,
	[CGRUBU] [nvarchar](20) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MASMERID] [int] NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[HESAPTIPID] [int] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[BANKAADI] [nvarchar](100) NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[MAHALLE] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[AKTARILDI] [int] NULL,
	[EMAIL2] [nvarchar](30) NULL,
	[EMAIL3] [nvarchar](30) NULL,
	[SEMT] [nvarchar](20) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SKODU] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDALTCARIID] [int] NULL,
	[CARIPROJEID] [int] NULL,
	[SOZLESMEID] [int] NULL,
 CONSTRAINT [PK_MUH_HESAP_ALTCARI] PRIMARY KEY CLUSTERED 
(
	[ALTCARIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_HESAP_ALTCARI] UNIQUE NONCLUSTERED 
(
	[ALTCARIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPISL](
	[ISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[FISID] [int] NULL,
	[HESAPID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[ACIKLAMA] [nvarchar](500) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TUTAR] [decimal](18, 2) NULL,
	[DTUTAR] [float] NULL,
	[BORC] [decimal](18, 2) NULL,
	[ALACAK] [decimal](18, 2) NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[BABSTUTAR] [float] NULL,
	[VADE] [datetime] NULL,
	[KAPANAN] [float] NULL,
	[ENTKAYNAK] [nvarchar](30) NULL,
	[ENTKAYITID] [int] NULL,
	[BUTCEID] [int] NULL,
	[SILINDI] [int] NULL,
	[CEKID] [int] NULL,
	[KDV] [float] NULL,
	[BELGENO] [nvarchar](30) NULL,
	[BELGEACIKLAMA] [nvarchar](500) NULL,
	[BELGETARIH] [datetime] NULL,
	[TEVKIFATKODU] [nvarchar](5) NULL,
	[TEVKIFATYUZDE] [float] NULL,
	[KISISAYI] [int] NULL,
	[RESMIKURUMKODU] [nvarchar](5) NULL,
	[TVKKDVPAY] [int] NULL,
	[TVKKDVPAYDA] [int] NULL,
	[KDVISTISNATUR] [nvarchar](5) NULL,
	[BANKAID] [int] NULL,
	[KAPANAN2] [float] NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[BANKAEKSTREDETAYID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[SSIRA] [int] NULL,
	[BELGETURU] [int] NULL,
	[ODEMEYONTEMI] [nvarchar](300) NULL,
	[GERCEKLESTIID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIMFIYAT] [float] NULL,
	[OZELKODID] [int] NULL,
	[CKARSIHESAPID] [int] NULL,
	[GERCEKLESTI] [bit] NULL,
 CONSTRAINT [PK_MUH_HESAPISL] PRIMARY KEY CLUSTERED 
(
	[ISLEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_HESAPID_YDK_05032022]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO








 



--SELECT * FROM  [FNCQ_HESAPDETAY_TESTTT] ('2020-01-01', '2021-12-31', '93', '125651')
	
CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_HESAPID_YDK_05032022] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID=@KODU
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@KODU
GO
/****** Object:  Table [dbo].[SGRUP]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SGRUP](
	[SGRUPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GRUPKODU] [nvarchar](30) NULL,
	[GRUPADI] [nvarchar](150) NULL,
	[GRUPADIENG] [nvarchar](100) NULL,
	[ANAGRUPADI] [nvarchar](50) NULL,
	[ANAGRUPADIENG] [nvarchar](50) NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[GRUPTURU] [nvarchar](20) NULL,
	[ANAGRUPMU] [bit] NULL,
	[MUHALISHESAPID] [int] NULL,
	[MUHALISIADEHESAPID] [int] NULL,
	[MUHSATISHESAPID] [int] NULL,
	[MUHSATISIADEHESAPID] [int] NULL,
	[MUHSARFHESAPID] [int] NULL,
	[MUHVIRMANHESAPID] [int] NULL,
	[POSAKTIFMI] [bit] NULL,
	[MASRAF] [int] NULL,
	[VADEGUN] [int] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[ALKOLLU] [int] NULL,
	[MUHISKONTOHESAPID] [int] NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[SKODU] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[SGRUPPOSTURU] [smallint] NULL,
	[POSGRUBU] [nvarchar](10) NULL,
	[OZELKOD1] [nvarchar](10) NULL,
	[OLDSGRUPID] [int] NULL,
 CONSTRAINT [PK_SGRUP] PRIMARY KEY CLUSTERED 
(
	[SGRUPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAUSER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAUSER](
	[NOVAUSERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](30) NULL,
	[SIFRESI] [nvarchar](40) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[DEPARTMANI] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[ADRES] [nvarchar](150) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[TIP] [bit] NULL,
	[YETKIGRUPID] [int] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[DEPOID] [int] NULL,
	[MASMERID] [int] NULL,
	[DEPKODU] [nvarchar](5) NULL,
	[SKODU] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[GARSONID] [int] NULL,
	[IZINLIIPAKTIF] [bit] NULL,
	[IZINLIIP] [nvarchar](150) NULL,
	[VERSIYONNO] [nvarchar](20) NULL,
	[DEPID] [int] NULL,
	[KAPALISATIS] [bit] NULL,
	[FIYAT123] [bit] NULL,
	[OZELFIYAT] [bit] NULL,
	[FIYATDEGISTIR] [bit] NULL,
	[RESIMDEGISTIR] [bit] NULL,
	[RESIMURUNSEC] [bit] NULL,
	[INDIRIMVER] [bit] NULL,
	[KASAGOREBILIR] [bit] NULL,
	[SATISIPTAL] [bit] NULL,
	[SATISDUZELT] [bit] NULL,
	[SERBESTDEPO] [bit] NULL,
	[TUTARSALINDIRIM] [bit] NULL,
	[MOBILYETKISEVIYE] [smallint] NULL,
	[GUNCELLENDI] [bit] NULL,
	[UPDATE_DATE] [datetime] NULL,
	[IKYETKI] [bit] NULL,
	[IKDEPARTMANID] [int] NULL,
	[ONAYTIPI] [smallint] NULL,
	[TAMYETKI] [bit] NULL,
	[OZELRAPOR] [bit] NULL,
	[TUMPERSONEL] [bit] NULL,
	[KARTNO] [nvarchar](35) NULL,
	[ONAYSEVIYE] [smallint] NULL,
	[SATIRSIL] [bit] NULL,
	[ISLEMMENU] [bit] NULL,
 CONSTRAINT [PK_NOVAUSER] PRIMARY KEY CLUSTERED 
(
	[NOVAUSERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KDVMUAFTANIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KDVMUAFTANIM](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](10) NULL,
	[ACIKLAMA] [nvarchar](2000) NULL,
	[ORAN] [nvarchar](10) NULL,
	[VARSAYILANHESAPID] [int] NULL,
	[TIP] [int] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
 CONSTRAINT [PK_KDVMUAFTANIM] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_KDVMUAFTANIM] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KDVTANIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KDVTANIM](
	[KDVTANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ORAN] [float] NULL,
	[ALKOLLU] [int] NULL,
	[ALISHESAPID] [int] NULL,
	[ALISIADEHESAPID] [int] NULL,
	[SATISHESAPID] [int] NULL,
	[SATISIADEHESAPID] [int] NULL,
	[TEVKALISHESAPID] [int] NULL,
	[TEVKSATISHESAPID] [int] NULL,
	[TEVKALISIADEHESAPID] [int] NULL,
	[TEVKSATISIADEHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[GELIRENTKONTROLHESABIID] [int] NULL,
	[GELIRENTKONTROLIADEHESAPID] [int] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[YAZARKASASIRA] [smallint] NULL,
	[OKCAKTAR] [bit] NULL,
 CONSTRAINT [PK_KDVTANIM] PRIMARY KEY CLUSTERED 
(
	[KDVTANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_KDVTANIM] UNIQUE NONCLUSTERED 
(
	[KDVTANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLON_EFATISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_STOKISLON_EFATISL] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  'FATURA' AS FISTIPI, F.ADD_USERID AS EKLEYEN, KDVMUAFTANIM.KODU AS OZELKDVKODU, KDVMUAFTANIM.ACIKLAMA AS OZELKDVACIKLAMA, F.ISLEMGRUPID1, F.ISLEMGRUPID2, 
F.ISLEMGRUPID3, ISNULL(F.DEPOID,FI.RGDEPOID) AS DEPOID,ISNULL(F.TUR,-1) AS TUR, MF.FISTURADI AS ISLEM, FI.STOKID,STOK.ADI AS STOKADI, FI.ACIKLAMA, FI.FADET * ISNULL(F.TUR,-1) AS GCADET,F.FISTURID,
             F.IRSALIYETARIHI,F.IRSALIYENO,FD.EFATNO,FD.EFATURAACIKLAMA, FD.EFATURA_ENTREFNO,FD.EFATTURU, EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,FD.EFATURA_CEVAPREFNO,FD.UUID,
             FD.EFATURAZARF, FD.EFATURAINDYOK,FD.EFATURA_LOG, FD.EFATURA_SONGONTAR,FD.EFATURADURUM,
             FI.BFIYAT,ISNULL(FI.SATIRIND,0) SATIRIND, ISNULL(FI.SATIRIND2,0) SATIRIND2, F.FATNO,F.ALTCARIID,ALTCARI.KODU AS ALTCARIKODU,ALTCARI.UNVANI AS ALTCARIUNVANI, CARI.HESAPID AS CARIID ,
             CARI.KODU AS CARIKODU, CARI.ACIKLAMA AS CARIUNVANI, ISNULL(F.ULKEKODU,CARI.ULKEKODU) AS ULKEKODU,
             ISNULL(F.ADRES1,CARI.ADRES1) AS ADRES1,ISNULL(F.ADRES2,CARI.ADRES2) AS ADRES2,F.VDNO,F.VD,CARI.TEL1,CARI.TEL2,CARI.FAX,CARI.GSM,F.ADD_USERID,F.EDIT_USERID
             ,U.KODU  AS EKLEYENKODU,U.ADSOYAD AS EKLEYENADI,             FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)AS SATIRBTUTARI,
             (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)* FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 *  (100 - ISNULL(FI.SATIRIND2,0)) / 100  AS SATIRINDT,
             FI.BFIYAT *(1-(100 - ISNULL(F.INDORAN1,0)) / 100 *  (100 - ISNULL(F.INDORAN2,0)) / 100 *  (100 - ISNULL(F.INDORAN3,0)) / 100)  AS FALTIINDT,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
              / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100    AS NFIYAT, STOK.ADI,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 *
             (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100   * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR AS TOPLAM,
			        ISNULL(F.INDORAN1,0) INDORAN1, ISNULL(F.EKORAN1,0) EKORAN1, ISNULL(F.INDORAN2,0) INDORAN2, ISNULL(F.EKORAN2,0) EKORAN2, ISNULL(F.INDORAN3,0) INDORAN3, ISNULL(F.EKORAN3,0) EKORAN3,
             F.BAYIID, ISNULL(FI.SATISTID,F.SATISTID) SATISTID, CASE WHEN STOK.TURU<>'Hammadde' THEN STOK.SONMALIYET ELSE  STOK.SALISFIYAT END AS SALISFIYAT, STOK.KODU AS STOKKODU, F.TARIH,FI.ARATOPLAM,
             ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE, F.FATID, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,ISNULL(FI.SRMMRKID,F.MASMERID) AS MASMERID,
             CAST(NULL AS INTEGER) AS KDEPOID, STOK.GRUP AS SGRUPKODU, F.FIRMAID, F.SUBEID AS SUBEID,CAST(TUR AS NVARCHAR(15)) AS ISLEMDETAY, FI.FATISLID SATIRKNO,FI.SATINALMAISLID,
             STOK.BIRIM AS SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV AS KDV,FI.KDV2 AS KDV2,FI.OTV,FI.OIV,FI.FBIRIM,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.FADET,0) END) FADET,FI.FBFIYAT,
             F.TOPLAM AS FTTOPLAM, F.KDV AS FTKDV, F.GTOPLAM AS FTGTOPLAM, SG.GRUPADI AS SGRUPADI, ISNULL(SG.ALKOLLU,0) AS ALKOLLU,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) AS  GCADETM,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) AS USTGRUPKODU,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) AS ALTGRUPKODU, FI.HESAPID, NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU AS TURU,SAYIMBIRIMI,
             FI.TEVORAN, (F.IND1+F.IND2+F.IND3) AS FAINDTOPLAM,(F.SIND+F.IND1+F.IND2+F.IND3) AS INDTOPLAM, (FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)) AS BTUTAR,
             SG.MUHAISKHESAPID,SG.MUHSISKHESAPID,F.ADD_DATE,
             CARI.HESAPID AS ALISHESAPID, CARI.HESAPID AS CHESAPID, F.MASADURUMID,
             F.SAAT,F.DOVIZ, FI.DOVIZ AS DOVIZSATIR, FI.KUR AS KURSATIR, F.KUR,SUBELER.SUBEKODU,SUBELER.SUBEADI,F.ACIKLAMA AS FATACIKLAMA,
			 F.ODEMEHESAPID,F.ODENENTUTAR,F.ODENENTUTAR2,HSPODEYEN.KODU AS ODEMESEKLIKODU,
			 HSPODEYEN.ACIKLAMA AS ODEMESEKLIADI, FI.KDVACIKLAMA, 
			 FI.KDVSIZLIKKODU,FI.TEVKANUNKODU,EDEVLETDURUM,[ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
             FROM FATISL FI WITH (NOLOCK) INNER JOIN
                  FATURA F  WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
				  FATURADETAY AS FD WITH (NOLOCK) ON F.FATID=FD.FATID LEFT OUTER JOIN
                  MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID = ALTCARI.ALTCARIID LEFT OUTER JOIN
                  MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID LEFT OUTER JOIN
                  STOK WITH (NOLOCK)  ON FI.STOKID = STOK.STOKID LEFT OUTER JOIN
                  [NOVAUSER] U WITH (NOLOCK)  ON F.ADD_USERID = U.NOVAUSERID LEFT OUTER JOIN
                  SGRUP SG  WITH (NOLOCK) ON STOK.STOKGRUPID = SG.SGRUPID LEFT JOIN
                  MUH_HESAP AS HSPODEYEN    WITH (NOLOCK) ON F.ODEMEHESAPID = HSPODEYEN.HESAPID LEFT JOIN
                  QMUH_FISTUR AS MF   WITH (NOLOCK) ON  F.FISTURID = MF.FISTURID LEFT OUTER JOIN
                  KDVTANIM  WITH (NOLOCK) ON KDVTANIM.ORAN=FI.KDV AND KDVTANIM.FIRMAID=F.FIRMAID AND ISNULL(SG.ALKOLLU,0) = ISNULL(KDVTANIM.ALKOLLU,0)   LEFT OUTER JOIN
                  SUBELER WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
				  LEFT JOIN KDVMUAFTANIM ON STOK.OTVID=KDVMUAFTANIM.ID
					WHERE  ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)>=0 AND ( ISNULL(IRSALIYE,0)=0 OR  ( (ISNULL(IRSALIYE,0)=1) AND 
					( ISNULL(FATCOUNTER,0) =0) ) ) AND 1=1 AND F.FATID=@FATID
GO
/****** Object:  Table [dbo].[SERVISFORM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERVISFORM](
	[SERVISFORMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[MASMERID] [int] NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[FORMNO] [nvarchar](10) NULL,
	[PLANLAMATARIH] [smalldatetime] NULL,
	[PLANSAAT] [time](7) NULL,
	[BITISTARIH] [smalldatetime] NULL,
	[BITISSAAT] [time](7) NULL,
	[SERVISDURUMID] [int] NULL,
	[CARIID] [int] NULL,
	[UNVANI] [nvarchar](150) NULL,
	[ADRES] [nvarchar](150) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](20) NULL,
	[MARKA] [nvarchar](20) NULL,
	[MODEL] [nvarchar](20) NULL,
	[PLAKANO] [nvarchar](15) NULL,
	[RENK] [nvarchar](20) NULL,
	[KM] [int] NULL,
	[SERINO] [nvarchar](25) NULL,
	[SASINO] [nvarchar](25) NULL,
	[MOTORNO] [nvarchar](25) NULL,
	[EKCIHAZBILGI] [nvarchar](150) NULL,
	[FIRMAYETKILI] [nvarchar](30) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[MUSTERITALEBI] [nvarchar](350) NULL,
	[TESPITEDILENARIZA] [nvarchar](350) NULL,
	[YAPILANISLEMLER] [nvarchar](750) NULL,
	[TESLIMEDEN] [nvarchar](20) NULL,
	[TESLIMALAN] [nvarchar](20) NULL,
	[TOPLAM] [float] NULL,
	[INDIRIM] [float] NULL,
	[NETTOPLAM] [float] NULL,
	[FATID] [int] NULL,
	[FATUUID] [uniqueidentifier] NULL,
	[RENKKODU] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[ISIBASLATANUSERID] [int] NULL,
	[ISIBITIRENUSERID] [int] NULL,
	[PROJEID] [int] NULL,
	[DURUMID] [int] NULL,
	[SIL] [smallint] NULL,
	[ALTCARIID] [int] NULL,
 CONSTRAINT [PK_SERVISFORM] PRIMARY KEY CLUSTERED 
(
	[SERVISFORMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_FATURA_HESAPID_YDFK_05032022]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO











 



--SELECT * FROM  [FNCQ_HESAPDETAY_TESTTT] ('2020-01-01', '2021-12-31', '93', '125651')

CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_FATURA_HESAPID_YDFK_05032022] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID=@KODU
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID=@KODU
  UNION ALL
SELECT FIRMAID,FATID AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  SELECT FIRMAID,FATID AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, ACIK AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_FATISL] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,K.KODU AS KULLANICI, OZELKDVKODU,OZELKDVACIKLAMA,MG1.GRUPADI AS ISLEMGRUPADI1, FATNO,CARIID,ALTCARIID,FI.ALTCARIKODU,ALTCARIUNVANI,SATINALMAISLID, ISNULL(VADE,TARIH) AS FTVADE,ISLEM AS TURADI,FATID, 0 AS IRSALIYE,DEPO.DEPOADI,EKLEYENKODU,EKLEYENADI,
           FI.IRSALIYETARIHI,FI.IRSALIYENO,FI.EFATNO,FI.EFATURAACIKLAMA, FI.EFATURA_ENTREFNO,FI.EFATTURU, FI.EFATURA_CEVAPACK,FI.EFATURA_CEVAPTARIHI,           FI.EFATURA_CEVAPREFNO,FI.UUID,              FI.EFATURAZARF, FI.EFATURAINDYOK,FI.EFATURA_LOG, FI.EFATURA_SONGONTAR,FI.EFATURADURUM,FI.FBIRIM,FI.FADET,FI.FBFIYAT,
           STOKID, STOKKODU,FI.ADI AS STOKADI,  TURU,SATIRKNO AS FATISLID,FI.DEPOID,CARIKODU,CARIUNVANI AS CUNVANI, ULKEKODU,
           SBIRIMI AS BIRIM, SGRUPADI,GCADET , ABS(GCADET) AS ADET, HESAPID, KDV,KDV2,OTV,ROUND(BFIYAT,4) AS BFIYAT,  
	   ROUND(NFIYAT,4) AS NFIYAT, ROUND(ARATOPLAM,4) AS ARATOPLAM, ROUND(SALISFIYAT,4) AS SALISFIYAT,
           ADRES1,ADRES2,VDNO,VD,TEL1,TEL2,FAX,GSM,FI.FISTURID, SATISTID,ODEMEHESAPID,ODEMESEKLIKODU,ODEMESEKLIADI,          
	   CASE WHEN FTGTOPLAM<>0 THEN ABS(GCADET)*NFIYAT*(100+KDV)/100*(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))/FTGTOPLAM ELSE 0 END AS ODENEN,
           ROUND(ABS(GCADET)*NFIYAT,4) AS NTUTAR, ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),4) AS NSATISKDV, 
	   ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),4) AS NALISKDV, ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),4) AS KDVTUTAR,
           ROUND((CASE
             WHEN ISNULL(TEVORAN,'')<>'' THEN
               ((((NFIYAT*CASE WHEN GCADET>0.001 THEN GCADET ELSE GCADET*-1 END *KDV)) *
               CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
               /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )/100)
           ELSE 0 END),4)  TEVKDV,
          ROUND((GCADETM*NFIYAT),4) AS SATIRNTUTART, ROUND(FTTOPLAM,4) AS FTTOPLAM, ROUND(FTKDV,4) AS FTKDV, ROUND(FTGTOPLAM,4) AS FTGTOPLAM, DOVIZ,  KUR, DOVIZSATIR,KURSATIR, KDV AS ALISKDV, KDV AS SATISKDV, TUR,
           ROUND(SATIRBTUTARI,4) AS SATIRBTUTARI,
           ROUND(SATIRINDT,4) AS SATIRINDT,
           ROUND(FALTIINDT,4) AS FALTIINDT,ROUND(FAINDTOPLAM,2) AS FAINDTOPLAM,FI.ALKOLLU, FI.ACIKLAMA,
           FI.MASMERID, NULL AS SRMMRKKODU,TEVORAN,FI.ALISHESAPID AS ALISHESAPID,CHESAPID,SAAT,         FI.SUBEID ,SUBEKODU,SUBEADI, MG.GRUPKODU AS MASMERKODU ,           MG.GRUPADI AS MASMERADI,FATACIKLAMA,MASADURUMID,
           CASE WHEN ISNULL(MASADURUMID,0)=0 THEN 'MARKET' ELSE 'RESTORAN' END AS SATISSEKLI,FI.ADD_DATE, SATIRIND, SATIRIND2, KDVACIKLAMA,KDVSIZLIKKODU,TEVKANUNKODU,EDEVLETDURUM,
		   [ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
           FROM [FNCQ_STOKISLON_EFATISL] (@FATID)  FI
           LEFT OUTER JOIN DEPO WITH (NOLOCK) ON FI.DEPOID = DEPO.DEPOID
           LEFT OUTER JOIN MUH_GRUP MG WITH (NOLOCK) ON FI.MASMERID = MG.GRUPID
		   LEFT OUTER JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON FI.ISLEMGRUPID1=MG1.GRUPID
		   LEFT OUTER JOIN [NOVAUSER] AS K ON FI.EKLEYEN=K.NOVAUSERID
		   WHERE FI.FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_YDK_05032022]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO










CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_YDK_05032022] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1  AND M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLON_FATISL_ANALIZ]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_STOKISLON_FATISL_ANALIZ] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  'FATURA' AS FISTIPI, F.ADD_USERID AS EKLEYEN, KDVMUAFTANIM.KODU AS OZELKDVKODU, KDVMUAFTANIM.ACIKLAMA AS OZELKDVACIKLAMA, F.ISLEMGRUPID1, F.ISLEMGRUPID2, 
F.ISLEMGRUPID3, ISNULL(F.DEPOID,FI.RGDEPOID) AS DEPOID,ISNULL(F.TUR,-1) AS TUR, MF.FISTURADI AS ISLEM, FI.STOKID,STOK.ADI AS STOKADI, FI.ACIKLAMA, FI.ADET * ISNULL(F.TUR,-1) AS GCADET,F.FISTURID,
             F.IRSALIYETARIHI,F.IRSALIYENO,FD.EFATNO,FD.EFATURAACIKLAMA, FD.EFATURA_ENTREFNO,FD.EFATTURU, EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,FD.EFATURA_CEVAPREFNO,FD.UUID,
             FD.EFATURAZARF, FD.EFATURAINDYOK,FD.EFATURA_LOG, FD.EFATURA_SONGONTAR,FD.EFATURADURUM,
             FI.BFIYAT,ISNULL(FI.SATIRIND,0) SATIRIND, ISNULL(FI.SATIRIND2,0) SATIRIND2, F.FATNO,F.ALTCARIID,ALTCARI.KODU AS ALTCARIKODU,ALTCARI.UNVANI AS ALTCARIUNVANI, CARI.HESAPID AS CARIID ,
             CARI.KODU AS CARIKODU, CARI.ACIKLAMA AS CARIUNVANI, ISNULL(F.ULKEKODU,CARI.ULKEKODU) AS ULKEKODU,
             ISNULL(F.ADRES1,CARI.ADRES1) AS ADRES1,ISNULL(F.ADRES2,CARI.ADRES2) AS ADRES2,F.VDNO,F.VD,CARI.TEL1,CARI.TEL2,CARI.FAX,CARI.GSM,F.ADD_USERID,F.EDIT_USERID
             ,U.KODU  AS EKLEYENKODU,U.ADSOYAD AS EKLEYENADI,             FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)AS SATIRBTUTARI,
             (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)* FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 *  (100 - ISNULL(FI.SATIRIND2,0)) / 100  AS SATIRINDT,
             FI.BFIYAT *(1-(100 - ISNULL(F.INDORAN1,0)) / 100 *  (100 - ISNULL(F.INDORAN2,0)) / 100 *  (100 - ISNULL(F.INDORAN3,0)) / 100)  AS FALTIINDT,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
              / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100    AS NFIYAT, STOK.ADI,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 *
             (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100   * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR AS TOPLAM,
			        ISNULL(F.INDORAN1,0) INDORAN1, ISNULL(F.EKORAN1,0) EKORAN1, ISNULL(F.INDORAN2,0) INDORAN2, ISNULL(F.EKORAN2,0) EKORAN2, ISNULL(F.INDORAN3,0) INDORAN3, ISNULL(F.EKORAN3,0) EKORAN3,
             F.BAYIID, ISNULL(FI.SATISTID,F.SATISTID) SATISTID, CASE WHEN STOK.TURU<>'Hammadde' THEN STOK.SONMALIYET ELSE  STOK.SALISFIYAT END AS SALISFIYAT, STOK.KODU AS STOKKODU, F.TARIH,FI.ARATOPLAM,
             ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE, F.FATID, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,ISNULL(FI.SRMMRKID,F.MASMERID) AS MASMERID,
             CAST(NULL AS INTEGER) AS KDEPOID, STOK.GRUP AS SGRUPKODU, F.FIRMAID, F.SUBEID AS SUBEID,CAST(TUR AS NVARCHAR(15)) AS ISLEMDETAY, FI.FATISLID SATIRKNO,FI.SATINALMAISLID,
             STOK.BIRIM AS SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV AS KDV,FI.KDV2 AS KDV2,FI.OTV,FI.OIV,FI.FBIRIM,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.FADET,0) END) FADET,FI.FBFIYAT,
             F.TOPLAM AS FTTOPLAM, F.KDV AS FTKDV, F.GTOPLAM AS FTGTOPLAM, SG.GRUPADI AS SGRUPADI, ISNULL(SG.ALKOLLU,0) AS ALKOLLU,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) AS  GCADETM,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) AS USTGRUPKODU,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) AS ALTGRUPKODU, FI.HESAPID, NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU AS TURU,SAYIMBIRIMI,
             FI.TEVORAN, (F.IND1+F.IND2+F.IND3) AS FAINDTOPLAM,(F.SIND+F.IND1+F.IND2+F.IND3) AS INDTOPLAM, (FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)) AS BTUTAR,
             SG.MUHAISKHESAPID,SG.MUHSISKHESAPID,F.ADD_DATE,
             CARI.HESAPID AS ALISHESAPID, CARI.HESAPID AS CHESAPID, F.MASADURUMID,
             F.SAAT,F.DOVIZ,F.KUR,SUBELER.SUBEKODU,SUBELER.SUBEADI,F.ACIKLAMA AS FATACIKLAMA,
			 F.ODEMEHESAPID,F.ODENENTUTAR,F.ODENENTUTAR2,HSPODEYEN.KODU AS ODEMESEKLIKODU,
			 HSPODEYEN.ACIKLAMA AS ODEMESEKLIADI, FI.KDVACIKLAMA, 
			 FI.KDVSIZLIKKODU,FI.TEVKANUNKODU,EDEVLETDURUM,[ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
             FROM FATISL FI WITH (NOLOCK) INNER JOIN
                  FATURA F  WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
				  FATURADETAY AS FD WITH (NOLOCK) ON F.FATID=FD.FATID LEFT OUTER JOIN
                  MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID = ALTCARI.ALTCARIID LEFT OUTER JOIN
                  MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID LEFT OUTER JOIN
                  STOK WITH (NOLOCK)  ON FI.STOKID = STOK.STOKID LEFT OUTER JOIN
                  [NOVAUSER] U WITH (NOLOCK)  ON F.ADD_USERID = U.NOVAUSERID LEFT OUTER JOIN
                  SGRUP SG  WITH (NOLOCK) ON STOK.STOKGRUPID = SG.SGRUPID LEFT JOIN
                  MUH_HESAP AS HSPODEYEN    WITH (NOLOCK) ON F.ODEMEHESAPID = HSPODEYEN.HESAPID LEFT JOIN
                  QMUH_FISTUR AS MF   WITH (NOLOCK) ON  F.FISTURID = MF.FISTURID LEFT OUTER JOIN
                  KDVTANIM  WITH (NOLOCK) ON KDVTANIM.ORAN=FI.KDV AND KDVTANIM.FIRMAID=F.FIRMAID AND ISNULL(SG.ALKOLLU,0) = ISNULL(KDVTANIM.ALKOLLU,0)   LEFT OUTER JOIN
                  SUBELER WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
				  LEFT JOIN KDVMUAFTANIM ON STOK.OTVID=KDVMUAFTANIM.ID AND KDVMUAFTANIM.FIRMAID=F.FIRMAID
					WHERE ISNULL(F.SIL,0)=0 AND ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)>=0 AND ( ISNULL(IRSALIYE,0)=0 OR  ( (ISNULL(IRSALIYE,0)=1) AND 
					( ISNULL(FATCOUNTER,0) =0) ) ) AND 1=1 AND F.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATISL_ANALIZ]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_FATISL_ANALIZ] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,K.KODU AS KULLANICI, OZELKDVKODU,OZELKDVACIKLAMA,MG1.GRUPADI AS ISLEMGRUPADI1, FATNO,CARIID,ALTCARIID,FI.ALTCARIKODU,ALTCARIUNVANI,SATINALMAISLID, ISNULL(VADE,TARIH) AS FTVADE,ISLEM AS TURADI,FATID, 0 AS IRSALIYE,DEPO.DEPOADI,EKLEYENKODU,EKLEYENADI,
           FI.IRSALIYETARIHI,FI.IRSALIYENO,FI.EFATNO,FI.EFATURAACIKLAMA, FI.EFATURA_ENTREFNO,FI.EFATTURU, FI.EFATURA_CEVAPACK,FI.EFATURA_CEVAPTARIHI,           FI.EFATURA_CEVAPREFNO,FI.UUID,              FI.EFATURAZARF, FI.EFATURAINDYOK,FI.EFATURA_LOG, FI.EFATURA_SONGONTAR,FI.EFATURADURUM,FI.FBIRIM,FI.FADET,FI.FBFIYAT,
           STOKID, STOKKODU,FI.ADI AS STOKADI,  TURU,SATIRKNO AS FATISLID,FI.DEPOID,CARIKODU,CARIUNVANI AS CUNVANI, ULKEKODU,
           SBIRIMI AS BIRIM, SGRUPADI,GCADET , ABS(GCADET) AS ADET, HESAPID, KDV,KDV2,OTV,ROUND(BFIYAT,2) AS BFIYAT,  
	   ROUND(NFIYAT,2) AS NFIYAT, ROUND(ARATOPLAM,2) AS ARATOPLAM, ROUND(SALISFIYAT,2) AS SALISFIYAT,
           ADRES1,ADRES2,VDNO,VD,TEL1,TEL2,FAX,GSM,FI.FISTURID, SATISTID,ODEMEHESAPID,ODEMESEKLIKODU,ODEMESEKLIADI,          
	   CASE WHEN FTGTOPLAM<>0 THEN ABS(GCADET)*NFIYAT*(100+KDV)/100*(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))/FTGTOPLAM ELSE 0 END AS ODENEN,
           ROUND(ABS(GCADET)*NFIYAT,2) AS NTUTAR, ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),2) AS NSATISKDV, 
	   ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),2) AS NALISKDV, ROUND((ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0),2) AS KDVTUTAR,
           ROUND((CASE
             WHEN ISNULL(TEVORAN,'')<>'' THEN
               ((((NFIYAT*CASE WHEN GCADET>0.001 THEN GCADET ELSE GCADET*-1 END *KDV)) *
               CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
               /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )/100)
           ELSE 0 END),2)  TEVKDV,
          ROUND((GCADETM*NFIYAT),2) AS SATIRNTUTART, ROUND(FTTOPLAM,2) AS FTTOPLAM, ROUND(FTKDV,2) AS FTKDV, ROUND(FTGTOPLAM,2) AS FTGTOPLAM, DOVIZ,  KUR, KDV AS ALISKDV, KDV AS SATISKDV, TUR,
           ROUND(SATIRBTUTARI,2) AS SATIRBTUTARI,
           ROUND(SATIRINDT,2) AS SATIRINDT,
           ROUND(FALTIINDT,2) AS FALTIINDT,ROUND(FAINDTOPLAM,2) AS FAINDTOPLAM,FI.ALKOLLU, FI.ACIKLAMA,
           FI.MASMERID, NULL AS SRMMRKKODU,TEVORAN,FI.ALISHESAPID AS ALISHESAPID,CHESAPID,SAAT,         FI.SUBEID ,SUBEKODU,SUBEADI, MG.GRUPKODU AS MASMERKODU ,           MG.GRUPADI AS MASMERADI,FATACIKLAMA,MASADURUMID,
           CASE WHEN ISNULL(MASADURUMID,0)=0 THEN 'MARKET' ELSE 'RESTORAN' END AS SATISSEKLI,FI.ADD_DATE, SATIRIND, SATIRIND2, KDVACIKLAMA,KDVSIZLIKKODU,TEVKANUNKODU,EDEVLETDURUM,
		   [ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
           FROM FNCQ_STOKISLON_FATISL_ANALIZ (@FIRMAID)  FI
           LEFT OUTER JOIN DEPO WITH (NOLOCK) ON FI.DEPOID = DEPO.DEPOID
           LEFT OUTER JOIN MUH_GRUP MG WITH (NOLOCK) ON FI.MASMERID = MG.GRUPID
		   LEFT OUTER JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON FI.ISLEMGRUPID1=MG1.GRUPID
		   LEFT OUTER JOIN [NOVAUSER] AS K ON FI.EKLEYEN=K.NOVAUSERID
		   WHERE FI.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLON_FATISL_IRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_STOKISLON_FATISL_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
    SELECT  'FATURA' AS FISTIPI, F.ADD_USERID AS EKLEYEN, KDVMUAFTANIM.KODU AS OZELKDVKODU, KDVMUAFTANIM.ACIKLAMA AS OZELKDVACIKLAMA, F.ISLEMGRUPID1, F.ISLEMGRUPID2, F.ISLEMGRUPID3, ISNULL(F.DEPOID,FI.RGDEPOID) AS DEPOID,
		ISNULL(F.TUR,-1) AS TUR, MF.FISTURADI AS ISLEM, FI.STOKID,STOK.ADI AS STOKADI, FI.ACIKLAMA, FI.ADET * ISNULL(F.TUR,-1) AS GCADET,F.FISTURID,
             F.IRSALIYETARIHI,F.IRSALIYENO,FD.EFATNO,FD.EFATURAACIKLAMA, FD.EFATURA_ENTREFNO,FD.EFATTURU, EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,
			 FD.EFATURA_CEVAPREFNO,FD.UUID,
             FD.EFATURAZARF, FD.EFATURAINDYOK,FD.EFATURA_LOG, FD.EFATURA_SONGONTAR,FD.EFATURADURUM,
             FI.BFIYAT,ISNULL(FI.SATIRIND,0) SATIRIND, ISNULL(FI.SATIRIND2,0) SATIRIND2, F.FATNO,F.ALTCARIID,ALTCARI.KODU AS ALTCARIKODU,ALTCARI.UNVANI AS ALTCARIUNVANI, CARI.HESAPID AS CARIID ,
             CARI.KODU AS CARIKODU, CARI.ACIKLAMA AS CARIUNVANI, ISNULL(F.ULKEKODU,CARI.ULKEKODU) AS ULKEKODU,
             ISNULL(F.ADRES1,CARI.ADRES1) AS ADRES1,ISNULL(F.ADRES2,CARI.ADRES2) AS ADRES2,F.VDNO,F.VD,CARI.TEL1,CARI.TEL2,CARI.FAX,CARI.GSM,F.ADD_USERID,F.EDIT_USERID
             ,U.KODU AS EKLEYENKODU,U.ADSOYAD AS EKLEYENADI,             FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)AS SATIRBTUTARI,
             (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)* FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 *  (100 - ISNULL(FI.SATIRIND2,0)) / 100  AS SATIRINDT,
             FI.BFIYAT *(1-(100 - ISNULL(F.INDORAN1,0)) / 100 *  (100 - ISNULL(F.INDORAN2,0)) / 100 *  (100 - ISNULL(F.INDORAN3,0)) / 100)  AS FALTIINDT,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
              / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100    AS NFIYAT, STOK.ADI,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 *
             (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100   * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR AS TOPLAM,
			        ISNULL(F.INDORAN1,0) INDORAN1, ISNULL(F.EKORAN1,0) EKORAN1, ISNULL(F.INDORAN2,0) INDORAN2, ISNULL(F.EKORAN2,0) EKORAN2, ISNULL(F.INDORAN3,0) INDORAN3, ISNULL(F.EKORAN3,0) EKORAN3,
             F.BAYIID, ISNULL(FI.SATISTID,F.SATISTID) SATISTID, CASE WHEN STOK.TURU<>'Hammadde' THEN STOK.SONMALIYET ELSE  STOK.SALISFIYAT END AS SALISFIYAT, STOK.KODU AS STOKKODU, F.TARIH,FI.ARATOPLAM,
             ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE, F.FATID, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,ISNULL(FI.SRMMRKID,F.MASMERID) AS MASMERID,
             CAST(NULL AS INTEGER) AS KDEPOID, STOK.GRUP AS SGRUPKODU, F.SUBEID AS SUBEID,CAST(TUR AS NVARCHAR(15)) AS ISLEMDETAY, FI.FATISLID SATIRKNO,FI.SATINALMAISLID,
             STOK.BIRIM AS SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV AS KDV,FI.KDV2 AS KDV2,FI.OTV,FI.OIV,FI.FBIRIM,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.FADET,0) END) FADET,FI.FBFIYAT,
             F.TOPLAM AS FTTOPLAM, F.KDV AS FTKDV, F.GTOPLAM AS FTGTOPLAM, SG.GRUPADI AS SGRUPADI, ISNULL(SG.ALKOLLU,0) AS ALKOLLU,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) AS  GCADETM,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) AS USTGRUPKODU,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) AS ALTGRUPKODU, FI.HESAPID, NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU AS TURU,SAYIMBIRIMI,
             FI.TEVORAN, (F.IND1+F.IND2+F.IND3) AS FAINDTOPLAM,(F.SIND+F.IND1+F.IND2+F.IND3) AS INDTOPLAM, (FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)) AS BTUTAR,
             SG.MUHAISKHESAPID,SG.MUHSISKHESAPID,F.ADD_DATE,
             CARI.HESAPID AS ALISHESAPID, CARI.HESAPID AS CHESAPID, F.MASADURUMID,
             F.SAAT,F.DOVIZ,F.KUR,SUBELER.SUBEKODU,SUBELER.SUBEADI,F.ACIKLAMA AS FATACIKLAMA,
			 F.ODEMEHESAPID,F.ODENENTUTAR,F.ODENENTUTAR2,HSPODEYEN.KODU AS ODEMESEKLIKODU,
			 HSPODEYEN.ACIKLAMA AS ODEMESEKLIADI, FI.KDVACIKLAMA, 
			 FI.KDVSIZLIKKODU,FI.TEVKANUNKODU,EDEVLETDURUM,[ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
             FROM FATISL FI WITH (NOLOCK) INNER JOIN
                  FATURA F  WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
				  FATURADETAY AS FD WITH (NOLOCK) ON FI.FATID=FD.FATID LEFT OUTER JOIN
                  MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID = ALTCARI.ALTCARIID LEFT OUTER JOIN
                  MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID LEFT OUTER JOIN
                  STOK WITH (NOLOCK)  ON FI.STOKID = STOK.STOKID LEFT OUTER JOIN
                  NOVAUSER U WITH (NOLOCK)  ON F.ADD_USERID = U.NOVAUSERID LEFT OUTER JOIN
                  SGRUP SG  WITH (NOLOCK) ON STOK.STOKGRUPID = SG.SGRUPID LEFT JOIN
                  MUH_HESAP AS HSPODEYEN    WITH (NOLOCK) ON F.ODEMEHESAPID = HSPODEYEN.HESAPID LEFT JOIN
                  QMUH_FISTUR AS MF   WITH (NOLOCK) ON  F.FISTURID = MF.FISTURID LEFT OUTER JOIN
                  KDVTANIM  WITH (NOLOCK) ON KDVTANIM.ORAN=FI.KDV AND KDVTANIM.FIRMAID=F.FIRMAID AND ISNULL(SG.ALKOLLU,0) = ISNULL(KDVTANIM.ALKOLLU,0)   LEFT OUTER JOIN
                  SUBELER WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
				  LEFT JOIN KDVMUAFTANIM ON STOK.OTVID=KDVMUAFTANIM.ID AND KDVMUAFTANIM.FIRMAID=F.FIRMAID
			WHERE  ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)=-1 AND F.FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATISL_IRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_FATISL_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
           SELECT TARIH,K.KODU AS KULLANICI, OZELKDVKODU,OZELKDVACIKLAMA,MG1.GRUPADI AS ISLEMGRUPADI1, FATNO,CARIID,ALTCARIID,FI.ALTCARIKODU,ALTCARIUNVANI,SATINALMAISLID, ISNULL(VADE,TARIH) AS FTVADE,ISLEM AS TURADI,FATID, 0 AS IRSALIYE,DEPO.DEPOADI,EKLEYENKODU,EKLEYENADI,
           FI.IRSALIYETARIHI,FI.IRSALIYENO,FI.EFATNO,FI.EFATURAACIKLAMA, FI.EFATURA_ENTREFNO,FI.EFATTURU, FI.EFATURA_CEVAPACK,FI.EFATURA_CEVAPTARIHI,           FI.EFATURA_CEVAPREFNO,FI.UUID,              FI.EFATURAZARF, FI.EFATURAINDYOK,FI.EFATURA_LOG, FI.EFATURA_SONGONTAR,FI.EFATURADURUM,FI.FBIRIM,FI.FADET,FI.FBFIYAT,
           STOKID, STOKKODU,FI.ADI AS STOKADI,  TURU,SATIRKNO AS FATISLID,FI.DEPOID,CARIKODU,CARIUNVANI AS CUNVANI, ULKEKODU,
           SBIRIMI AS BIRIM, SGRUPADI,GCADET , ABS(GCADET) AS ADET, HESAPID, KDV,KDV2,OTV,BFIYAT,  NFIYAT, ARATOPLAM,SALISFIYAT,
           ADRES1,ADRES2,VDNO,VD,TEL1,TEL2,FAX,GSM,FI.FISTURID, ODEMEHESAPID,ODEMESEKLIKODU,ODEMESEKLIADI,          CASE WHEN FTGTOPLAM<>0 THEN ABS(GCADET)*NFIYAT*(100+KDV)/100*(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))/FTGTOPLAM ELSE 0 END AS ODENEN,
           ABS(GCADET)*NFIYAT AS NTUTAR, (ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0) AS NSATISKDV, (ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0) AS NALISKDV, (ABS(GCADET)*NFIYAT/100*(100+OTV)) *(KDV/100.0) AS KDVTUTAR,
           CASE
             WHEN ISNULL(TEVORAN,'')<>'' THEN
               ((((NFIYAT*CASE WHEN GCADET>0.001 THEN GCADET ELSE GCADET*-1 END *KDV)) *
               CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
               /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )/100)
           ELSE 0 END  TEVKDV,
          (GCADETM*NFIYAT) AS SATIRNTUTART, FTTOPLAM, FTKDV, FTGTOPLAM, DOVIZ,  KUR, KDV AS ALISKDV, KDV AS SATISKDV, TUR,
           SATIRBTUTARI,
           SATIRINDT,
           FALTIINDT,FAINDTOPLAM,FI.ALKOLLU, FI.ACIKLAMA,
           FI.MASMERID, NULL AS SRMMRKKODU,TEVORAN,FI.ALISHESAPID AS ALISHESAPID,CHESAPID,SAAT,         FI.SUBEID ,SUBEKODU,SUBEADI, MG.GRUPKODU AS MASMERKODU ,           MG.GRUPADI AS MASMERADI,FATACIKLAMA,MASADURUMID,
           CASE WHEN ISNULL(MASADURUMID,0)=0 THEN 'MARKET' ELSE 'RESTORAN' END AS SATISSEKLI,FI.ADD_DATE, SATIRIND, SATIRIND2, KDVACIKLAMA,KDVSIZLIKKODU,TEVKANUNKODU,EDEVLETDURUM,
		   [ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
           FROM [FNCQ_STOKISLON_FATISL_IRSALIYE] (@FATID) FI
           LEFT OUTER JOIN DEPO WITH (NOLOCK) ON FI.DEPOID = DEPO.DEPOID
           LEFT OUTER JOIN MUH_GRUP MG WITH (NOLOCK) ON FI.MASMERID = MG.GRUPID
		   LEFT OUTER JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON FI.ISLEMGRUPID1=MG1.GRUPID
           LEFT OUTER JOIN NOVAUSER AS K ON FI.EKLEYEN=K.NOVAUSERID
		   WHERE FI.FATID=@FATID
GO
/****** Object:  View [dbo].[QMUH_FISDURUM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE VIEW [dbo].[QMUH_FISDURUM] AS 
  SELECT -2 AS FISDURUMID,'Silindi' AS FISDURUM  UNION ALL   SELECT -1 ,'Planlandı' AS FISDURUM  UNION ALL   SELECT 0 ,'İşlemde' AS FISDURUM  UNION ALL   SELECT 1 ,'Muhasebeleşti' AS FISDURUM  UNION ALL   SELECT 2 ,'Onaylandı' AS FISDURUM  UNION ALL   SELECT 3 ,'YevNo Verildi ' AS FISDURUM  UNION ALL   SELECT 9 ,'Beyan Edildi' AS FISDURUM
GO
/****** Object:  View [dbo].[QMUH_HESAPTIP]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[QMUH_HESAPTIP] AS 
  SELECT 900 AS HESAPTIPID,'GENEL' AS HESAPTIPADI, '' ANAHESAPKODU 
  UNION ALL   
  SELECT 120,'Cari Alıcı','120' 
  UNION ALL   
  SELECT 100,'Kasa','100' 
  UNION ALL   
  SELECT 102,'Banka','102' 
  UNION ALL   
  SELECT 335,'Personel','335' 
  UNION ALL   
  SELECT 6,'Gelir','6' 
  UNION ALL   
  SELECT 7,'Gider','7' 
  UNION ALL   
  SELECT 150,'Stok','150' 
  UNION ALL   
  SELECT 101,'Alınan Çekler','101' 
  UNION ALL   
  SELECT 103,'Verilen Çekler','103' 
  UNION ALL   
  SELECT 331,'Ortaklar','331' 
  UNION ALL   
  SELECT 800,'Üyeler','800' 
  UNION ALL   
  SELECT 320,'Cari Satıcı','320'
  UNION ALL   
  SELECT 191,'Alış Kdv','191'
  UNION ALL   
  SELECT 391,'Satış Kdv','391'
GO
/****** Object:  View [dbo].[QMUH_BELGETURU]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE VIEW [dbo].[QMUH_BELGETURU] AS 
 SELECT -1 AS BELGETURUID , 'Diğer' AS BELGETURUADI, 'other' GIBBELGETURUADI, 'Diğer' GIBBELGETURUADITR  UNION ALL SELECT 0 , 'Belgesiz' , '' , null  UNION ALL SELECT 1 , 'Fatura' , 'invoice' , 'Fatura' UNION ALL SELECT 2 , 'Çek', 'check' , 'Çek' UNION ALL SELECT 3 , 'Senet', 'voucher' , 'Senet' UNION ALL SELECT 4 , 'Banka Dekont', 'receipt' , 'Makbuz' UNION ALL SELECT 5 , 'Z Raporu', 'other' , 'Diğer' UNION ALL SELECT 6 , 'Gider Pusulası', 'receipt' , 'Makbuz' UNION ALL SELECT 7 , 'Müstahsil', 'receipt' , 'Makbuz' UNION ALL SELECT 8 , 'Serbest Meslek', 'receipt' , 'Makbuz' UNION ALL SELECT 9 , 'Tahsil', 'receipt' , 'Makbuz' UNION ALL SELECT 10 , 'Tediye', 'receipt' , 'Makbuz' UNION ALL SELECT 11 , 'Yazar Kasa Fişi', 'receipt' , 'Makbuz' UNION ALL SELECT 12 , 'Kredi Kartı', 'receipt' , 'Makbuz' UNION ALL SELECT 13 , 'Maaş', 'other' , 'Diğer' UNION ALL SELECT 14 , 'Vergi', 'receipt' , 'Makbuz' UNION ALL SELECT 15 ,'Kur Farkı', 'other' , 'Diğer' UNION ALL SELECT 16 ,'Gelir Tahakkuk', 'other' , 'Diğer' UNION ALL SELECT 17 ,'Genel Dekont', 'receipt' , 'Makbuz' UNION ALL SELECT 18 ,'Müşteri Sipariş Belgesi', 'order-customer' , 'Müşteri Sipariş Belgesi' UNION ALL SELECT 19 ,'Satıcı Sipariş Belgesi', 'order-vendor' , 'Satıcı Sipariş Belgesi' UNION ALL SELECT 20 ,'Nakliye', 'shipment' , 'Navlun' UNION ALL SELECT 21 ,'Depo Transfer Fişi', 'other' , 'Diğer'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUH_HESAPISL2_FATURA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_QMUH_HESAPISL2_FATURA] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + '_' + CAST(F.FISID AS nvarchar(20)) +
	'_' + ISNULL(MK.KODU,'') + '_' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+'.Çeyrek' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+'.Hft' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+' '+MGF.ACIKLAMA,M.KODU+' '+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  PROJEID,     
	F.ADD_DATE, F.ADD_USERID,  ISNULL(USER_ADD.ADSOYAD,USER_ADD.KODU) AS EKLEYEN,  
	F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.ADD_DATE, F.ADD_USERID,
			  F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
/*Fis Baslik Tek Satir */
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

/*Fis Baslik Detayli */
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0
  
  UNION ALL
    SELECT SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID, CARIID AS HESAPID, NULL AS KARSIHESAPID, NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,NULL AS MERKEZIFC, 5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL,NULL,NULL,NULL,NULL,NULL, NULL AS MASMERID, NULL AS PROJEID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID
  
  UNION ALL

 SELECT FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, 0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,NULL AS MERKEZIFC, FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL,NULL,NULL,NULL,NULL,NULL, NULL AS MASMERID, NULL AS PROJEID,TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID

  UNION ALL

 SELECT FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,NULL AS MERKEZIFC, FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL,NULL,NULL,NULL,NULL,NULL, NULL AS MASMERID, NULL AS PROJEID,TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE abs(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 and FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID

  UNION ALL
  SELECT FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,NULL AS MERKEZIFC, FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL,NULL,NULL,NULL,NULL,NULL, NULL AS MASMERID, NULL AS PROJEID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID
  UNION ALL
  SELECT DEPOFISID*-1 AS FISID, NULL AS ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, ACIK AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,NULL AS MERKEZIFC, -11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL,NULL,NULL,NULL,NULL,NULL, NULL AS MASMERID, NULL AS PROJEID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID
  
  ) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID AND MGF.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_ADD WITH (NOLOCK)   ON F.ADD_USERID       = USER_ADD.NOVAUSERID
 WHERE  M.FIRMAID=@FIRMAID 
 ORDER BY F.TARIH, F.FISID, MK.KODU, ISLEMID
GO
/****** Object:  View [dbo].[QMUH_CEKTUR]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE VIEW [dbo].[QMUH_CEKTUR] AS 
  SELECT -1 AS CEKTURID,'Kendi Çekimiz' AS CEKTURU UNION ALL   SELECT -2 ,'Kendi Senedimiz' UNION ALL   SELECT  1 ,'Müşteri Çeki' UNION ALL   SELECT  2 ,'Müşteri Senedi'
GO
/****** Object:  Table [dbo].[CEKLER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKLER](
	[CEKID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[CEKTURID] [int] NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[TURU] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[BANKA] [nvarchar](50) NULL,
	[SUBE] [nvarchar](50) NULL,
	[HESAPNO] [nvarchar](50) NULL,
	[CEKNO] [nvarchar](50) NULL,
	[ILKSAHIBI] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](50) NULL,
	[NOTLAR] [nvarchar](250) NULL,
	[DTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[TLTUTAR] [float] NULL,
	[SILINDI] [int] NULL,
	[TESLIMEDEN] [nvarchar](50) NULL,
	[TESLIMALAN] [nvarchar](50) NULL,
	[CEKDURUMID] [smallint] NULL,
	[DURUMID] [smallint] NULL,
	[MASMERID] [int] NULL,
	[CEKALTCARIID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[ILKFISID] [int] NULL,
	[SONFISID] [int] NULL,
	[CEKHESAPID] [int] NULL,
	[SONHESAPID] [int] NULL,
	[SONALTCARIID] [int] NULL,
	[SONCEKHESAPID] [int] NULL,
	[SONCEKALTCARIID] [int] NULL,
	[SONCEKDURUMID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[CEKNOID] [int] NULL,
	[PROJEID] [int] NULL,
 CONSTRAINT [PK_CEKLER] PRIMARY KEY CLUSTERED 
(
	[CEKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_CEKLER] UNIQUE NONCLUSTERED 
(
	[CEKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_CEKLER]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_CEKLER] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT  C.CEKID, C.CEKTURID,C.FIRMAID,C.SUBEID,VADE,YEAR(VADE) AS VADEYIL,MONTH(VADE) AS VADEAY,TARIH,CEKTUR.CEKTURU,FISTUR.FISTURADI, 
H1.KODU AS HESAPKODU, H1.ACIKLAMA AS HESAPADI, H2.KODU AS CEKHESAPKODU, H2.ACIKLAMA AS CEKHESAPADI, ILKSAHIBI,
BANKA,SUBE,HESAPNO,CEKNO,DTUTAR,C.DOVIZ,TLTUTAR,TESLIMALAN,TESLIMEDEN,C.NOTLAR, MUH_GRUP.GRUPKODU AS PROJEKODU, MUH_GRUP.GRUPADI AS PROJEADI 
FROM CEKLER AS C WITH (NOLOCK) INNER JOIN QMUH_FISTUR AS FISTUR WITH (NOLOCK)  ON C.SONCEKDURUMID=FISTUR.FISTURID
LEFT JOIN MUH_HESAP AS H1 WITH (NOLOCK)  ON C.SONHESAPID=H1.HESAPID
LEFT JOIN MUH_HESAP AS H2 WITH (NOLOCK)  ON C.SONCEKHESAPID=H2.HESAPID
LEFT JOIN QMUH_CEKTUR AS CEKTUR WITH (NOLOCK)  ON C.CEKTURID=CEKTUR.CEKTURID
LEFT JOIN MUH_GRUP WITH (NOLOCK) ON C.PROJEID=MUH_GRUP.GRUPID
WHERE H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND C.FIRMAID=@FIRMAID AND ISNULL(C.SIL,0)=0
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUH_HESAPISL2_HESAPID]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE FUNCTION [dbo].[FNCQ_QMUH_HESAPISL2_HESAPID] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + '_' + CAST(F.FISID AS nvarchar(20)) +
	'_' + ISNULL(MK.KODU,'') + '_' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+'.Çeyrek' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+'.Hft' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO, ISNULL(F.TFISID,F.FISID) AS TFISID,
	ISNULL(F.TFISNO,F.FISNO) AS TFISNO,ISNULL(F.TFISTARIH,F.TARIH) AS TFISTARIH,
	ISNULL(F.TFISACIKLAMA,F.ACIKLAMA) AS TFISACIKLAMA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+' '+MGF.ACIKLAMA,M.KODU+' '+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  PROJEID,     
	F.ADD_DATE, F.ADD_USERID,  ISNULL(USER_ADD.ADSOYAD,USER_ADD.KODU) AS EKLEYEN,  F.EDIT_DATE,F.EDIT_USERID,
	ISNULL(USER_UPD.ADSOYAD,USER_UPD.KODU) AS GUNCELLEYEN, F.DEL_DATE ,F.DEL_USERID,
	ISNULL(USER_DEL.ADSOYAD,USER_DEL.KODU) AS SILEN, F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE  HI.HESAPID=@HESAPID AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
--Fis Baslik Tek Satir
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.FISHESAPID=@HESAPID AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

--Fis Baslik Detayli
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.FISHESAPID=@HESAPID AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID AND MGF.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_ADD WITH (NOLOCK)   ON F.ADD_USERID       = USER_ADD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_UPD WITH (NOLOCK)   ON F.EDIT_USERID        = USER_UPD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_DEL WITH (NOLOCK)   ON F.DEL_USERID        = USER_DEL.NOVAUSERID
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@HESAPID
 ORDER BY F.TARIH, F.FISID, MK.KODU, ISLEMID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKSONALIS_IRSALIYELI]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKSONALIS_IRSALIYELI] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT FI.FATISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, F.FISHESAPID AS CARIID, F.UNVANI AS CARIUNVANI, F.TARIH, 
         F.FATNO, FI.BFIYAT, FI.FBFIYAT, FI.KDV AS SONKDV, FI.FBIRIM AS SONABIRIM, FI.FADET AS SONADET,  
         ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT, 
         ISNULL((((((((FI.FBFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFBFIYAT, 		  
		  FI.SKTARIHI   
  FROM FATURA F WITH (NOLOCK) INNER JOIN   
       FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=-1  AND FI.BFIYAT>0 AND  
                                    ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
       STOK S WITH (NOLOCK) ON FI.STOKID = S.STOKID and S.FIRMAID=@FIRMAID INNER JOIN  
       ( 
        SELECT FI.STOKID,MAX(FATISLID) SONFATISLID   
        FROM FATURA F WITH (NOLOCK) INNER JOIN   
             FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=-1  AND FI.BFIYAT>0 AND  
                                          ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
      	    ( 
 			 SELECT MAX(F.TARIH ) SONTARIH, FI.STOKID   
 			 FROM FATURA F WITH (NOLOCK) INNER JOIN   
 				    FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=-1  AND  
 				                               FI.BFIYAT>0 AND ISNULL(IRSALIYE,0)=0 AND F.TUR = 1 AND FISTURID=51 AND F.FIRMAID=@FIRMAID ) 
 			 GROUP BY  FI.STOKID 
 			  ) QFAT ON FI.STOKID = QFAT.STOKID AND F.TARIH  = QFAT.SONTARIH   
        GROUP BY  FI.STOKID 
        ) QSTSONFATISL  ON FI.STOKID = QSTSONFATISL.STOKID AND FI.FATISLID = QSTSONFATISL.SONFATISLID   
 
 UNION ALL 
 SELECT FI.DEPOFISISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, NULL AS CARIID, 'AÇILIŞ FİŞİ' AS CARIUNVANI, F.TARIH, 
        NULL, FI.BFIYAT, FI.FBFIYAT, 0, FI.FBIRIM AS SONABIRIM, FI.MIKTAR AS SONADET, 
        FI.BFIYAT, FI.FBFIYAT,FI.SKTARIHI 
 FROM DEPOFIS AS F WITH (NOLOCK)
      INNER JOIN DEPOFISISL FI WITH (NOLOCK) ON  F.DEPOFISID=FI.DEPOFISID 
      INNER JOIN STOK S WITH (NOLOCK) ON S.STOKID=FI.STOKID 
 WHERE F.FIRMAID=@FIRMAID AND F.ACIKLAMA='SYSACILIS'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUH_HESAPISLYEVMIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_QMUH_HESAPISLYEVMIYE] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN SELECT TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + '_' + CAST(F.FISID AS nvarchar(20)) +
	'_' + ISNULL(MK.KODU,'') + '_' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+'.Çeyrek' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+'.Hft' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,REPLACE(F.YEVMACIKLAMA,char(13) + char(10), '') AS YEVMACIKLAMA,F.BELGENO, F.TFISID,
	F.TFISNO,F.TFISTARIH,F.TFISACIKLAMA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	REPLACE(CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END,char(13) + char(10), '') ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,BTURU.GIBBELGETURUADITR,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP, ISNULL(AC.VADEGUN,M.VADEGUN) VADEGUN,DATEADD(DAY,ISNULL(ISNULL(AC.VADEGUN,M.VADEGUN),0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+' '+MGF.ACIKLAMA,M.KODU+' '+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID,ISLEMGRUPID1,
	ISLEMGRUPID2,ISLEMGRUPID3,
	F.MASMERID,  PROJEID,     
	F.ADD_DATE, F.ADD_USERID,  ISNULL(USER_ADD.ADSOYAD,USER_ADD.KODU) AS EKLEYEN, USER_ADD.GOREVI AS EKLEYENGOREVI, F.EDIT_DATE,F.EDIT_USERID,
	ISNULL(USER_UPD.ADSOYAD,USER_UPD.KODU) AS GUNCELLEYEN, USER_UPD.GOREVI AS GUNCELLEYENGOREVI,F.DEL_DATE ,F.DEL_USERID,
	ISNULL(USER_DEL.ADSOYAD,USER_DEL.KODU) AS SILEN, USER_DEL.GOREVI AS SILENGOREVI, F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,REPLACE(F.FISACIKLAMA, char(13) + char(10),'') AS FISACIKLAMA,ODEMEYONTEMI,F.FISTOPLAM 
 FROM (   SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK, ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO, ISNULL(HI.BELGEACIKLAMA,F.BELGEACIKLAMA) BELGEACIKLAMA, ISNULL(HI.ODEMEYONTEMI,F.ODEMEYONTEMI) ODEMEYONTEMI,HI.YEVSATIRSIRANO, F.ACIKLAMA FISACIKLAMA,F.TOPLAM FISTOPLAM,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,HI.MIKTAR, 
  HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN   
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID 
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND  ISNULL(SIL,0)=0 AND  ISNULL(F.FISTURID,1)>0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)  
  UNION ALL  


--Fis Baslik Tek Satir 
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,                CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,              
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK, 
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,              
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK, 
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA,F.ODEMEYONTEMI ODEMEYONTEMI,F.YEVSATIRSIRANO,F.ACIKLAMA FISACIKLAMA,F.TOPLAM FISTOPLAM, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI, NULL AS MIKTAR, 
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU,F.TARIH BELGETARIH,F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID     
			   FROM       MUH_FIS F WITH (NOLOCK) LEFT OUTER JOIN               
              QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID FULL JOIN               MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1 
              WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0 AND ISNULL(F.FISTURID,1)>0 AND  ISNULL(F.PASIF,0)=0 AND ISNULL(F.FISDURUMID,0)>=0 AND (F.FISHESAPID IS NOT NULL)) AS 
			  F         
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID AND MGF.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID

 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_ADD WITH (NOLOCK)   ON F.ADD_USERID       = USER_ADD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_UPD WITH (NOLOCK)   ON F.EDIT_USERID        = USER_UPD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_DEL WITH (NOLOCK)   ON F.DEL_USERID        = USER_DEL.NOVAUSERID
 WHERE M.FIRMAID=@FIRMAID AND ISNULL(BORC,0)+ISNULL(ALACAK,0)>0
-- ORDER BY F.TARIH, F.FISID, MK.KODU, ISLEMID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLON_FATISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_STOKISLON_FATISL] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  'FATURA' AS FISTIPI, F.ADD_USERID AS EKLEYEN, KDVMUAFTANIM.KODU AS OZELKDVKODU, KDVMUAFTANIM.ACIKLAMA AS OZELKDVACIKLAMA, F.ISLEMGRUPID1, F.ISLEMGRUPID2, 
F.ISLEMGRUPID3, ISNULL(F.DEPOID,FI.RGDEPOID) AS DEPOID,ISNULL(F.TUR,-1) AS TUR, MF.FISTURADI AS ISLEM, FI.STOKID,STOK.ADI AS STOKADI, FI.ACIKLAMA, FI.ADET * ISNULL(F.TUR,-1) AS GCADET,F.FISTURID,
             F.IRSALIYETARIHI,F.IRSALIYENO,FD.EFATNO,FD.EFATURAACIKLAMA, FD.EFATURA_ENTREFNO,FD.EFATTURU, EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,FD.EFATURA_CEVAPREFNO,FD.UUID,
             FD.EFATURAZARF, FD.EFATURAINDYOK,FD.EFATURA_LOG, FD.EFATURA_SONGONTAR,FD.EFATURADURUM,
             FI.BFIYAT,ISNULL(FI.SATIRIND,0) SATIRIND, ISNULL(FI.SATIRIND2,0) SATIRIND2, F.FATNO,F.ALTCARIID,ALTCARI.KODU AS ALTCARIKODU,ALTCARI.UNVANI AS ALTCARIUNVANI, CARI.HESAPID AS CARIID ,
             CARI.KODU AS CARIKODU, CARI.ACIKLAMA AS CARIUNVANI, ISNULL(F.ULKEKODU,CARI.ULKEKODU) AS ULKEKODU,
             ISNULL(F.ADRES1,CARI.ADRES1) AS ADRES1,ISNULL(F.ADRES2,CARI.ADRES2) AS ADRES2,F.VDNO,F.VD,CARI.TEL1,CARI.TEL2,CARI.FAX,CARI.GSM,F.ADD_USERID,F.EDIT_USERID
             ,U.KODU  AS EKLEYENKODU,U.ADSOYAD AS EKLEYENADI,             FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)AS SATIRBTUTARI,
             (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)* FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 *  (100 - ISNULL(FI.SATIRIND2,0)) / 100  AS SATIRINDT,
             FI.BFIYAT *(1-(100 - ISNULL(F.INDORAN1,0)) / 100 *  (100 - ISNULL(F.INDORAN2,0)) / 100 *  (100 - ISNULL(F.INDORAN3,0)) / 100)  AS FALTIINDT,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
              / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100    AS NFIYAT, STOK.ADI,
             FI.BFIYAT * (100 - ISNULL(FI.SATIRIND,0)) / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 *
             (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100   * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR AS TOPLAM,
			        ISNULL(F.INDORAN1,0) INDORAN1, ISNULL(F.EKORAN1,0) EKORAN1, ISNULL(F.INDORAN2,0) INDORAN2, ISNULL(F.EKORAN2,0) EKORAN2, ISNULL(F.INDORAN3,0) INDORAN3, ISNULL(F.EKORAN3,0) EKORAN3,
             F.BAYIID, ISNULL(FI.SATISTID,F.SATISTID) SATISTID, CASE WHEN STOK.TURU<>'Hammadde' THEN STOK.SONMALIYET ELSE  STOK.SALISFIYAT END AS SALISFIYAT, STOK.KODU AS STOKKODU, F.TARIH,FI.ARATOPLAM,
             ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE, F.FATID, STOK.SKOMORAN AS STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,ISNULL(FI.SRMMRKID,F.MASMERID) AS MASMERID,
             CAST(NULL AS INTEGER) AS KDEPOID, STOK.GRUP AS SGRUPKODU, F.FIRMAID, F.SUBEID AS SUBEID,CAST(TUR AS NVARCHAR(15)) AS ISLEMDETAY, FI.FATISLID SATIRKNO,FI.SATINALMAISLID,
             STOK.BIRIM AS SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV AS KDV,FI.KDV2 AS KDV2,FI.OTV,FI.OIV,FI.FBIRIM,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.FADET,0) END) FADET,FI.FBFIYAT,
             F.TOPLAM AS FTTOPLAM, F.KDV AS FTKDV, F.GTOPLAM AS FTGTOPLAM, SG.GRUPADI AS SGRUPADI, ISNULL(SG.ALKOLLU,0) AS ALKOLLU,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) AS  GCADETM,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) AS ANAGRUPKODU, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) AS USTGRUPKODU,
             SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) AS ALTGRUPKODU, FI.HESAPID, NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU AS TURU,SAYIMBIRIMI,
             FI.TEVORAN, (F.IND1+F.IND2+F.IND3) AS FAINDTOPLAM,(F.SIND+F.IND1+F.IND2+F.IND3) AS INDTOPLAM, (FI.BFIYAT*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END)) AS BTUTAR,
             SG.MUHAISKHESAPID,SG.MUHSISKHESAPID,F.ADD_DATE,
             CARI.HESAPID AS ALISHESAPID, CARI.HESAPID AS CHESAPID, F.MASADURUMID,
             F.SAAT,F.DOVIZ,F.KUR,SUBELER.SUBEKODU,SUBELER.SUBEADI,F.ACIKLAMA AS FATACIKLAMA,
			 F.ODEMEHESAPID,F.ODENENTUTAR,F.ODENENTUTAR2,HSPODEYEN.KODU AS ODEMESEKLIKODU,
			 HSPODEYEN.ACIKLAMA AS ODEMESEKLIADI, FI.KDVACIKLAMA, 
			 FI.KDVSIZLIKKODU,FI.TEVKANUNKODU,EDEVLETDURUM,[ONLINE],ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
			 ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,TEVKANUNACIKLAMA 
             FROM FATISL FI WITH (NOLOCK) INNER JOIN
                  FATURA F  WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
				  FATURADETAY AS FD WITH (NOLOCK) ON F.FATID=FD.FATID LEFT OUTER JOIN
                  MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID = ALTCARI.ALTCARIID LEFT OUTER JOIN
                  MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID LEFT OUTER JOIN
                  STOK WITH (NOLOCK)  ON FI.STOKID = STOK.STOKID LEFT OUTER JOIN
                  [NOVAUSER] U WITH (NOLOCK)  ON F.ADD_USERID = U.NOVAUSERID LEFT OUTER JOIN
                  SGRUP SG  WITH (NOLOCK) ON STOK.STOKGRUPID = SG.SGRUPID LEFT JOIN
                  MUH_HESAP AS HSPODEYEN    WITH (NOLOCK) ON F.ODEMEHESAPID = HSPODEYEN.HESAPID LEFT JOIN
                  QMUH_FISTUR AS MF   WITH (NOLOCK) ON  F.FISTURID = MF.FISTURID LEFT OUTER JOIN
                  KDVTANIM  WITH (NOLOCK) ON KDVTANIM.ORAN=FI.KDV AND KDVTANIM.FIRMAID=F.FIRMAID AND ISNULL(SG.ALKOLLU,0) = ISNULL(KDVTANIM.ALKOLLU,0)   LEFT OUTER JOIN
                  SUBELER WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
				  LEFT JOIN KDVMUAFTANIM ON STOK.OTVID=KDVMUAFTANIM.ID AND KDVMUAFTANIM.FIRMAID=F.FIRMAID
					WHERE  ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)>=0 AND ( ISNULL(IRSALIYE,0)=0 OR  ( (ISNULL(IRSALIYE,0)=1) AND 
					( ISNULL(FATCOUNTER,0) =0) ) ) AND 1=1 AND F.FATID=@FATID
GO
/****** Object:  Table [dbo].[SATISODEME]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SATISODEME](
	[SATISODEMEID] [int] IDENTITY(1,1) NOT NULL,
	[DEPOFISID] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL,
 CONSTRAINT [PK_SATISODEME] PRIMARY KEY CLUSTERED 
(
	[SATISODEMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETTAHSILAT]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETTAHSILAT] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TUKETIMFIS.TARIH,DEPO.DEPOADI, ZAMAN,CASE WHEN ISLEMTIPI=1 THEN '01-GİREN' ELSE '022-ÇIKAN' END AS TUR,KASIYER,ODEMETURU,SATISODEME.ACIKLAMA AS ISLEM,TUTAR,KUR,DOVIZ,TUTAR*KUR AS TLTUTAR 
FROM SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND  TUKETIMFIS.FIRMAID=@FIRMAID AND TUKETIMFIS.TARIH BETWEEN @TARIH1 AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_CARI_PROJE_ANALIZ]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_CARI_PROJE_ANALIZ] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TUKETIMFIS.FIRMAID,TARIH,'01-STOK/MALZEME' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, TEMPITSID AS ENTKAYNAKID,
DEPOFISISLID AS ISLEMID,KARSI.ACIKLAMA AS ALICIHESAPADI, MUH_HESAP.ACIKLAMA AS SATICIHESAPADI, STOK.ADI+' '+ISNULL(TUKETIMFISISL.ACIKLAMA,'') AS ACIKLAMA, 
FMIKTAR AS MIKTAR, FBIRIM AS BIRIM, FBFIYAT AS BIRIMFIYAT,
FMIKTAR*FBFIYAT AS TUTAR, FBMALIYET AS SATISTUTARI,ISNULL(FBMALIYET,0)-(FMIKTAR*FBFIYAT) AS KARTUTAR  
FROM TUKETIMFIS INNER JOIN TUKETIMFISISL ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID 
INNER JOIN MUH_HESAP ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID
LEFT JOIN MUH_GRUP ON TUKETIMFIS.PROJEID=MUH_GRUP.GRUPID
LEFT JOIN MUH_HESAP AS KARSI ON TUKETIMFISISL.ETSCARIID=KARSI.HESAPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND ETSCARIID>0
UNION ALL
SELECT FATURA.FIRMAID, TARIH,'01-STOK/MALZEME' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, KNO AS ENTKAYNAKID,FATISLID AS ISLEMID,KARSI.ACIKLAMA AS ALICIHESAPADI, MUH_HESAP.ACIKLAMA AS SATICIHESAPADI, STOK.ADI+' '+ISNULL(FATISL.ACIKLAMA,'') AS ACIKLAMA, 
FADET AS MIKTAR, FBIRIM AS BIRIM, FBFIYAT AS BIRIMFIYAT,
ARATOPLAM AS TUTAR, FATISL.TOPLAM AS SATISTUTARI, ISNULL(FATISL.TOPLAM,0)-ISNULL(ARATOPLAM,0) AS KARTUTAR 
FROM FATURA INNER JOIN FATISL ON FATURA.FATID=FATISL.FATID INNER JOIN MUH_HESAP ON FATURA.FISHESAPID=MUH_HESAP.HESAPID INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID
LEFT JOIN MUH_GRUP ON FATURA.PROJEID=MUH_GRUP.GRUPID
LEFT JOIN MUH_HESAP AS KARSI ON FATISL.FKARSIHESAPID=KARSI.HESAPID
WHERE ISNULL(FATURA.SIL,0)=0 AND FATURA.FIRMAID=@FIRMAID AND FKARSIHESAPID>0
UNION ALL 
SELECT MUH_FIS.FIRMAID,TARIH, '02-GİDERLER' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, ENTKAYNAKID, ISLEMID, KARSI.ACIKLAMA AS ALICIHESAPADI, MUH_HESAP.ACIKLAMA AS SATICIHESAPADI,MUH_HESAPISL.ACIKLAMA,MIKTAR,BIRIM,BIRIMFIYAT,
TUTAR,ISNULL(ODENMEYEN2,0) AS SATISTUTARI, ISNULL(ODENMEYEN2,0)-ISNULL(TUTAR,0) AS KARTUTAR  FROM MUH_FIS
INNER JOIN MUH_HESAPISL ON MUH_FIS.FISID=MUH_HESAPISL.FISID INNER JOIN MUH_HESAP ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
LEFT JOIN MUH_GRUP ON MUH_FIS.PROJEID=MUH_GRUP.GRUPID
LEFT JOIN MUH_HESAP AS KARSI ON MUH_HESAPISL.CKARSIHESAPID=KARSI.HESAPID
WHERE ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.FIRMAID=@FIRMAID AND CKARSIHESAPID>0
GO
/****** Object:  Table [dbo].[KASATESLIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KASATESLIM](
	[KASATESLIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ISLEM] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TLTUTAR] [float] NULL,
	[KASAACIKFAZLA] [float] NULL,
	[KALAN] [float] NULL,
	[YETKILI] [nvarchar](30) NULL,
	[AKTIFZAMAN] [datetime] NULL,
	[SIL] [smallint] NULL,
	[NAKITT] [float] NULL,
	[KKARTIT] [float] NULL,
	[NAKITA] [float] NULL,
	[KKARTIA] [float] NULL,
	[CNAKITODEME] [float] NULL,
	[CNAKITTAHSILAT] [float] NULL,
	[CKKARTIODEME] [float] NULL,
	[CKKARTITAHSILAT] [float] NULL,
	[ACIKHESAP] [float] NULL,
 CONSTRAINT [PK_KASATESLIM] PRIMARY KEY CLUSTERED 
(
	[KASATESLIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASATESLIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_KASATESLIM] (@FIRMAID INT, @SUBEID INT)  RETURNS  table  AS   
RETURN
		SELECT YETKILI,TARIH,GERCEKTARIH as AKTIFZAMAN,'SATIS' AS ISLEM,SUM(ISNULL(TOPLAM,0)) AS TOPLAM, 
		SUM(ISNULL(INDTUTAR,0)) AS INDTUTAR, SUM(ISNULL(TOPLAM,0)-ISNULL(INDTUTAR,0)) AS NETTOPLAM, 0.00 as KASAACIKFAZLA FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0
		GROUP BY YETKILI,TARIH,SUBEID,GERCEKTARIH
		UNION ALL
		SELECT MUH_FIS.ADD_USERID,TARIH,ADD_DATE AS AKTIFZAMAN,'TAHSILAT' AS ISLEM,SUM(TOPLAM) AS TOPLAM, 0.00,SUM(TOPLAM) AS TOPLAM,0.00 
		FROM MUH_FIS WHERE FISTURID IN(1,3) AND FISDEPOID>0
		AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 
		GROUP BY MUH_FIS.ADD_USERID,TARIH,SUBEID,ADD_DATE
		UNION ALL
		SELECT YETKILI,TARIH,AKTIFZAMAN,'KASA TESLIM' AS ISLEM,TLTUTAR*-1 AS TOPLAM,0.00 AS INDTUTAR, TLTUTAR*-1 AS NETTOPLAM, KASAACIKFAZLA AS KASAACIKFAZLA 
		FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0
		UNION ALL
		SELECT MUH_FIS.ADD_USERID,TARIH,ADD_DATE AS AKTIFZAMAN,'ÖDEMELER' AS ISLEM,SUM(TOPLAM)*-1 AS TOPLAM, 0.00,SUM(TOPLAM)*-1 AS TOPLAM,0.00 
		FROM MUH_FIS WHERE FISTURID IN(2,4) AND FISDEPOID>0
		AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 
		GROUP BY MUH_FIS.ADD_USERID,TARIH,SUBEID,ADD_DATE
GO
/****** Object:  Table [dbo].[EFATURA_FIRMA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_FIRMA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VDNO] [nvarchar](50) NULL,
	[KODU] [nvarchar](250) NULL,
	[UNVANI] [nvarchar](500) NULL,
	[TIPI] [nvarchar](10) NULL,
	[KAYITTARIHI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[FIRMATIPI] [smallint] NULL,
	[SUBEID] [int] NULL,
 CONSTRAINT [PK_EFATURA_FIRMA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[EFATURA_FIRMA_VIEW]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[EFATURA_FIRMA_VIEW] AS
			    SELECT * FROM EFATURA_FIRMA
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKSONALIS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKSONALIS] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT FI.FATISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, F.FISHESAPID AS CARIID,F.SUBEID, F.UNVANI AS CARIUNVANI, F.TARIH, 
         F.FATNO, FI.BFIYAT, FI.FBFIYAT, FI.KDV AS SONKDV, FI.FBIRIM AS SONABIRIM, FI.FADET AS SONADET,  
         ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT, 
         ISNULL((((((((FI.FBFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFBFIYAT, 		  
		  FI.SKTARIHI   
  FROM FATURA F WITH (NOLOCK) INNER JOIN   
       FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  FI.SATIRIND<100 AND ISNULL(F.FISDURUMID,0)>=0  AND FI.BFIYAT>0 AND  
                                    ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
       STOK S WITH (NOLOCK) ON FI.STOKID = S.STOKID and S.FIRMAID=@FIRMAID INNER JOIN  
       ( 
        SELECT F.SUBEID,FI.STOKID,MAX(FATISLID) SONFATISLID   
        FROM FATURA F WITH (NOLOCK) INNER JOIN   
             FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  FI.SATIRIND<100 AND ISNULL(F.FISDURUMID,0)>=0  AND FI.BFIYAT>0 AND  
                                          ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
      	    ( 
 			 SELECT SUBEID,MAX(F.TARIH ) SONTARIH, FI.STOKID   
 			 FROM FATURA F WITH (NOLOCK) INNER JOIN   
 				    FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  FI.SATIRIND<100 AND ISNULL(F.FISDURUMID,0)>=0  AND  
 				                               FI.BFIYAT>0 AND ISNULL(IRSALIYE,0)=0 AND F.TUR = 1 AND FISTURID=51 AND F.FIRMAID=@FIRMAID ) 
 			 GROUP BY SUBEID,FI.STOKID 
 			  ) QFAT ON FI.STOKID = QFAT.STOKID AND F.TARIH  = QFAT.SONTARIH   
        GROUP BY F.SUBEID,FI.STOKID 
        ) QSTSONFATISL  ON FI.STOKID = QSTSONFATISL.STOKID AND FI.FATISLID = QSTSONFATISL.SONFATISLID   
 
 UNION ALL 
 SELECT FI.DEPOFISISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, NULL AS CARIID,F.GSUBEID AS SUBEID, 'AÇILIŞ FİŞİ' AS CARIUNVANI, F.TARIH, 
        NULL, FI.BFIYAT, FI.FBFIYAT, 0, FI.FBIRIM AS SONABIRIM, FI.MIKTAR AS SONADET, 
        FI.BFIYAT, FI.FBFIYAT,FI.SKTARIHI 
 FROM DEPOFIS AS F 
      INNER JOIN DEPOFISISL FI WITH (NOLOCK) ON  F.DEPOFISID=FI.DEPOFISID 
      INNER JOIN STOK S ON S.STOKID=FI.STOKID 
 WHERE F.FIRMAID=@FIRMAID AND F.ISLEM='SAYIM'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKSONALIS2]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_STOKSONALIS2] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT FI.FATISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, F.FISHESAPID AS CARIID, F.UNVANI AS CARIUNVANI, F.TARIH, 
         F.FATNO, FI.BFIYAT, FI.FBFIYAT, FI.KDV AS SONKDV, FI.FBIRIM AS SONABIRIM, FI.FADET AS SONADET,  
         ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT, 
         ISNULL((((((((FI.FBFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFBFIYAT, 		  
		  FI.SKTARIHI   
  FROM FATURA F WITH (NOLOCK) INNER JOIN   
       FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=0  AND FI.BFIYAT>0 AND  
                                    ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
       STOK S WITH (NOLOCK) ON FI.STOKID = S.STOKID and S.FIRMAID=@FIRMAID INNER JOIN  
       ( 
        SELECT FI.STOKID,MAX(FATISLID) SONFATISLID   
        FROM FATURA F WITH (NOLOCK) INNER JOIN   
             FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=0  AND FI.BFIYAT>0 AND  
                                          ISNULL(IRSALIYE,0)=0 AND F.FISTURID=51 AND F.FIRMAID=@FIRMAID) INNER JOIN   
      	    ( 
 			 SELECT MAX(F.TARIH ) SONTARIH, FI.STOKID   
 			 FROM FATURA F WITH (NOLOCK) INNER JOIN   
 				    FATISL FI WITH (NOLOCK) ON ( F.FATID = FI.FATID AND  ISNULL(FI.SATIRIND,0)<100 AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISDURUMID,0)>=0  AND  
 				                               FI.BFIYAT>0 AND ISNULL(IRSALIYE,0)=0 AND F.TUR = 1 AND FISTURID=51 AND F.FIRMAID=@FIRMAID ) 
 			 GROUP BY  FI.STOKID 
 			  ) QFAT ON FI.STOKID = QFAT.STOKID AND F.TARIH  = QFAT.SONTARIH   
        GROUP BY  FI.STOKID 
        ) QSTSONFATISL  ON FI.STOKID = QSTSONFATISL.STOKID AND FI.FATISLID = QSTSONFATISL.SONFATISLID   
 
 UNION ALL 
 SELECT FI.DEPOFISISLID,FI.STOKID, S.ADI AS SADI, S.KODU, S.BIRIM AS SBIRIMI, NULL AS CARIID, 'AÇILIŞ FİŞİ' AS CARIUNVANI, F.TARIH, 
        NULL, FI.BFIYAT, FI.FBFIYAT, 0, FI.FBIRIM AS SONABIRIM, FI.MIKTAR AS SONADET, 
        FI.BFIYAT, FI.FBFIYAT,FI.SKTARIHI 
 FROM DEPOFIS AS F WITH (NOLOCK)
      INNER JOIN DEPOFISISL FI WITH (NOLOCK) ON  F.DEPOFISID=FI.DEPOFISID 
      INNER JOIN STOK S WITH (NOLOCK) ON S.STOKID=FI.STOKID 
 WHERE F.FIRMAID=@FIRMAID AND F.ACIKLAMA='SYSACILIS'
GO
/****** Object:  Table [dbo].[RESMITATIL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RESMITATIL](
	[RESMITATILLERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[IZINKODU] [nvarchar](10) NULL,
	[IZINADI] [nvarchar](50) NULL,
	[BASLANGIC] [smalldatetime] NULL,
	[BITIS] [smalldatetime] NULL,
	[RENKKODU] [nvarchar](20) NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [smalldatetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_RESMITATIL] PRIMARY KEY CLUSTERED 
(
	[RESMITATILLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TAKVIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TAKVIM](
	[TAKVIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
 CONSTRAINT [PK_TAKVIM] PRIMARY KEY CLUSTERED 
(
	[TAKVIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_RESMITATIL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_RESMITATIL] (@YIL INT, @AY INT, @FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT IZINKODU,IZINADI, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN,RENKKODU FROM RESMITATIL,TAKVIM WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND TARIH>=BASLANGIC AND TARIH<=BITIS
GO
/****** Object:  Table [dbo].[IKVARDIYA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYA](
	[IKVARDIYAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[HAFTABASI] [smalldatetime] NULL,
	[HAFTASONU] [smalldatetime] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[KILITLI] [smallint] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKVARDIYA] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKVARDIYATANIM]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYATANIM](
	[IKVARDIYATANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[VARDIYAKODU] [nvarchar](10) NULL,
	[VARDIYAADI] [nvarchar](20) NULL,
	[OZELKOD] [nvarchar](10) NULL,
	[GIRIS] [time](7) NULL,
	[CIKIS] [time](7) NULL,
	[TURU] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[VARDIYAANAGRUP] [nvarchar](20) NULL,
	[MESAIID] [int] NULL,
 CONSTRAINT [PK_IKVARDIYATANIM] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYATANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKVARDIYATARIH]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYATARIH](
	[IKVARDIYATARIHID] [int] IDENTITY(1,1) NOT NULL,
	[IKVARDIYAID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[PSICILID] [int] NULL,
	[IKVARDIYATANIMID] [int] NULL,
	[SAY] [int] NULL,
 CONSTRAINT [PK_IKVARDIYATARIH] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYATARIHID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERDEPART]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERDEPART](
	[PERDEPARTMANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPKODU] [nvarchar](20) NULL,
	[DEPADI] [nvarchar](50) NULL,
	[DEPMUDURU] [nvarchar](30) NULL,
	[DEPSEFI] [nvarchar](30) NULL,
	[ELKDEPKODU] [nvarchar](30) NULL,
	[ELKDEPADI] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_PERDEPART] PRIMARY KEY CLUSTERED 
(
	[PERDEPARTMANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKPERSONEL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKPERSONEL](
	[IKPERSONELID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FIRMA] [int] NULL,
	[PSICILID] [int] NULL,
	[AD] [nvarchar](20) NULL,
	[SOYAD] [nvarchar](20) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[UNVANID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[DEPKODU] [nvarchar](10) NULL,
	[CALISIYOR] [int] NULL,
	[GOREVI] [nvarchar](30) NULL,
	[MAXMESAI] [float] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[OZELKOD3] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[TCKIMLIKNO] [nvarchar](11) NULL,
 CONSTRAINT [PK_IKPERSONEL] PRIMARY KEY CLUSTERED 
(
	[IKPERSONELID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_VARDIYA_ANALIZ]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_VARDIYA_ANALIZ] (@FIRMAID INT, @YIL INT, @AY INT)  RETURNS  table  AS   
RETURN
SELECT YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN, TARIH, SUBELER.SUBEKODU, SUBELER.SUBEADI, VARDIYA.FIRMAID,VARDIYA.SUBEID,VARDIYA.DEPARTMANID,PERDEPART.ELKDEPADI, 
V.PSICILID,P.ADSOYAD,P.TCKIMLIKNO, V.IKVARDIYATANIMID,VARDIYAKODU,VARDIYAADI,OZELKOD,GIRIS,CIKIS,TURU,  SAY 
FROM IKVARDIYA AS VARDIYA WITH (NOLOCK) INNER JOIN IKVARDIYATARIH  AS V WITH (NOLOCK) ON VARDIYA.IKVARDIYAID=V.IKVARDIYAID
INNER JOIN PERDEPART WITH (NOLOCK) ON VARDIYA.DEPARTMANID=PERDEPART.PERDEPARTMANID
INNER JOIN IKVARDIYATANIM AS TANIM WITH (NOLOCK) ON V.IKVARDIYATANIMID=TANIM.IKVARDIYATANIMID
LEFT JOIN IKPERSONEL AS P WITH (NOLOCK) ON V.PSICILID=P.PSICILID AND ISNULL(P.SIL,0)=0
INNER JOIN SUBELER ON VARDIYA.SUBEID=SUBELER.SUBEID
WHERE  ISNULL(VARDIYA.SIL,0)=0 AND VARDIYA.FIRMAID=@FIRMAID AND YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETSATIS_FISKDV]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETSATIS_FISKDV] (@DEPOFISID INT)  RETURNS  table  AS   
RETURN
SELECT DEPOFISID, KDVORAN, SUM(FMIKTAR*FBFIYAT) AS BRUTTOPLAM, AVG(INDORAN) AS INDORAN,SUM((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN)) AS NETTOPLAM, 
SUM(((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN))/(100+KDVORAN)*100) AS MATRAH, 
SUM(((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN))/(100+KDVORAN)*KDVORAN) AS KDV  
FROM TUKETIMFISISL WHERE DEPOFISID=@DEPOFISID AND ISNULL(SILINDI,0)=0
GROUP BY DEPOFISID,KDVORAN
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATURA_IRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_EFATURA_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT 
   FISTURID,ISNULL(DOVIZ,'') FATURADOVIZI, ISNULL(ISNULL(EFATURAACIKLAMA, ACIKLAMA),'') ACIKLAMA,EFATURAACIKLAMA2,FATID,
   CARIID,UUID,FATNO,EFATNO,EFATURADURUM,EDEVLET_ILETIMYONTEMI,ISNULL(EDEVLETDURUM,1) EDEVLETDURUM,
   TARIH,SAAT,ROUND(TOPLAM,2) AS FATURATOPLAM,ROUND((TOPLAM+OTV),2) AS FATURAOTVLITOPLAM,ROUND(GTOPLAM,2) AS GENELTOPLAM, ROUND(TEVKIFATTOPLAM,2) AS TEVKIFATTOPLAM, ROUND(ISNULL(GTOPLAM,0),2)+ROUND(ISNULL(TEVKIFATTOPLAM,0),2) AS VDTOPLAM,
   ROUND(INDEKTOPLAM,2) AS FATURAINDIRIM,
   ROUND(KDV,2) AS FATURAKDV,ROUND(OTV,2) AS FATURAOTV,ROUND(NTOPLAM,2) AS FATURANETTOPLAM,
   FATUNVANI AS UNVANI,ISNULL(ADRES1,'') FATURADRES,ISNULL(ADRES2,'') FATURADRES2, ISNULL(ADRES3,'') AS FATURADRES3,VD,
   VDNO,TEL TEL1,FAX,EMAIL, WEB, EFATURAZARF, EFATURAINDYOK,
   EFATURA_LOG, EFATURA_SONGONTAR, /*DOVIZ*/ 'TL' AS DOVIZ, EFATURA_ENTREFNO,  FIRMAID, 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, KDVACIKLAMA,KDVSIZLIKKODU,      SIPARISNO, SIPARISTARIHI, IRSALIYENO,IRSALIYETARIHI,
   EFATURA_PKUTUSU, EFATURA_KABULREDNOTU, SUBEID GSUBEID, EFATURAACIKLAMA, VADE,
   ISNULL(ONLINE,0) ONLINE,ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
   ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,GBEYANNO, GBEYANTARIHI, GMAKBUZNO, GMAKBUZTARIHI, GIRISGUMRUK, ALISYAPILANFIRMA,ALISFNO, ALISFTARIHI, MODELYILI,SASINO,RENK,MOTORNO,  
   EI_SATICIVKNO	,EI_SATICIUNVAN	,EI_ALICIVKNO,EI_ALICIUNVAN	,EI_ISLEMBASLATANVKNO, 
   EI_ISLEMBASLATANUNVAN	,EI_TASIYICIVKNO	,EI_TASIYICIUNVAN,EI_ARACPLAKA	,EI_DORSEPLAKA	,
   EI_ARACSOFORADISOYADI ,EI_ARACSOFORID,EI_TESLIMATTANIM,EI_TESLIMATADRES,EI_TESLIMATILCE,EI_TESLIMATIL,EI_TESLIMATULKE,EFATURA_IBAN,EI_TASIYICIPOSTAKUTUSU 
   FROM [FNCQ_FATURA_IRSALIYE] (@FATID) 
   WHERE ISNULL(EFATURADURUM,0)>0  AND FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATISL_DETAY]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EFATISL_DETAY] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT QMUH_FATISL.FATID, QMUH_FATISL.FATISLID AS SATIRNO, 
       QMUH_FATISL.FADET SATIRADET,QMUH_FATISL.FBFIYAT SATIRBFIYAT,QMUH_FATISL.KDV AS SATIRKDVORAN,QMUH_FATISL.OTV AS OTV,
	   CASE WHEN (FATURA.FISTURID IN (61,62,63,64)) OR (FATURA.MODUL = 8192) OR (ISNULL(QMUH_FATISL.STOKID,-1) = -1) THEN QMUH_FATISL.ACIKLAMA ELSE QMUH_FATISL.STOKADI+(CASE WHEN QMUH_FATISL.ACIKLAMA<>'' THEN ' - '+QMUH_FATISL.ACIKLAMA ELSE '' END) END AS SATIRACIKLAMA,OZELKDVKODU,OZELKDVACIKLAMA,
	   QMUH_FATISL.SATIRIND, QMUH_FATISL.SATIRIND2, QMUH_FATISL.FBIRIM ,(QMUH_FATISL.NTUTAR/100*(100+QMUH_FATISL.OTV)) *(QMUH_FATISL.KDV/100.0) SATIRKDVTUTAR,QMUH_FATISL.KDV2,
	   QMUH_FATISL.SATIRNTUTART AS ARATOPLAM, QMUH_FATISL.KDVACIKLAMA, QMUH_FATISL.KDVSIZLIKKODU ,ROUND(ISNULL(QMUH_FATISL.TEVKDV,0),2) TEV_TUTAR,
	   ROUND(ISNULL(CASE WHEN QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV<>0 THEN ISNULL(ROUND(10000*QMUH_FATISL.TEVKDV/(QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV),2),0)  ELSE 0 END,0),0) TEV_ORAN,QMUH_FATISL.TEVKANUNKODU,QMUH_FATISL.TEVKANUNACIKLAMA 
FROM [FNCQ_FATISL] (@FATID) AS QMUH_FATISL
LEFT JOIN FATURA ON FATURA.FATID = QMUH_FATISL.FATID
WHERE ISNULL(QMUH_FATISL.EFATURADURUM,0)>0 AND FATURA.FATID=@FATID
GO
/****** Object:  Table [dbo].[IKVARDIYAAYLIK]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYAAYLIK](
	[IKVARDIYAAYLIKID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[YIL] [smallint] NULL,
	[AY] [smallint] NULL,
	[DEPARTMANID] [int] NULL,
	[PSICILID] [int] NULL,
	[V1] [int] NULL,
	[V2] [int] NULL,
	[V3] [int] NULL,
	[V4] [int] NULL,
	[V5] [int] NULL,
	[V6] [int] NULL,
	[V7] [int] NULL,
	[V8] [int] NULL,
	[V9] [int] NULL,
	[V10] [int] NULL,
	[V11] [int] NULL,
	[V12] [int] NULL,
	[V13] [int] NULL,
	[V14] [int] NULL,
	[V15] [int] NULL,
	[V16] [int] NULL,
	[V17] [int] NULL,
	[V18] [int] NULL,
	[V19] [int] NULL,
	[V20] [int] NULL,
	[V21] [int] NULL,
	[V22] [int] NULL,
	[V23] [int] NULL,
	[V24] [int] NULL,
	[V25] [int] NULL,
	[V26] [int] NULL,
	[V27] [int] NULL,
	[V28] [int] NULL,
	[V29] [int] NULL,
	[V30] [int] NULL,
	[V31] [int] NULL,
	[TMESAI] [int] NULL,
	[M1] [int] NULL,
	[M2] [int] NULL,
	[M3] [int] NULL,
	[M4] [int] NULL,
	[M5] [int] NULL,
	[M6] [int] NULL,
	[M7] [int] NULL,
	[M8] [int] NULL,
	[M9] [int] NULL,
	[M10] [int] NULL,
	[K1] [nvarchar](5) NULL,
	[K2] [nvarchar](5) NULL,
	[K3] [nvarchar](5) NULL,
	[K4] [nvarchar](5) NULL,
	[K5] [nvarchar](5) NULL,
	[K6] [nvarchar](5) NULL,
	[K7] [nvarchar](5) NULL,
	[K8] [nvarchar](5) NULL,
	[K9] [nvarchar](5) NULL,
	[K10] [nvarchar](5) NULL,
	[K11] [nvarchar](5) NULL,
	[K12] [nvarchar](5) NULL,
	[K13] [nvarchar](5) NULL,
	[K14] [nvarchar](5) NULL,
	[K15] [nvarchar](5) NULL,
	[K16] [nvarchar](5) NULL,
	[K17] [nvarchar](5) NULL,
	[K18] [nvarchar](5) NULL,
	[K19] [nvarchar](5) NULL,
	[K20] [nvarchar](5) NULL,
	[K21] [nvarchar](5) NULL,
	[K22] [nvarchar](5) NULL,
	[K23] [nvarchar](5) NULL,
	[K24] [nvarchar](5) NULL,
	[K25] [nvarchar](5) NULL,
	[K26] [nvarchar](5) NULL,
	[K27] [nvarchar](5) NULL,
	[K28] [nvarchar](5) NULL,
	[K29] [nvarchar](5) NULL,
	[K30] [nvarchar](5) NULL,
	[K31] [nvarchar](5) NULL,
	[TDIGER] [int] NULL,
 CONSTRAINT [PK_IKVARDIYAAYLIK] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYAAYLIKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_AYLIK_VARDIYA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_AYLIK_VARDIYA] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT SB.SUBEKODU,SB.SUBEADI,PD.DEPADI,PER.GOREVI, PER.ADSOYAD, PER.TCKIMLIKNO, PER.ISEGIRIS, PER.ISTENAYRILIS, V.* 
FROM IKVARDIYAAYLIK AS V WITH (NOLOCK) INNER JOIN SUBELER AS SB WITH (NOLOCK) ON V.SUBEID=SB.SUBEID
INNER JOIN PERDEPART AS PD WITH (NOLOCK) ON V.DEPARTMANID=PD.PERDEPARTMANID
INNER JOIN IKPERSONEL AS PER WITH (NOLOCK) ON V.PSICILID=PER.PSICILID
WHERE ISNULL(PER.SIL,0)=0 AND V.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATISL_DETAY_IRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EFATISL_DETAY_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN          
SELECT QMUH_FATISL.FATID, QMUH_FATISL.FATISLID AS SATIRNO,  
                QMUH_FATISL.FADET SATIRADET,QMUH_FATISL.FBFIYAT SATIRBFIYAT,QMUH_FATISL.KDV AS SATIRKDVORAN,QMUH_FATISL.OTV AS OTV, 
         	   CASE WHEN (FATURA.FISTURID IN (61,62,63,64)) OR (FATURA.MODUL = 8192) OR (ISNULL(QMUH_FATISL.STOKID,-1) = -1) THEN  
          QMUH_FATISL.ACIKLAMA ELSE QMUH_FATISL.STOKADI+(CASE WHEN QMUH_FATISL.ACIKLAMA<>'' THEN ' - '+QMUH_FATISL.ACIKLAMA ELSE '' END) END AS SATIRACIKLAMA,
          OZELKDVKODU,OZELKDVACIKLAMA,
         	   QMUH_FATISL.SATIRIND, QMUH_FATISL.SATIRIND2, QMUH_FATISL.FBIRIM ,(QMUH_FATISL.NTUTAR/100*(100+QMUH_FATISL.OTV)) *(QMUH_FATISL.KDV/100.0) SATIRKDVTUTAR,
			   QMUH_FATISL.KDV2, 
         	   QMUH_FATISL.SATIRNTUTART AS ARATOPLAM, QMUH_FATISL.KDVACIKLAMA, QMUH_FATISL.KDVSIZLIKKODU ,
			   ROUND(ISNULL(QMUH_FATISL.TEVKDV,0),2) TEV_TUTAR, 
         	   ROUND(ISNULL(CASE WHEN QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV<>0 THEN 
			   ISNULL(ROUND(10000*QMUH_FATISL.TEVKDV/(QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV),2),0)  ELSE 0 END,0),0) TEV_ORAN,QMUH_FATISL.TEVKANUNKODU,QMUH_FATISL.TEVKANUNACIKLAMA  
         FROM [FNCQ_FATISL_IRSALIYE] (@FATID)  as QMUH_FATISL
         LEFT JOIN FATURA(NOLOCK) ON FATURA.FATID = QMUH_FATISL.FATID 
         WHERE ISNULL(QMUH_FATISL.EFATURADURUM,0)>0 AND FATURA.FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATISL]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_EFATISL] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT QMUH_FATISL.FATID,QMUH_FATISL.FATISLID AS SATIRNO, 
       QMUH_FATISL.FADET SATIRADET,QMUH_FATISL.FBFIYAT SATIRBFIYAT,QMUH_FATISL.KDV AS SATIRKDVORAN,QMUH_FATISL.OTV AS OTV,
	   CASE WHEN (FATURA.FISTURID IN (61,62,63,64)) OR (FATURA.MODUL = 8192) OR (ISNULL(QMUH_FATISL.STOKID,-1) = -1) THEN QMUH_FATISL.ACIKLAMA ELSE QMUH_FATISL.STOKADI+(CASE WHEN QMUH_FATISL.ACIKLAMA<>'' THEN ' - '+QMUH_FATISL.ACIKLAMA ELSE '' END) END AS SATIRACIKLAMA,OZELKDVKODU,OZELKDVACIKLAMA,
	   QMUH_FATISL.SATIRIND, QMUH_FATISL.SATIRIND2, QMUH_FATISL.FBIRIM ,
	   (QMUH_FATISL.NTUTAR/100*(100+ISNULL(QMUH_FATISL.OTV,0))) *(QMUH_FATISL.KDV/100.0) SATIRKDVTUTAR,QMUH_FATISL.KDV2,
	   QMUH_FATISL.SATIRNTUTART AS ARATOPLAM, QMUH_FATISL.KDVACIKLAMA, QMUH_FATISL.KDVSIZLIKKODU ,ROUND(ISNULL(QMUH_FATISL.TEVKDV,0),2) TEV_TUTAR,
	   ROUND(ISNULL(CASE WHEN QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV<>0 THEN ISNULL(ROUND(10000*QMUH_FATISL.TEVKDV/(QMUH_FATISL.NTUTAR*QMUH_FATISL.KDV),2),0)  ELSE 0 END,0),0) TEV_ORAN,QMUH_FATISL.TEVKANUNKODU,QMUH_FATISL.TEVKANUNACIKLAMA 
FROM [FNCQ_FATISL] (@FATID) AS QMUH_FATISL
LEFT JOIN FATURA ON FATURA.FATID = QMUH_FATISL.FATID
WHERE ISNULL(QMUH_FATISL.EFATURADURUM,0)>0 AND FATURA.FATID=@FATID
GO
/****** Object:  Table [dbo].[FATURAIRSALIYE]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAIRSALIYE](
	[FATIRSID] [int] NULL,
	[FATID] [int] NULL,
	[IRSALIYENO] [nvarchar](50) NULL,
	[IRSALIYETARIHI] [datetime] NULL
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATIRS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EFATIRS] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN  
            SELECT  FATURA.FATID,FATIRSID, FATISL.IRSALIYENO , FATISL.IRSALIYETARIHI
          FROM FATURA AS FATURA
          INNER JOIN FATURAIRSALIYE AS FATISL ON FATISL.FATID=FATURA.FATID
          WHERE   ISNULL(FISDURUMID,0)>= -1 AND FATURA.FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATURA]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EFATURA] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN  
SELECT 
   FISTURID,ISNULL(DOVIZ,'') FATURADOVIZI, ISNULL(ISNULL(EFATURAACIKLAMA, ACIKLAMA),'') ACIKLAMA,EFATURAACIKLAMA2,F.FATID,
   F.FISHESAPID AS CARIID,UUID,FATNO,EFATNO,EFATURADURUM,EDEVLET_ILETIMYONTEMI,ISNULL(EDEVLETDURUM,1) EDEVLETDURUM,
   TARIH,SAAT,ROUND(TOPLAM,2) AS FATURATOPLAM,ROUND((TOPLAM+OTV),2) AS FATURAOTVLITOPLAM,ROUND(GTOPLAM,2) AS GENELTOPLAM, ROUND(TEVKIFATTOPLAM,2) AS TEVKIFATTOPLAM, ROUND(ISNULL(GTOPLAM,0),2)+ROUND(ISNULL(TEVKIFATTOPLAM,0),2) AS VDTOPLAM,
   ROUND((ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)),2) AS FATURAINDIRIM,
   ROUND(KDV,2) AS FATURAKDV,ROUND(OTV,2) AS FATURAOTV,ROUND(NTOPLAM,2) AS FATURANETTOPLAM,
   F.UNVANI,ISNULL(ADRES1,'') FATURADRES,ISNULL(ADRES2,'') FATURADRES2, ISNULL(ADRES3,'') AS FATURADRES3,VD,
   VDNO,TEL TEL1,FAX,EMAIL, WEB, EFATURAZARF, EFATURAINDYOK,
   EFATURA_LOG, EFATURA_SONGONTAR, 'TL' AS DOVIZ, EFATURA_ENTREFNO, F.FIRMAID, F.SUBEID, CASE WHEN ISNULL(F.KUR,1) = 0 THEN 1 ELSE ISNULL(F.KUR,1) END AS KUR,  ISNULL(EFATTURU,0) AS EFATTURU,
   EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,EFATURA_CEVAPREFNO,EFATURA_CEVAP_UUID,EFATURA_CEVAPNO, KDVACIKLAMA,KDVSIZLIKKODU, YEVNO,YEVMTARIH, SIPARISNO, SIPARISTARIHI, IRSALIYENO,IRSALIYETARIHI,
   EFATURA_PKUTUSU, EFATURA_KABULREDNOTU, SUBEID GSUBEID, EFATURAACIKLAMA, VADE,
   ISNULL(ONLINE,0) ONLINE,ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
   ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,GBEYANNO, GBEYANTARIHI, GMAKBUZNO, GMAKBUZTARIHI, GIRISGUMRUK, ALISYAPILANFIRMA,ALISFNO, ALISFTARIHI, MODELYILI,SASINO,RENK,MOTORNO,  
   EI_SATICIVKNO	,EI_SATICIUNVAN	,EI_ALICIVKNO,EI_ALICIUNVAN	,EI_ISLEMBASLATANVKNO, 
   EI_ISLEMBASLATANUNVAN	,EI_TASIYICIVKNO	,EI_TASIYICIUNVAN,EI_ARACPLAKA	,EI_DORSEPLAKA	,
   EI_ARACSOFORADISOYADI ,EI_ARACSOFORID,EI_TESLIMATTANIM,EI_TESLIMATADRES,EI_TESLIMATILCE,EI_TESLIMATIL,EI_TESLIMATULKE,EFATURA_IBAN,EI_TASIYICIPOSTAKUTUSU 
   FROM FATURA AS F LEFT JOIN FATURADETAY ON F.FATID=FATURADETAY.FATID LEFT JOIN FATURAEK ON F.FATID=FATURAEK.FATID 
   WHERE ISNULL(EFATURADURUM,0)>0 AND F.FATID=@FATID
GO
/****** Object:  View [dbo].[FU_CIFT]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_CIFT]
AS
SELECT  ROW_NUMBER() OVER(PARTITION BY ENTKAYNAKID ORDER BY ENTKAYNAKID ASC)  as sıra, TARIH,FISID,ENTKAYNAKID,ADD_DATE FROM MUH_FIS WHERE FIRMAID=65 AND ENTKAYNAK='EMLAKSATIS' AND ISNULL(SIL,0)=0 AND ENTKAYNAKID IN (SELECT ENTKAYNAKID FROM MUH_FIS WHERE FIRMAID=65 AND ENTKAYNAK='EMLAKSATIS' AND ISNULL(SIL,0)=0 GROUP BY ENTKAYNAKID HAVING COUNT(ENTKAYNAKID)>1) 
GO
/****** Object:  Table [dbo].[PERBUTCEGIRIS]    Script Date: 17.07.2026 15:19:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERBUTCEGIRIS](
	[PERBUTCEGIRISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPID] [int] NULL,
	[UNVANID] [int] NULL,
	[YIL] [smallint] NULL,
	[AY1_MAAS] [float] NULL,
	[AY1_KUR] [float] NULL,
	[AY1_1] [float] NULL,
	[AY1_2] [float] NULL,
	[AY1_3] [float] NULL,
	[AY1_4] [float] NULL,
	[AY2_MAAS] [float] NULL,
	[AY2_KUR] [float] NULL,
	[AY2_1] [float] NULL,
	[AY2_2] [float] NULL,
	[AY2_3] [float] NULL,
	[AY2_4] [float] NULL,
	[AY3_MAAS] [float] NULL,
	[AY3_KUR] [float] NULL,
	[AY3_1] [float] NULL,
	[AY3_2] [float] NULL,
	[AY3_3] [float] NULL,
	[AY3_4] [float] NULL,
	[AY4_MAAS] [float] NULL,
	[AY4_KUR] [float] NULL,
	[AY4_1] [float] NULL,
	[AY4_2] [float] NULL,
	[AY4_3] [float] NULL,
	[AY4_4] [float] NULL,
	[AY5_MAAS] [float] NULL,
	[AY5_KUR] [float] NULL,
	[AY5_1] [float] NULL,
	[AY5_2] [float] NULL,
	[AY5_3] [float] NULL,
	[AY5_4] [float] NULL,
	[AY6_MAAS] [float] NULL,
	[AY6_KUR] [float] NULL,
	[AY6_1] [float] NULL,
	[AY6_2] [float] NULL,
	[AY6_3] [float] NULL,
	[AY6_4] [float] NULL,
	[AY7_MAAS] [float] NULL,
	[AY7_KUR] [float] NULL,
	[AY7_1] [float] NULL,
	[AY7_2] [float] NULL,
	[AY7_3] [float] NULL,
	[AY7_4] [float] NULL,
	[AY8_MAAS] [float] NULL,
	[AY8_KUR] [float] NULL,
	[AY8_1] [float] NULL,
	[AY8_2] [float] NULL,
	[AY8_3] [float] NULL,
	[AY8_4] [float] NULL,
	[AY9_MAAS] [float] NULL,
	[AY9_KUR] [float] NULL,
	[AY9_1] [float] NULL,
	[AY9_2] [float] NULL,
	[AY9_3] [float] NULL,
	[AY9_4] [float] NULL,
	[AY10_MAAS] [float] NULL,
	[AY10_KUR] [float] NULL,
	[AY10_1] [float] NULL,
	[AY10_2] [float] NULL,
	[AY10_3] [float] NULL,
	[AY10_4] [float] NULL,
	[AY11_MAAS] [float] NULL,
	[AY11_KUR] [float] NULL,
	[AY11_1] [float] NULL,
	[AY11_2] [float] NULL,
	[AY11_3] [float] NULL,
	[AY11_4] [float] NULL,
	[AY12_MAAS] [float] NULL,
	[AY12_KUR] [float] NULL,
	[AY12_1] [float] NULL,
	[AY12_2] [float] NULL,
	[AY12_3] [float] NULL,
	[AY12_4] [float] NULL,
	[DEPKODU] [nvarchar](20) NULL,
	[UNVANKODU] [nvarchar](20) NULL,
	[DOVIZ] [nvarchar](5) NULL,
 CONSTRAINT [PK_PERBUTCEGIRIS] PRIMARY KEY CLUSTERED 
(
	[PERBUTCEGIRISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERUNVAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERUNVAN](
	[PERUNVANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[UNVANKODU] [nvarchar](30) NULL,
	[UNVANADI] [nvarchar](50) NULL,
	[DEPID] [int] NULL,
	[DEPKODU] [nvarchar](20) NULL,
	[UCRETTIPI] [nvarchar](20) NULL,
	[NETUCRET] [float] NULL,
	[NETUCRET1] [float] NULL,
	[NETUCRET2] [float] NULL,
	[NETUCRET3] [float] NULL,
	[NETUCRET4] [float] NULL,
	[NETUCRET5] [float] NULL,
	[BUTCEUCRET1] [float] NULL,
	[BUTCEUCRET2] [float] NULL,
	[BUTCEUCRET3] [float] NULL,
	[BUTCEUCRET4] [float] NULL,
	[BUTCEUCRET5] [float] NULL,
	[BRUTUCRET] [float] NULL,
	[SGKMESLEKKODU] [nvarchar](20) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[ELKUNVANID] [int] NULL,
 CONSTRAINT [PK_PERUNVAN] PRIMARY KEY CLUSTERED 
(
	[PERUNVANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[FU_PERBUTCEANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[FU_PERBUTCEANALIZ]
AS
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,1 AS AY, 
NULLIF(ISNULL(AY1_1,0)+ISNULL(AY1_2,0)+ISNULL(AY1_3,0)+ISNULL(AY1_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY1_1,0)+ISNULL(AY1_2,0)+ISNULL(AY1_3,0)+ISNULL(AY1_4,0),0)/4*AY1_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY1_1,0)+ISNULL(AY1_2,0)+ISNULL(AY1_3,0)+ISNULL(AY1_4,0),0)/4*AY1_MAAS)/NULLIF(AY1_KUR,0) AS DOVIZMAASBUTCE,DOVIZ 
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,2 AS AY, 
NULLIF(ISNULL(AY2_1,0)+ISNULL(AY2_2,0)+ISNULL(AY2_3,0)+ISNULL(AY2_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY2_1,0)+ISNULL(AY2_2,0)+ISNULL(AY2_3,0)+ISNULL(AY2_4,0),0)/4*AY2_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY2_1,0)+ISNULL(AY2_2,0)+ISNULL(AY2_3,0)+ISNULL(AY2_4,0),0)/4*AY2_MAAS)/NULLIF(AY3_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,3 AS AY, 
NULLIF(ISNULL(AY3_1,0)+ISNULL(AY3_2,0)+ISNULL(AY3_3,0)+ISNULL(AY3_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY3_1,0)+ISNULL(AY3_2,0)+ISNULL(AY3_3,0)+ISNULL(AY3_4,0),0)/4*AY3_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY3_1,0)+ISNULL(AY3_2,0)+ISNULL(AY3_3,0)+ISNULL(AY3_4,0),0)/4*AY3_MAAS)/NULLIF(AY3_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,4 AS AY, 
NULLIF(ISNULL(AY4_1,0)+ISNULL(AY4_2,0)+ISNULL(AY4_3,0)+ISNULL(AY4_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY4_1,0)+ISNULL(AY4_2,0)+ISNULL(AY4_3,0)+ISNULL(AY4_4,0),0)/4*AY4_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY4_1,0)+ISNULL(AY4_2,0)+ISNULL(AY4_3,0)+ISNULL(AY4_4,0),0)/4*AY4_MAAS)/NULLIF(AY4_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,5 AS AY, 
NULLIF(ISNULL(AY5_1,0)+ISNULL(AY5_2,0)+ISNULL(AY5_3,0)+ISNULL(AY5_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY5_1,0)+ISNULL(AY5_2,0)+ISNULL(AY5_3,0)+ISNULL(AY5_4,0),0)/5*AY5_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY5_1,0)+ISNULL(AY5_2,0)+ISNULL(AY5_3,0)+ISNULL(AY5_4,0),0)/5*AY5_MAAS)/NULLIF(AY1_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,6 AS AY, 
NULLIF(ISNULL(AY6_1,0)+ISNULL(AY6_2,0)+ISNULL(AY6_3,0)+ISNULL(AY6_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY6_1,0)+ISNULL(AY6_2,0)+ISNULL(AY6_3,0)+ISNULL(AY6_4,0),0)/4*AY6_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY6_1,0)+ISNULL(AY6_2,0)+ISNULL(AY6_3,0)+ISNULL(AY6_4,0),0)/4*AY6_MAAS)/NULLIF(AY6_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,7 AS AY, 
NULLIF(ISNULL(AY7_1,0)+ISNULL(AY7_2,0)+ISNULL(AY7_3,0)+ISNULL(AY7_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY7_1,0)+ISNULL(AY7_2,0)+ISNULL(AY7_3,0)+ISNULL(AY7_4,0),0)/4*AY7_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY7_1,0)+ISNULL(AY7_2,0)+ISNULL(AY7_3,0)+ISNULL(AY7_4,0),0)/4*AY7_MAAS)/NULLIF(AY7_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,8 AS AY, 
NULLIF(ISNULL(AY8_1,0)+ISNULL(AY8_2,0)+ISNULL(AY8_3,0)+ISNULL(AY8_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY8_1,0)+ISNULL(AY8_2,0)+ISNULL(AY8_3,0)+ISNULL(AY8_4,0),0)/4*AY8_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY8_1,0)+ISNULL(AY8_2,0)+ISNULL(AY8_3,0)+ISNULL(AY8_4,0),0)/4*AY8_MAAS)/NULLIF(AY8_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,9 AS AY, 
NULLIF(ISNULL(AY9_1,0)+ISNULL(AY9_2,0)+ISNULL(AY9_3,0)+ISNULL(AY9_4,0),0)/4 AS KISI , 
NULLIF(ISNULL(AY9_1,0)+ISNULL(AY9_2,0)+ISNULL(AY9_3,0)+ISNULL(AY9_4,0),0)/4*AY9_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY9_1,0)+ISNULL(AY9_2,0)+ISNULL(AY9_3,0)+ISNULL(AY9_4,0),0)/4*AY9_MAAS)/NULLIF(AY9_KUR,0) AS DOVIZMAASBUTCE,DOVIZ 
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,10 AS AY, 
NULLIF(ISNULL(AY10_1,0)+ISNULL(AY10_2,0)+ISNULL(AY10_3,0)+ISNULL(AY10_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY10_1,0)+ISNULL(AY10_2,0)+ISNULL(AY10_3,0)+ISNULL(AY10_4,0),0)/4*AY10_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY10_1,0)+ISNULL(AY10_2,0)+ISNULL(AY10_3,0)+ISNULL(AY10_4,0),0)/4*AY10_MAAS)/NULLIF(AY10_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,11 AS AY, 
NULLIF(ISNULL(AY11_1,0)+ISNULL(AY11_2,0)+ISNULL(AY11_3,0)+ISNULL(AY11_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY11_1,0)+ISNULL(AY11_2,0)+ISNULL(AY11_3,0)+ISNULL(AY11_4,0),0)/4*AY11_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY11_1,0)+ISNULL(AY11_2,0)+ISNULL(AY11_3,0)+ISNULL(AY11_4,0),0)/4*AY11_MAAS)/NULLIF(AY11_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
UNION ALL
SELECT PERBUTCEGIRISID,PB.FIRMAID,PB.SUBEID,SB.SUBEADI,PB.DEPID,PB.UNVANID,PB.DEPKODU,PB.UNVANKODU,PD.DEPADI,PU.UNVANADI,YIL,12 AS AY, 
NULLIF(ISNULL(AY12_1,0)+ISNULL(AY12_2,0)+ISNULL(AY12_3,0)+ISNULL(AY12_4,0),0)/4 AS KISI, 
NULLIF(ISNULL(AY12_1,0)+ISNULL(AY12_2,0)+ISNULL(AY12_3,0)+ISNULL(AY12_4,0),0)/4*AY12_MAAS AS TLMAASBUTCE,
(NULLIF(ISNULL(AY12_1,0)+ISNULL(AY12_2,0)+ISNULL(AY12_3,0)+ISNULL(AY12_4,0),0)/4*AY12_MAAS)/NULLIF(AY12_KUR,0) AS DOVIZMAASBUTCE,DOVIZ  
FROM PERBUTCEGIRIS as PB INNER JOIN PERDEPART AS PD ON PB.DEPID=PD.PERDEPARTMANID
INNER JOIN PERUNVAN AS PU ON PB.UNVANID=PU.PERUNVANID
INNER JOIN SUBELER AS SB ON PB.SUBEID=SB.SUBEID
GO
/****** Object:  Table [dbo].[PERBUTCE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERBUTCE](
	[PERBUTCEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[LSUBEID] [int] NULL,
	[DEPID] [int] NULL,
	[UNVANID] [int] NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[CALISAN] [float] NULL,
	[NETMAAS] [float] NULL,
	[BRUTMAAS] [float] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[KUR] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[GVMATRAH] [float] NULL,
	[KUMGVMATRAH] [float] NULL,
	[SSKISVEREN] [float] NULL,
	[ISSIZLIKISVEREN] [float] NULL,
 CONSTRAINT [PK_PERBUTCE] PRIMARY KEY CLUSTERED 
(
	[PERBUTCEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[FU_BUTCEANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_BUTCEANALIZ]
AS
SELECT FU.FIRMAID,FU.SUBEID,FU.DEPID,FU.UNVANID,FU.DEPKODU,FU.UNVANKODU,FU.DEPADI,FU.UNVANADI,FU.YIL,FU.AY,FU.KISI, 
ISNULL(BRUTMAAS,0) AS BRUTMAAS, ISNULL(NETMAAS,0) AS NETMAAS,ISNULL(BRUTMAAS,0)*ISNULL(FU.KISI,0) AS AYLIKBRUTBUTCE,
ISNULL(NETMAAS,0)*ISNULL(FU.KISI,0) AS AYLIKNETBUTCE 
FROM FU_PERBUTCEANALIZ AS FU LEFT JOIN PERBUTCE AS PB ON FU.FIRMAID=PB.FIRMAID AND FU.SUBEID=PB.SUBEID 
AND FU.DEPID=PB.DEPID AND FU.UNVANID=PB.UNVANID AND FU.YIL=PB.YIL AND FU.AY=PB.AY
GO
/****** Object:  Table [dbo].[BANKAKREDIDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKAKREDIDETAY](
	[BANKAKREDIDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[BANKAKREDIID] [int] NULL,
	[TAKSITNO] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TAKSITTUTARI] [float] NULL,
	[ANAPARA] [float] NULL,
	[FAIZ] [float] NULL,
	[KKDF] [float] NULL,
	[BSMV] [float] NULL,
	[KALANANAPARA] [float] NULL,
	[MUHFISID] [int] NULL,
	[ODENENTUTAR] [float] NULL,
 CONSTRAINT [PK_BANKAKREDIDETAY] PRIMARY KEY CLUSTERED 
(
	[BANKAKREDIDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKAKREDI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKAKREDI](
	[BANKAKREDIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KREDITARIHI] [smalldatetime] NULL,
	[BITISTARIHI] [smalldatetime] NULL,
	[KREDITURID] [int] NULL,
	[KREDITUTARI] [float] NULL,
	[FAIZORANI] [float] NULL,
	[KKDFORANI] [float] NULL,
	[BSMVORANI] [float] NULL,
	[TAKSITSAYISI] [float] NULL,
	[TAKSITTUTARI] [float] NULL,
	[GERIODEMETUTARI] [float] NULL,
	[AYLIKMALIYET] [float] NULL,
	[YILLIKMALIYET] [float] NULL,
	[BANKAID] [int] NULL,
	[ANAPARAHESAPID] [int] NULL,
	[FAIZHESAPID] [int] NULL,
	[KKDFHESAPID] [int] NULL,
	[BSMVHESAPID] [int] NULL,
	[MUHFISID] [int] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[FISIVAR] [bit] NULL,
	[GELECEKGIDERID] [int] NULL,
	[GELECEKGIDERID2] [int] NULL,
	[GELECEKANAPARAHESAPID] [int] NULL,
	[GIDERHESAPID] [int] NULL,
	[FAIZHESAPID2] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
 CONSTRAINT [PK_BANKAKREDI] PRIMARY KEY CLUSTERED 
(
	[BANKAKREDIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_BANKAKREDI_ANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_BANKAKREDI_ANALIZ] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT BANKAKREDI.FIRMAID,BANKAKREDIDETAYID, BANKAKREDI.BANKAKREDIID, BANKAKREDI.BANKAID, MUH_HESAP.ACIKLAMA AS BANKAHESAPADI,
BANKAKREDI.DOVIZ, KREDITARIHI, YEAR(KREDITARIHI) AS KREDI_YIL, 
MONTH(KREDITARIHI) AS KREDI_AY, DAY(KREDITARIHI) AS KREDI_GUN,
TAKSITNO, TARIH AS TAKSIT_TARIH, YEAR(TARIH) AS TAKSIT_YIL, MONTH(TARIH) AS TAKSIT_AY, DAY(TARIH) AS TAKSIT_GUN, 
BANKAKREDIDETAY.TAKSITTUTARI, ANAPARA,FAIZ,KKDF,BSMV,KALANANAPARA,ODENENTUTAR,(CASE WHEN BANKAKREDIDETAY.MUHFISID>0 THEN 'Ödendi' else 'Ödeme Bekliyor' END) AS DURUMU,
BANKAKREDIDETAY.MUHFISID  
FROM BANKAKREDI INNER JOIN BANKAKREDIDETAY ON BANKAKREDI.BANKAKREDIID=BANKAKREDIDETAY.BANKAKREDIID
LEFT JOIN MUH_HESAP ON BANKAKREDI.BANKAID=MUH_HESAP.HESAPID
WHERE ISNULL(BANKAKREDI.SIL,0)=0 AND BANKAKREDI.FIRMAID=@FIRMAID
GO
/****** Object:  Table [dbo].[SPAFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAFIS](
	[SPAFISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[SPAMEKANID] [int] NULL,
	[SPAGOREVLIID] [int] NULL,
	[ODANO] [nvarchar](20) NULL,
	[MISAFIRADI] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[KISI] [smallint] NULL,
	[TUTAR] [float] NULL,
	[INDORAN] [float] NULL,
	[NETTUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[NAKIT] [float] NULL,
	[KKARTI] [float] NULL,
	[TICKET] [float] NULL,
	[ACIK] [float] NULL,
	[KAPANDI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[CARIID] [int] NULL,
	[INDTUTAR] [float] NULL,
	[OTELID] [int] NULL,
	[SERVISVAR] [bit] NULL,
	[TEL] [nvarchar](20) NULL,
	[SPAFIS] [int] NULL,
 CONSTRAINT [PK_SPAFIS] PRIMARY KEY CLUSTERED 
(
	[SPAFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AJANDA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AJANDA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[PARENTID] [int] NULL,
	[TYPE] [int] NULL,
	[START] [smalldatetime] NULL,
	[FINISH] [smalldatetime] NULL,
	[OPTIONS] [int] NULL,
	[CAPTION] [nvarchar](255) NULL,
	[RECURRENCEINDEX] [int] NULL,
	[LOCATION] [nvarchar](255) NULL,
	[MESSAGE] [nvarchar](255) NULL,
	[REMINDERDATE] [smalldatetime] NULL,
	[REMINDERMINUTES] [int] NULL,
	[STATE] [int] NULL,
	[LABELCOLOR] [int] NULL,
	[ACTUALSTART] [smalldatetime] NULL,
	[ACTUALFINISH] [smalldatetime] NULL,
	[SYNCIDFFIELD] [nvarchar](255) NULL,
	[RESOURCEID] [int] NULL,
	[RECUREENCEINFO] [ntext] NULL,
	[HKIMLIKID] [int] NULL,
	[SPAFISID] [int] NULL,
	[ISLEMID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NULL,
	[BIRIMFIYAT] [float] NULL,
	[INDORAN] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SPAGOREVLIID] [int] NULL,
	[SPAMEKANID] [int] NULL,
	[KOMORAN] [float] NULL,
	[KOMTUTAR] [float] NULL,
	[KOMDOVIZ] [nvarchar](5) NULL,
	[SATISTARIHI] [smalldatetime] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[SURE] [int] NULL,
 CONSTRAINT [PK_AJANDA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_AJANDA] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAGOREVLI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAGOREVLI](
	[SPAGOREVLIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GOREVLIADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](30) NULL,
	[TGUNU] [int] NULL,
	[AKTIF] [bit] NULL,
	[SIRA] [smallint] NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[PRIMORAN] [float] NULL,
	[PRIMTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[PRIMSURE] [float] NULL,
	[SUREYEGOREPRIM] [bit] NULL,
	[AJANDAGOSTER] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[SPAMEKANID] [int] NULL,
	[OTELID] [int] NULL,
 CONSTRAINT [PK_SPAGOREVLI] PRIMARY KEY CLUSTERED 
(
	[SPAGOREVLIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SPAANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SPAANALIZ] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
	 RETURN
	SELECT SPAFIS.FIRMAID, KAPANDI, ISNULL(convert(varchar, [START], 23),SATISTARIHI) AS SATISTARIHI,GOREVLI.GOREVLIADI,GOREVLI.PRIMORAN AS GOREVLI_PRIMORAN, 
	ISNULL(GOREVLI.PRIMTUTAR,0) AS GOREVLI_PRIMTUTAR,   GOREVLI.DOVIZ AS GOREVLI_DOVIZ, ISNULL(GOREVLI.PRIMTUTAR,0)*ISNULL(AJANDA.KUR,1) AS GOREVLI_PRIMTUTAR_TL, 
	ISNULL(GOREVLI.PRIMSURE,0) AS GOREVLI_PRIMSURE, 
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR ELSE 0.00 END) AS GOREVLI_PRIMSURE_KAZANC,
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS GOREVLI_PRIMSURE_KAZANC_TL,
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR 
	WHEN GOREVLI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*GOREVLI.PRIMORAN WHEN GOREVLI.PRIMTUTAR>0 THEN GOREVLI.PRIMTUTAR  ELSE 0.00 END) AS GOREVLI_TOPLAMPRIM,
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR 
	WHEN GOREVLI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*GOREVLI.PRIMORAN WHEN GOREVLI.PRIMTUTAR>0 THEN GOREVLI.PRIMTUTAR  ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS GOREVLI_TOPLAMPRIM_TL,

	SATISCI.GOREVLIADI AS SATISCIADI, ISNULL(SATISCI.PRIMORAN,0) AS SATISCI_PRIMORAN, 
	ISNULL(SATISCI.PRIMTUTAR,0) AS SATISCI_PRIMTUTAR, SATISCI.DOVIZ AS SATISCI_DOVIZ, ISNULL(SATISCI.PRIMTUTAR,0)*ISNULL(AJANDA.KUR,1) AS SATISCI_PRIMTUTAR_TL, ISNULL(SATISCI.PRIMSURE,0) AS SATISCI_PRIMSURE,
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR ELSE 0.00 END) AS SATISCI_PRIMSURE_KAZANC,
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS SATISCI_PRIMSURE_KAZANC_TL,
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR 
	WHEN SATISCI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*SATISCI.PRIMORAN WHEN SATISCI.PRIMTUTAR>0 THEN SATISCI.PRIMTUTAR  ELSE 0.00 END) AS SATISCI_TOPLAMPRIM,
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR 
	WHEN SATISCI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*SATISCI.PRIMORAN WHEN SATISCI.PRIMTUTAR>0 THEN SATISCI.PRIMTUTAR  ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS SATISCI_TOPLAMPRIM_TL,
	ISNULL(P.ADI,'GENEL') AS PAKETADI, 
	S.ADI AS HIZMETADI, AJANDA.SURE, BIRIMFIYAT,BIRIMFIYAT*ISNULL(AJANDA.KUR,1) AS BIRIMFIYAT_TL, AJANDA.INDORAN, BIRIMFIYAT-(BIRIMFIYAT/100*(100-AJANDA.INDORAN)) AS INDTUTAR,
	(BIRIMFIYAT-(BIRIMFIYAT/100*(100-AJANDA.INDORAN)))*ISNULL(AJANDA.KUR,1) AS INDTUTAR_TL,
	BIRIMFIYAT/100*(100-AJANDA.INDORAN) AS NETTUTAR, (BIRIMFIYAT/100*(100-AJANDA.INDORAN))*ISNULL(AJANDA.KUR,1) AS NETTUTAR_TL,
	AJANDA.KUR,AJANDA.DOVIZ FROM AJANDA WITH (NOLOCK) 
	INNER JOIN SPAFIS ON AJANDA.SPAFISID=SPAFIS.SPAFISID 
	INNER JOIN STOK AS S WITH (NOLOCK) ON AJANDA.STOKID=S.STOKID
	LEFT JOIN STOK AS P WITH (NOLOCK) ON AJANDA.ANASTOKID=P.STOKID
	LEFT JOIN SPAGOREVLI AS GOREVLI WITH (NOLOCK) on AJANDA.SPAGOREVLIID=GOREVLI.SPAGOREVLIID
	LEFT JOIN SPAGOREVLI AS SATISCI WITH (NOLOCK) on SPAFIS.SPAGOREVLIID=SATISCI.SPAGOREVLIID
	WHERE ISNULL(SPAFIS.SIL,0)=0 AND ISNULL(AJANDA.SIL,0)=0 AND SPAFIS.FIRMAID=@FIRMAID AND ISNULL(convert(varchar, [START], 23),AJANDA.SATISTARIHI) BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EFATISL_IRSALIYE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EFATISL_IRSALIYE] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN  
          SELECT FATID,1 AS SATIRNO,SUM(SATIRADET) AS SATIRADET, SATIRBFIYAT,
          SATIRKDVORAN, OTV,SATIRACIKLAMA,OZELKDVKODU,OZELKDVACIKLAMA,SATIRIND,SATIRIND2,
          FBIRIM,SUM(SATIRKDVTUTAR) AS SATIRKDVTUTAR,KDV2,SUM(ARATOPLAM) AS ARATOPLAM,KDVACIKLAMA,KDVSIZLIKKODU,
          SUM(TEV_TUTAR) AS TEV_TUTAR,TEV_ORAN,TEVKANUNKODU,TEVKANUNACIKLAMA
          FROM FNCQ_EFATISL_DETAY_IRSALIYE (@FATID) AS FI
          GROUP BY FATID,SATIRKDVORAN,OTV,SATIRACIKLAMA,OZELKDVKODU,
          OZELKDVACIKLAMA,SATIRBFIYAT,SATIRIND,SATIRIND2,FBIRIM,KDV2,KDVACIKLAMA,KDVSIZLIKKODU,TEV_ORAN,TEVKANUNKODU,TEVKANUNACIKLAMA
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASATESLIM_LISTE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_KASATESLIM_LISTE] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT FIRMAID,TARIH, YETKILI, TUTAR AS KASATUTARI, TLTUTAR AS TESLIMEDILEN, KASAACIKFAZLA  FROM KASATESLIM WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_BIRIMSEC]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_BIRIMSEC] (@STOKID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT STOKID,ISNULL(BIRIM,'Adet') as BIRIM,1 AS KATSAYI, BIRIM AS ANABIRIM FROM STOK WHERE BIRIM<>'' AND STOKID=@STOKID
 UNION ALL
 SELECT STOKID,BIRIM2,ISNULL(KATSAYI2,1) AS KATSAYI,BIRIM AS ANABIRIM FROM STOK WHERE BIRIM2<>'' AND STOKID=@STOKID
 UNION ALL
 SELECT STOKID,BIRIM3,ISNULL(KATSAYI3,1) AS KATSAYI,BIRIM AS ANABIRIM FROM STOK WHERE BIRIM3<>'' AND STOKID=@STOKID
 UNION ALL
 SELECT STOKID,BIRIM4,ISNULL(KATSAYI4,1) AS KATSAYI,BIRIM AS ANABIRIM FROM STOK WHERE BIRIM4<>'' AND STOKID=@STOKID
 UNION ALL
 SELECT STOKID,BIRIM5,ISNULL(KATSAYI5,1) AS KATSAYI,BIRIM AS ANABIRIM FROM STOK WHERE BIRIM5<>'' AND STOKID=@STOKID
GO
/****** Object:  Table [dbo].[STOK_ANLASMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_ANLASMA](
	[ANLASMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[CARIID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[BTARIH] [datetime] NULL,
	[STARIH] [datetime] NULL,
	[AKTIF] [bit] NULL,
	[ANLASMANO] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[TIPID] [int] NULL,
	[ANLASMATURU] [nvarchar](20) NULL,
	[SKODU] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[YETKILI] [nvarchar](20) NULL,
	[EKLEMETARIHI] [datetime] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_STOK_ANLASMA] PRIMARY KEY CLUSTERED 
(
	[ANLASMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_STOK_ANLASMA] UNIQUE NONCLUSTERED 
(
	[ANLASMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_ANLASMA_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_ANLASMA_DETAY](
	[ANLASMAISLID] [int] IDENTITY(1,1) NOT NULL,
	[ANLASMAID] [int] NULL,
	[BARKOD] [nvarchar](20) NULL,
	[STOKID] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[MARKAID] [int] NULL,
	[KOTA] [float] NULL,
	[FIYAT] [float] NULL,
	[KDVDAHILMI] [nvarchar](5) NULL,
	[KDV] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[BEDELSIZ] [bit] NULL,
	[ISKONTOORAN] [float] NULL,
	[ISKONTOORAN2] [float] NULL,
	[ISKONTOORAN3] [float] NULL,
	[MARKANOTE] [nvarchar](50) NULL,
	[MIKTAR] [float] NULL,
	[VASTOGU] [bit] NULL,
	[AHESAPID] [int] NULL,
	[AALTCARIID] [int] NULL,
	[NETMANUEL] [float] NULL,
	[GRUPID] [int] NULL,
 CONSTRAINT [PK_STOK_ANLASMA_DETAY] PRIMARY KEY CLUSTERED 
(
	[ANLASMAISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_STOK_ANLASMA_DETAY] UNIQUE NONCLUSTERED 
(
	[ANLASMAISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ANLASMAOZET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	CREATE FUNCTION [dbo].[FNCQ_ANLASMAOZET] (@FIRMAID INT)  RETURNS  table  AS   
	RETURN
	SELECT AKTIF, ANLASMATURU,BTARIH,STARIH,FIRMAID,SUBEID,MARKAID,STOKID,FIYAT,ISKONTOORAN,ISKONTOORAN2,(((FIYAT/100)*(100-ISNULL(ISKONTOORAN,0)))/100)*(100-ISNULL(ISKONTOORAN2,0)) AS NETFIYAT 
	FROM STOK_ANLASMA_DETAY AS DETAY INNER JOIN STOK_ANLASMA AS ANLASMA ON DETAY.ANLASMAID=ANLASMA.ANLASMAID
	WHERE ISNULL(ANLASMA.SIL,0)=0 AND FIRMAID=@FIRMAID
GO
/****** Object:  Table [dbo].[ADISYON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADISYON](
	[FISCOUNTER] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPKODU] [nvarchar](15) NULL,
	[MASANO] [nvarchar](40) NULL,
	[TARIH] [datetime] NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[FISNO] [int] NULL,
	[ODERNO] [nvarchar](50) NULL,
	[ADISYONNO] [nvarchar](15) NULL,
	[GARSONKODU] [nvarchar](15) NULL,
	[YETKILIKODU] [nvarchar](15) NULL,
	[TUR] [nvarchar](10) NULL,
	[MUSTERIKODU] [nvarchar](30) NULL,
	[MUSTERIADI] [nvarchar](50) NULL,
	[MUSTERITELEFON] [nvarchar](20) NULL,
	[MUSTERIBAKIYE] [float] NULL,
	[INDORAN] [float] NULL,
	[SERVISORAN] [float] NULL,
	[SERVISTUTAR] [float] NULL,
	[TOPLAM] [float] NULL,
	[FUNVANI] [nvarchar](50) NULL,
	[FADRESI1] [nvarchar](250) NULL,
	[FADRESI2] [nvarchar](150) NULL,
	[FVD] [nvarchar](25) NULL,
	[FVDNO] [nvarchar](25) NULL,
	[KDV] [float] NULL,
	[MATRAH] [float] NULL,
	[ONAKIT] [float] NULL,
	[OKK] [float] NULL,
	[OTICKET] [float] NULL,
	[OACIK] [float] NULL,
	[YTOPLAM] [float] NULL,
	[ITOPLAM] [float] NULL,
	[FYAZIYLA] [nvarchar](80) NULL,
	[KISI] [int] NULL,
	[MODANO] [nvarchar](15) NULL,
	[MKNO] [float] NULL,
	[FISLI] [bit] NULL,
	[STOPLAM] [float] NULL,
	[YAZCOUNT] [int] NULL,
	[KKTURU] [nvarchar](50) NULL,
	[TICKETTURU] [nvarchar](50) NULL,
	[DIRTY] [int] NULL,
	[DTURU] [nvarchar](50) NULL,
	[DTOPLAM] [float] NULL,
	[FKISINO] [nvarchar](50) NULL,
	[OTICKET2] [float] NULL,
	[OTICKET3] [float] NULL,
	[OTICKET4] [float] NULL,
	[OTICKET5] [float] NULL,
	[OTICKET6] [float] NULL,
	[VPARA] [float] NULL,
	[MUSTERIID] [int] NULL,
	[MODAADI] [nvarchar](50) NULL,
	[DOVIZTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[KASIYER] [nvarchar](15) NULL,
	[SECINDID] [int] NULL,
	[INDSEBEP] [nvarchar](50) NULL,
	[PBAKIYE] [float] NULL,
	[MID] [int] NULL,
	[KALANKREDI] [float] NULL,
	[ODENMEZTOPLAM] [float] NULL,
	[MASASTATU] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[MARS] [int] NULL,
	[MARSSAATI] [datetime] NULL,
	[ODERSERINO] [nvarchar](50) NULL,
	[CALLSIPARISID] [int] NULL,
	[MUSKARTNO] [nvarchar](20) NULL,
	[SIL] [smallint] NULL,
	[SSAATI] [datetime] NULL,
	[MCOUNTER] [int] NULL,
	[ILKMASANO] [nvarchar](40) NULL,
	[OKCUNQNUMBER] [nvarchar](30) NULL,
	[OKCFISNO] [nvarchar](20) NULL,
	[OKCSTATU] [nvarchar](30) NULL,
	[DEPID] [int] NULL,
	[GARSONID] [int] NULL,
	[KASIYERID] [int] NULL,
 CONSTRAINT [PK_ADISYON] PRIMARY KEY CLUSTERED 
(
	[FISCOUNTER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_ADISYON] UNIQUE NONCLUSTERED 
(
	[FISCOUNTER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADSSATIR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADSSATIR](
	[COUNTER] [int] IDENTITY(1,1) NOT NULL,
	[FISCOUNTER] [int] NULL,
	[ILKFISCOUNTER] [int] NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ADET] [float] NULL,
	[BIRIMFIYAT] [float] NULL,
	[TUTAR] [float] NULL,
	[YAZ] [bit] NULL,
	[GARSONKODU] [nvarchar](5) NULL,
	[BARKOD] [nvarchar](50) NULL,
	[H] [int] NULL,
	[SIP] [bit] NULL,
	[INDORAN] [float] NULL,
	[INDID] [nvarchar](100) NULL,
	[GGRUP] [nvarchar](5) NULL,
	[HHOUR] [bit] NULL,
	[ZAYII] [bit] NULL,
	[IADE] [bit] NULL,
	[BEKLET] [int] NULL,
	[SAAT] [datetime] NULL,
	[GONDERILDI] [bit] NULL,
	[MALIYET] [float] NULL,
	[SERVIS] [int] NULL,
	[SIPADET] [float] NULL,
	[BUCUKLU] [bit] NULL,
	[IKRAM] [bit] NULL,
	[CALLSIPARISID] [int] NULL,
	[EKFIYAT] [float] NULL,
	[DKODU] [nvarchar](10) NULL,
	[DKURU] [float] NULL,
	[MENUSTOKID] [int] NULL,
	[ODENENADET] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[ADSSATIRUUID] [uniqueidentifier] NULL,
	[SIL] [smallint] NULL,
	[GARSONID] [int] NULL,
	[SEC] [bit] NULL,
 CONSTRAINT [PK_ADSSATIR] PRIMARY KEY CLUSTERED 
(
	[COUNTER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIKART]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIKART](
	[CARIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[KODU] [nvarchar](100) NULL,
	[UNVANI] [nvarchar](255) NULL,
	[ADRES1] [nvarchar](100) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](100) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](100) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[TEL1] [nvarchar](50) NULL,
	[TEL2] [nvarchar](50) NULL,
	[FAX] [nvarchar](50) NULL,
	[GSM] [nvarchar](20) NULL,
	[STDIND] [float] NULL,
	[VADEGUN] [int] NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISIND] [float] NULL,
	[TIP] [nvarchar](15) NULL,
	[ADISOYADI] [nvarchar](25) NULL,
	[DYERI] [nvarchar](15) NULL,
	[BABAADI] [nvarchar](15) NULL,
	[DTARIHI] [datetime] NULL,
	[TCKIMLIKNO] [nvarchar](12) NULL,
	[CINSIYETI] [nvarchar](1) NULL,
	[YAZISMA] [nvarchar](2) NULL,
	[UYENOT] [nvarchar](15) NULL,
	[CEPTEL] [nvarchar](14) NULL,
	[GRUBU] [nvarchar](10) NULL,
	[MESLEK] [nvarchar](20) NULL,
	[KARTNO] [nvarchar](25) NULL,
	[STATUSU] [nvarchar](15) NULL,
	[HESAPID] [int] NULL,
	[NOTLAR] [nvarchar](500) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[CGRUBU] [nvarchar](15) NULL,
	[KLIMITI] [float] NULL,
	[GKODU] [nvarchar](10) NULL,
	[KARTTURU] [nvarchar](10) NULL,
	[INDORAN] [float] NULL,
	[ASIMORAN] [float] NULL,
	[KSKODU] [nvarchar](100) NULL,
	[GRUPID] [int] NULL,
	[SUBEID] [int] NULL,
	[SKODU] [nvarchar](50) NULL,
	[HESAPNO] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[IBANKODU] [nvarchar](50) NULL,
	[ADRES3] [nvarchar](100) NULL,
	[BANKAADI] [nvarchar](50) NULL,
	[FIRMA] [nvarchar](15) NULL,
	[ISADRES] [nvarchar](55) NULL,
	[ISTEL] [nvarchar](14) NULL,
	[ISTEL2] [nvarchar](14) NULL,
	[EVADRES] [nvarchar](40) NULL,
	[EVADRES2] [nvarchar](40) NULL,
	[EVPKODU] [nvarchar](50) NULL,
	[EVTEL] [nvarchar](14) NULL,
	[EVFAX] [nvarchar](14) NULL,
	[GOREVI] [nvarchar](15) NULL,
	[ARACTEL] [nvarchar](14) NULL,
	[ESIADI] [nvarchar](25) NULL,
	[COCUK1] [nvarchar](15) NULL,
	[COCUK2] [nvarchar](15) NULL,
	[EVLILIKT] [datetime] NULL,
	[SAC] [nvarchar](10) NULL,
	[BOY] [int] NULL,
	[KILO] [int] NULL,
	[HASTALIKLAR] [nvarchar](100) NULL,
	[KANGRUBU] [nvarchar](7) NULL,
	[UYENO] [nvarchar](15) NULL,
	[UYEBASLAMA] [datetime] NULL,
	[UYEBITIS] [datetime] NULL,
	[UYELIKTIPI] [nvarchar](15) NULL,
	[UYEKISITIPI] [nvarchar](10) NULL,
	[ACILDURUM] [nvarchar](100) NULL,
	[REF1] [nvarchar](50) NULL,
	[REF2] [nvarchar](50) NULL,
	[SATISTEMSIL] [nvarchar](15) NULL,
	[SATISTID] [int] NULL,
	[EKTUTAR1] [float] NULL,
	[EKTUTAR2] [float] NULL,
	[EKTUTAR3] [float] NULL,
	[EKTUTAR4] [float] NULL,
	[EKTARIH1] [datetime] NULL,
	[EKTARIH2] [datetime] NULL,
	[EKTARIH3] [datetime] NULL,
	[SIL] [smallint] NULL,
	[RESIM] [image] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_CARIKART] PRIMARY KEY CLUSTERED 
(
	[CARIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_CARIKART] UNIQUE NONCLUSTERED 
(
	[CARIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPART]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPART](
	[DEPARTMANID] [int] IDENTITY(1,1) NOT NULL,
	[KODU] [nvarchar](5) NOT NULL,
	[ADI] [nvarchar](50) NOT NULL,
	[TUR] [nvarchar](1) NULL,
	[DEPOY] [nvarchar](15) NULL,
	[DEPOI] [nvarchar](15) NULL,
	[KDV] [int] NULL,
	[MUHKODU] [nvarchar](40) NULL,
	[MUHKODUYIYECEK] [nvarchar](40) NULL,
	[MUHKODUICECEK] [nvarchar](40) NULL,
	[GRUBU] [nvarchar](20) NULL,
	[INGDEPADI] [nvarchar](30) NULL,
	[ISLEMTURU] [int] NULL,
	[STDGELIRGRUBU] [nvarchar](5) NULL,
	[GELIRGRUBU] [int] NULL,
	[TUMGELIRGRUBU] [nvarchar](100) NULL,
	[MASMER] [nvarchar](15) NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ETSKASAKODU] [nvarchar](30) NULL,
	[MERKEZKASAKODU] [nvarchar](30) NULL,
	[MERKEZDEPARTKODU] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[MERKEZKODU] [nvarchar](5) NULL,
	[DEPOD] [nvarchar](15) NULL,
	[MASAKOLON] [int] NULL,
	[MASASATIR] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEPTIPI] [smallint] NULL,
 CONSTRAINT [PK_DEPART] PRIMARY KEY CLUSTERED 
(
	[DEPARTMANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_DEPART] UNIQUE NONCLUSTERED 
(
	[DEPARTMANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GARSON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GARSON](
	[GARSONID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[GKODU] [nvarchar](15) NOT NULL,
	[GADI] [nvarchar](25) NULL,
	[GSIFRE] [nvarchar](50) NULL,
	[DEPKODU] [nvarchar](200) NULL,
	[GYETKI] [nvarchar](50) NULL,
	[GGRUPID] [int] NULL,
	[GARSONRESIM] [image] NULL,
	[SIFRESOR] [bit] NULL,
	[GARSONPRIM] [float] NULL,
	[SIL] [smallint] NULL,
	[GHESAPID] [int] NULL,
	[TELEFON] [nvarchar](30) NULL,
	[ADRES] [nvarchar](150) NULL,
	[PAKETCI] [bit] NULL,
	[YAZARKASASIRA] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEPKODUX] [nvarchar](20) NULL,
	[YINDIRIM] [bit] NULL,
	[YADISYONYAZ] [bit] NULL,
	[YHESAPAL] [bit] NULL,
	[YODEMESIL] [bit] NULL,
	[YODEMEDUZELT] [bit] NULL,
	[YGUNSONU] [bit] NULL,
	[YRAPORLAR] [bit] NULL,
	[YMASAAKTAR] [bit] NULL,
	[YYEMEKSEPETI] [bit] NULL,
	[YYEMEKSEPETIRED] [bit] NULL,
	[YYEMEKSEPETIKABUL] [bit] NULL,
	[YCALLERID] [bit] NULL,
	[YISLEMMENU] [bit] NULL,
	[YADISYONGOR] [bit] NULL,
	[YADISYONDUZELT] [bit] NULL,
	[YADISYONYAZDIR] [bit] NULL,
	[YRENKSECENEK] [bit] NULL,
	[YUYECARI] [bit] NULL,
	[YFIYATGUNCELLE] [bit] NULL,
	[YMIKTARGIRIS] [bit] NULL,
	[YSAYIM] [bit] NULL,
	[YGMP3] [bit] NULL,
	[YACIKSATIS] [bit] NULL,
	[YRESIMDEGISTIR] [bit] NULL,
	[YXRAPORU] [bit] NULL,
	[YZRAPORU] [bit] NULL,
	[YGUNGERIALMA] [bit] NULL,
	[YGUNKAPATMA] [bit] NULL,
	[YIADE] [bit] NULL,
 CONSTRAINT [PK_GARSON] PRIMARY KEY CLUSTERED 
(
	[GARSONID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_GARSON] UNIQUE NONCLUSTERED 
(
	[GKODU] ASC,
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ADISYONANALIZ_SILINEN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_ADISYONANALIZ_SILINEN] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,MKNO, A.SUBEID,CK.KODU AS CARIKODU, CK.UNVANI AS CARIUNVANI, 
(CASE WHEN ISNULL(IADE,0)=1 THEN 'IADE' WHEN ISNULL(ZAYII,0)=1 THEN 'ZAYII' WHEN ISNULL(IKRAM,0)=1 THEN 'IKRAM' ELSE 'SATIS' END) AS ISLEMTURU,
(CASE WHEN A.ONAKIT>0 AND A.OKK=0 THEN 'NAKIT' WHEN A.OKK>0 AND A.ONAKIT=0 THEN 'KREDI KARTI' WHEN A.OACIK>0 THEN 'ACIK' ELSE 'NAKIT/KART' END) AS TAHSILATTURU,
A.TUR,ADS.IADE,ADS.IKRAM,ADS.ZAYII,A.FISCOUNTER,D.KODU,D.ADI AS DEPADI,MASANO,ASAATI,KSAATI,SAAT AS SIPARISSAATI, FISNO,
 G2.GKODU AS ADISYONGARSON, G2.GADI AS ADISYONGARSONADI, G2.GHESAPID AS ADSMUHHESAPID, MH2.KODU AS ADSGARSONMUHKODU, MH2.ACIKLAMA AS ADSGARSONMUHADI,  
 G.GKODU AS SATIRGARSON, G.GADI AS SATIRGARSONADI, G.GHESAPID AS SATIRMUHHESAPID, MH.KODU AS SATIRGARSONMUHKODU, MH.ACIKLAMA AS SATIRGARSONMUHADI,
 TUTAR/100*G.GARSONPRIM AS SATIRGARSONPRIMI, TUTAR/100*G2.GARSONPRIM AS ADISYONGARSONPRIMI,
 S.GRUP AS GRUBU, SG.GRUPADI AS GRUPADI, S.KODU AS SKODU,S.ADI AS URUNADI,ADS.ACIKLAMA, A.MODANO AS ODANO, A.MODAADI, A.MUSTERIKODU, A.MUSTERIADI, 
 ADET,S.BIRIM, BIRIMFIYAT, ADS.INDORAN, (BIRIMFIYAT*ADET)-((BIRIMFIYAT*ADET)/100*(100-ADS.INDORAN)) AS INDTUTAR, (BIRIMFIYAT)/100*(100-ISNULL(ADS.INDORAN,0)) AS NETFIYAT, 
 BIRIMFIYAT*ADET AS TOPLAM, (BIRIMFIYAT*ADET)/100*(100-ISNULL(ADS.INDORAN,0)) AS NETTOPLAM
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER 
 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID INNER JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
 INNER JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID
 LEFT JOIN GARSON AS G2 WITH (NOLOCK) ON A.GARSONID=G2.GARSONID
 LEFT JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON G.GHESAPID=MH.HESAPID
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON G2.GHESAPID=MH2.HESAPID
 WHERE A.TARIH BETWEEN @TARIH AND @TARIH2 AND A.FIRMAID=@FIRMAID AND ISNULL(A.SIL,0)=-2
 UNION ALL
 SELECT TARIH,MKNO, A.SUBEID,CK.KODU AS CARIKODU, CK.UNVANI AS CARIUNVANI, 
(CASE WHEN ISNULL(IADE,0)=1 THEN 'IADE' WHEN ISNULL(ZAYII,0)=1 THEN 'ZAYII' WHEN ISNULL(IKRAM,0)=1 THEN 'IKRAM' ELSE 'SATIS' END) AS ISLEMTURU,
(CASE WHEN A.ONAKIT>0 AND A.OKK=0 THEN 'NAKIT' WHEN A.OKK>0 AND A.ONAKIT=0 THEN 'KREDI KARTI' WHEN A.OACIK>0 THEN 'ACIK' ELSE 'NAKIT/KART' END) AS TAHSILATTURU,
A.TUR,ADS.IADE,ADS.IKRAM,ADS.ZAYII,A.FISCOUNTER,D.KODU,D.ADI AS DEPADI,MASANO,ASAATI,KSAATI,SAAT AS SIPARISSAATI, FISNO,
 G2.GKODU AS ADISYONGARSON, G2.GADI AS ADISYONGARSONADI, G2.GHESAPID AS ADSMUHHESAPID, MH2.KODU AS ADSGARSONMUHKODU, MH2.ACIKLAMA AS ADSGARSONMUHADI,  
 G.GKODU AS SATIRGARSON, G.GADI AS SATIRGARSONADI, G.GHESAPID AS SATIRMUHHESAPID, MH.KODU AS SATIRGARSONMUHKODU, MH.ACIKLAMA AS SATIRGARSONMUHADI,
 TUTAR/100*G.GARSONPRIM AS SATIRGARSONPRIMI, TUTAR/100*G2.GARSONPRIM AS ADISYONGARSONPRIMI,
 S.GRUP AS GRUBU, SG.GRUPADI AS GRUPADI, S.KODU AS SKODU,S.ADI AS URUNADI,ADS.ACIKLAMA, A.MODANO AS ODANO, A.MODAADI, A.MUSTERIKODU, A.MUSTERIADI, 
 ADET,S.BIRIM, BIRIMFIYAT, ADS.INDORAN, (BIRIMFIYAT*ADET)-((BIRIMFIYAT*ADET)/100*(100-ADS.INDORAN)) AS INDTUTAR, (BIRIMFIYAT)/100*(100-ISNULL(ADS.INDORAN,0)) AS NETFIYAT, 
 BIRIMFIYAT*ADET AS TOPLAM, (BIRIMFIYAT*ADET)/100*(100-ISNULL(ADS.INDORAN,0)) AS NETTOPLAM
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER 
 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID INNER JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
 INNER JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID
 LEFT JOIN GARSON AS G2 WITH (NOLOCK) ON A.GARSONID=G2.GARSONID
 LEFT JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON G.GHESAPID=MH.HESAPID
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON G2.GHESAPID=MH2.HESAPID
 WHERE A.TARIH BETWEEN @TARIH AND @TARIH2 AND A.FIRMAID=@FIRMAID AND ISNULL(A.SIL,0)=0 AND ISNULL(ADS.SIL,0)=-2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ADISYONANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_ADISYONANALIZ] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,MKNO, A.FIRMAID, A.SUBEID,CK.KODU AS CARIKODU, CK.UNVANI AS CARIUNVANI, 
(CASE WHEN ISNULL(IADE,0)=1 THEN 'IADE' WHEN ISNULL(ZAYII,0)=1 THEN 'ZAYII' WHEN ISNULL(IKRAM,0)=1 THEN 'IKRAM' ELSE 'SATIS' END) AS ISLEMTURU,
(CASE WHEN A.ONAKIT>0 AND A.OKK=0 THEN 'NAKIT' WHEN A.OKK>0 AND A.ONAKIT=0 THEN 'KREDI KARTI' WHEN A.OACIK>0 THEN 'ACIK' ELSE 'NAKIT/KART' END) AS TAHSILATTURU,
A.TUR,ADS.IADE,ADS.IKRAM,ADS.ZAYII,A.FISCOUNTER,D.KODU,D.ADI AS DEPADI,MASANO,ASAATI,KSAATI,SAAT AS SIPARISSAATI, CONVERT(NVARCHAR(2), SAAT, 108) AS SIPARISSAATI2, FISNO,
 G2.GKODU AS ADISYONGARSON, G2.GADI AS ADISYONGARSONADI, KASIYER.GADI AS KASIYER, KASIYER.GKODU AS KASIYERKODU, G2.GHESAPID AS ADSMUHHESAPID, MH2.KODU AS ADSGARSONMUHKODU, MH2.ACIKLAMA AS ADSGARSONMUHADI,  
 G.GKODU AS SATIRGARSON, G.GADI AS SATIRGARSONADI, G.GHESAPID AS SATIRMUHHESAPID, MH.KODU AS SATIRGARSONMUHKODU, MH.ACIKLAMA AS SATIRGARSONMUHADI,
 TUTAR/100*G.GARSONPRIM AS SATIRGARSONPRIMI, TUTAR/100*G2.GARSONPRIM AS ADISYONGARSONPRIMI,
 S.GRUP AS GRUBU, SG.GRUPADI AS GRUPADI, S.KODU AS SKODU,S.ADI AS URUNADI,S.POSTURU, ADS.ACIKLAMA, A.MODANO AS ODANO, A.MODAADI, A.MUSTERIKODU, A.MUSTERIADI, 
 ADET,S.BIRIM, BIRIMFIYAT, A.INDORAN, (BIRIMFIYAT*ADET)-((BIRIMFIYAT*ADET)/100*(100-A.INDORAN)) AS INDTUTAR, 
 BIRIMFIYAT/100*(100-ISNULL(A.INDORAN,0)) AS NETFIYAT, 
 BIRIMFIYAT*ADET AS TOPLAM, (BIRIMFIYAT*ADET)/100*(100-ISNULL(A.INDORAN,0)) AS NETTOPLAM,ADET*S.MALIYET AS MALIYETTOPLAM
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER 
 LEFT JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID INNER JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
 LEFT JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID 
 LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID
 LEFT JOIN GARSON AS G2 WITH (NOLOCK) ON A.GARSONID=G2.GARSONID
 LEFT JOIN GARSON AS KASIYER WITH (NOLOCK) ON A.KASIYERID=KASIYER.GARSONID
 LEFT JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON G.GHESAPID=MH.HESAPID
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON G2.GHESAPID=MH2.HESAPID
 WHERE A.TARIH BETWEEN @TARIH AND @TARIH2 AND A.FIRMAID=@FIRMAID AND ISNULL(A.SIL,0)=0 AND ISNULL(ADS.SIL,0)=0
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ADISYONANALIZ_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_ADISYONANALIZ_DETAY] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @CARIID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,MKNO, A.SUBEID,CK.KODU AS CARIKODU, CK.UNVANI AS CARIUNVANI, 
(CASE WHEN ISNULL(IADE,0)=1 THEN 'IADE' WHEN ISNULL(ZAYII,0)=1 THEN 'ZAYII' WHEN ISNULL(IKRAM,0)=1 THEN 'IKRAM' ELSE 'SATIS' END) AS ISLEMTURU,
(CASE WHEN A.ONAKIT>0 AND A.OKK=0 THEN 'NAKIT' WHEN A.OKK>0 AND A.ONAKIT=0 THEN 'KREDI KARTI' WHEN A.OACIK>0 THEN 'ACIK' ELSE 'NAKIT/KART' END) AS TAHSILATTURU,
A.TUR,ADS.IADE,ADS.IKRAM,ADS.ZAYII,A.FISCOUNTER,D.KODU,D.ADI AS DEPADI,MASANO,ASAATI,KSAATI,SAAT AS SIPARISSAATI, CONVERT(NVARCHAR(2), SAAT, 108) AS SIPARISSAATI2, FISNO,
 G2.GKODU AS ADISYONGARSON, G2.GADI AS ADISYONGARSONADI, G2.GHESAPID AS ADSMUHHESAPID, MH2.KODU AS ADSGARSONMUHKODU, MH2.ACIKLAMA AS ADSGARSONMUHADI,  
 G.GKODU AS SATIRGARSON, G.GADI AS SATIRGARSONADI, G.GHESAPID AS SATIRMUHHESAPID, MH.KODU AS SATIRGARSONMUHKODU, MH.ACIKLAMA AS SATIRGARSONMUHADI,
 TUTAR/100*G.GARSONPRIM AS SATIRGARSONPRIMI, TUTAR/100*G2.GARSONPRIM AS ADISYONGARSONPRIMI,
 S.GRUP AS GRUBU, SG.GRUPADI AS GRUPADI, S.KODU AS SKODU,S.ADI AS URUNADI,ADS.ACIKLAMA, A.MODANO AS ODANO, A.MODAADI, A.MUSTERIKODU, A.MUSTERIADI, 
 ADET,S.BIRIM, BIRIMFIYAT, A.INDORAN, (BIRIMFIYAT*ADET)-((BIRIMFIYAT*ADET)/100*(100-A.INDORAN)) AS INDTUTAR, (BIRIMFIYAT)/100*(100-ISNULL(A.INDORAN,0)) AS NETFIYAT, 
 BIRIMFIYAT*ADET AS TOPLAM, (BIRIMFIYAT*ADET)/100*(100-ISNULL(A.INDORAN,0)) AS NETTOPLAM
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER 
 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID INNER JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
 INNER JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID
 LEFT JOIN GARSON AS G2 WITH (NOLOCK) ON A.GARSONID=G2.GARSONID
 LEFT JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON G.GHESAPID=MH.HESAPID
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON G2.GHESAPID=MH2.HESAPID
 WHERE A.MKNO=@CARIID AND A.TARIH BETWEEN @TARIH AND @TARIH2 AND A.FIRMAID=@FIRMAID AND ISNULL(A.SIL,0)=0 AND ISNULL(ADS.SIL,0)=0
GO
/****** Object:  Table [dbo].[IKEGITIMYER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMYER](
	[IKEGITIMYERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EGITIMYERI] [nvarchar](30) NULL,
	[KAPASITE] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKEGITIMYER] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMYERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKEGITIMKATILIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMKATILIM](
	[IKEGITIMKATILIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[IKEGITIMPLANID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[IKEGITIMTANIMID] [int] NULL,
	[EGITIMIVERENID] [int] NULL,
	[EGITIMCI] [nvarchar](50) NULL,
	[EGITIMYERID] [int] NULL,
	[SURE] [smallint] NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[EGITIMSORUMLUSU] [nvarchar](30) NULL,
	[DOKUMANNO] [nvarchar](20) NULL,
	[YAYINTARIHI] [smalldatetime] NULL,
	[REVIZYONTARIHI] [smalldatetime] NULL,
	[REVIZYONNO] [nvarchar](20) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[KILITLI] [smallint] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKEGITIMKATILIM] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMKATILIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKEGITIMKATILIM_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMKATILIM_DETAY](
	[IKEGITIMKATILIM_DETAYID] [int] IDENTITY(1,1) NOT NULL,
	[IKEGITIMKATILIMID] [int] NULL,
	[SIRANO] [smallint] NULL,
	[PSICILID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[UNVANID] [int] NULL,
	[DURUM] [nvarchar](10) NULL,
	[DURUMID] [smallint] NULL,
 CONSTRAINT [PK_IKEGITIMKATILIM_DETAY] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMKATILIM_DETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKEGITIMPLAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMPLAN](
	[IKEGITIMPLANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DOKUMANNO] [nvarchar](30) NULL,
	[YAYINTARIHI] [smalldatetime] NULL,
	[REVIZYONTARIHI] [smalldatetime] NULL,
	[REVIZYONNO] [nvarchar](20) NULL,
	[YIL] [smallint] NULL,
	[AY] [smallint] NULL,
	[DEPARTMANID] [int] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[DEPARTMANSEF] [nvarchar](50) NULL,
	[DEPARTMANMD] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[KILITLI] [smallint] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EGITIMPLAN] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMPLANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKEGITIMPLAN_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMPLAN_DETAY](
	[IKEGITIMPLANDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[IKEGITIMPLANID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EGITIMSIRANO] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[ICDISEGITIM] [nvarchar](10) NULL,
	[IKEGITIMTANIMID] [int] NULL,
	[EGITIMIVERENID] [int] NULL,
	[EGITIMVEREN] [nvarchar](50) NULL,
	[SURE] [smallint] NULL,
	[KATILIMCISAYISI] [smallint] NULL,
	[EGITIMYERID] [int] NULL,
	[MALIYET] [float] NULL,
	[EGITIMDEGERLENDIRME] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[EGITIMDURUMID] [smallint] NULL,
 CONSTRAINT [PK_IKEGITIMPLAN_DETAY] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMPLANDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKEGITIMTANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKEGITIMTANIM](
	[IKEGITIMTANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ICDISEGITIM] [nvarchar](10) NULL,
	[EGITIMADI] [nvarchar](1200) NULL,
	[SURE] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[SKODU] [nvarchar](20) NULL,
	[SKODUX] [nvarchar](20) NULL,
 CONSTRAINT [PK_IKEGITIMTANIM] PRIMARY KEY CLUSTERED 
(
	[IKEGITIMTANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EGITIMRAPORU]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EGITIMRAPORU] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT '01-PLANLAMA' AS DURUM,IKEGITIMPLAN_DETAY.ICDISEGITIM,IKEGITIMPLAN.FIRMAID, IKEGITIMPLAN.SUBEID,  SUBELER.SUBEKODU,SUBELER.SUBEADI, IKEGITIMPLAN.IKEGITIMPLANID, YIL,AY,TARIH,DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, IKEGITIMPLAN_DETAY.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI, 
EGITIMVEREN,IKEGITIMPLAN_DETAY.SURE,KATILIMCISAYISI,EGITIMYERID,IKEGITIMYER.EGITIMYERI 
FROM IKEGITIMPLAN INNER JOIN IKEGITIMPLAN_DETAY ON IKEGITIMPLAN.IKEGITIMPLANID=IKEGITIMPLAN_DETAY.IKEGITIMPLANID
LEFT JOIN PERDEPART ON IKEGITIMPLAN.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKEGITIMTANIM ON IKEGITIMPLAN_DETAY.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID
LEFT JOIN SUBELER ON IKEGITIMPLAN.SUBEID=SUBELER.SUBEID
LEFT JOIN IKEGITIMYER ON IKEGITIMPLAN_DETAY.EGITIMYERID=IKEGITIMYER.IKEGITIMYERID
WHERE ISNULL(IKEGITIMPLAN.SIL,0)=0 AND IKEGITIMPLAN.FIRMAID=@FIRMAID
 UNION ALL
SELECT '02-GERCEKLESEN' AS DURUM, NULL, IKEGITIMKATILIM.FIRMAID, IKEGITIMKATILIM.SUBEID, SUBELER.SUBEKODU,SUBELER.SUBEADI, IKEGITIMKATILIM.IKEGITIMKATILIMID,YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY,TARIH,IKEGITIMKATILIM.DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, 
IKEGITIMKATILIM.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI,NULL,
IKEGITIMTANIM.SURE,SUM(DURUMID) AS KATILIMCISAYISI,NULL,NULL FROM IKEGITIMKATILIM 
INNER JOIN IKEGITIMKATILIM_DETAY ON IKEGITIMKATILIM.IKEGITIMKATILIMID=IKEGITIMKATILIM_DETAY.IKEGITIMKATILIMID
LEFT JOIN PERDEPART ON IKEGITIMKATILIM.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKEGITIMTANIM ON IKEGITIMKATILIM.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID
LEFT JOIN SUBELER ON IKEGITIMKATILIM.SUBEID=SUBELER.SUBEID
WHERE ISNULL(IKEGITIMKATILIM.SIL,0)=0 AND IKEGITIMKATILIM.FIRMAID=@FIRMAID
GROUP BY IKEGITIMKATILIM.IKEGITIMKATILIMID,YEAR(TARIH), MONTH(TARIH),IKEGITIMKATILIM.DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, IKEGITIMKATILIM.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI,
IKEGITIMTANIM.SURE,TARIH,IKEGITIMKATILIM.SUBEID, SUBELER.SUBEKODU,SUBELER.SUBEADI,IKEGITIMKATILIM.FIRMAID
GO
/****** Object:  Table [dbo].[KASAMUH]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KASAMUH](
	[KASAISLID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[TARIH] [datetime] NULL,
	[SAAT] [datetime] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[DOVIZTUTAR] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[TLTUTAR] [float] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ENO] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[SIRANO] [int] NULL,
	[ISLEMTURU] [nvarchar](25) NULL,
	[DEPT] [nvarchar](5) NULL,
	[KDEPT] [nvarchar](5) NULL,
	[CARIID] [int] NULL,
	[ISLEMTIP] [nvarchar](1) NULL,
	[MHESAPID] [int] NULL,
	[KHESAPID] [int] NULL,
	[PUAN] [float] NULL,
	[KASIYERID] [int] NULL,
 CONSTRAINT [PK_KASAMUH] PRIMARY KEY CLUSTERED 
(
	[KASAISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_KASAMUH] UNIQUE NONCLUSTERED 
(
	[KASAISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_CARIISLEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_CARIISLEM] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10)	)  RETURNS  table  AS   
RETURN
 SELECT TARIH,TIP,DEPT,'KASA' AS DEPADI, KM.CARIID AS CARIID, 
 CK.KODU,CK.UNVANI, ENO, KM.ACIKLAMA, DOVIZKURU,DOVIZKODU,DOVIZTUTAR AS DBORC, TLTUTAR AS BORC, 0.00 AS DALACAK, 0.00 AS ALACAK, KASAISLID AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, MH2.KODU AS KARSIHESAPKODU, MH2.ACIKLAMA AS KARSIHESAPADI,ISNULL(PUAN,0) AS PUAN 
 FROM KASAMUH AS KM WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON KM.CARIID=CK.CARIID
 left JOIN MUH_HESAP AS MH WITH (NOLOCK) ON KM.MHESAPID=MH.HESAPID 
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON KM.KHESAPID=MH2.HESAPID
 WHERE KM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND ISLEMTURU IN('LİMİT YÜKLE','NAKİT ÖDEME','KK ÖDEME','BORÇ DEKONTU','POS SATIS','KYK HARCAMA','BONUS KULLANIM')
 UNION ALL
 SELECT TARIH,TIP,DEPT,'KASA' AS DEPADI, KM.CARIID AS CARIID, 
 CK.KODU,CK.UNVANI, ENO, KM.ACIKLAMA, DOVIZKURU,DOVIZKODU,0.00 AS DBORC,0.00 AS BORC, DOVIZTUTAR AS DALACAK, TLTUTAR AS ALACAK, KASAISLID AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, MH2.KODU AS KARSIHESAPKODU, MH2.ACIKLAMA AS KARSIHESAPADI, ISNULL(PUAN,0) AS PUAN  
 FROM KASAMUH AS KM WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON KM.CARIID=CK.CARIID
 left JOIN MUH_HESAP AS MH WITH (NOLOCK) ON KM.MHESAPID=MH.HESAPID 
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON KM.KHESAPID=MH2.HESAPID
 WHERE KM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2  AND ISLEMTURU NOT IN('LİMİT YÜKLE','NAKİT ÖDEME','KK ÖDEME','BORÇ DEKONTU','POS SATIS','KYK HARCAMA','BONUS KULLANIM')
 UNION ALL
 SELECT TARIH,TIP,D.KODU AS DEPT,D.ADI AS DEPADI, A.MKNO AS CARIID,
 CK.KODU, CK.UNVANI, CAST(FISCOUNTER AS NVARCHAR(10)) AS ENO, A.ACIKLAMA,1.00 AS DOVIZKURU,'TL' AS DOVIZKODU, OACIK AS DBORC, OACIK AS BORC, 0.00 AS DALACAK,0.00 AS ALACAK, FISCOUNTER AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, '600' AS KARSIHESAPKODU, 'Gelir Hesabı' AS KARSIHESAPADI,0.00 AS PUAN
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID INNER JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON CK.HESAPID=MH.HESAPID
 WHERE A.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND A.FIRMAID=@FIRMAID AND ISNULL(A.SIL,0)=0
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_CARIISLEM_MUAVIN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_CARIISLEM_MUAVIN] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @CARIID NVARCHAR(20))  RETURNS  table  AS   
RETURN
 SELECT TARIH,TIP,DEPT,'KASA' AS DEPADI, KM.CARIID AS CARIID, 
 CK.KODU,CK.UNVANI, ENO, KM.ACIKLAMA, DOVIZKURU,DOVIZKODU,DOVIZTUTAR AS BORC, 0.00 AS ALACAK, KASAISLID AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, MH2.KODU AS KARSIHESAPKODU, MH2.ACIKLAMA AS KARSIHESAPADI,ISNULL(PUAN,0) AS PUAN 
 FROM KASAMUH AS KM WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON KM.CARIID=CK.CARIID
 left JOIN MUH_HESAP AS MH WITH (NOLOCK) ON KM.MHESAPID=MH.HESAPID 
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON KM.KHESAPID=MH2.HESAPID
 WHERE KM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND KM.CARIID=@CARIID AND ISLEMTURU IN('LİMİT YÜKLE','NAKİT ÖDEME','KK ÖDEME','BORÇ DEKONTU','POS SATIS','KYK HARCAMA','BONUS KULLANIM')
 UNION ALL
 SELECT TARIH,TIP,DEPT,'KASA' AS DEPADI, KM.CARIID AS CARIID, 
 CK.KODU,CK.UNVANI, ENO, KM.ACIKLAMA, DOVIZKURU,DOVIZKODU,0.00 AS BORC, DOVIZTUTAR AS ALACAK, KASAISLID AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, MH2.KODU AS KARSIHESAPKODU, MH2.ACIKLAMA AS KARSIHESAPADI, ISNULL(PUAN,0) AS PUAN  
 FROM KASAMUH AS KM WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON KM.CARIID=CK.CARIID
 left JOIN MUH_HESAP AS MH WITH (NOLOCK) ON KM.MHESAPID=MH.HESAPID 
 LEFT JOIN MUH_HESAP AS MH2 WITH (NOLOCK) ON KM.KHESAPID=MH2.HESAPID
 WHERE KM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND KM.CARIID=@CARIID AND ISLEMTURU NOT IN('LİMİT YÜKLE','NAKİT ÖDEME','KK ÖDEME','BORÇ DEKONTU','POS SATIS','KYK HARCAMA','BONUS KULLANIM')
 UNION ALL
 SELECT TARIH,TIP,D.KODU AS DEPT,D.ADI AS DEPADI, A.MKNO AS CARIID,
 CK.KODU, CK.UNVANI, CAST(FISCOUNTER AS NVARCHAR(10)) AS ENO, A.ACIKLAMA,1.00 AS DOVIZKURU,'TL' AS DOVIZKODU, OACIK AS BORC, 0.00 AS ALACAK, FISCOUNTER AS ISLEMID,
 MH.KODU AS MUHASEBEKODU, MH.ACIKLAMA AS MUHASEBEADI, '600' AS KARSIHESAPKODU, 'Gelir Hesabı' AS KARSIHESAPADI,0.00 AS PUAN
 FROM ADISYON AS A WITH (NOLOCK) INNER JOIN CARIKART AS CK WITH (NOLOCK) ON A.MKNO=CK.CARIID INNER JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID
 LEFT JOIN MUH_HESAP AS MH WITH (NOLOCK) ON CK.HESAPID=MH.HESAPID
 WHERE A.FIRMAID=@FIRMAID AND A.TARIH BETWEEN @TARIH AND @TARIH2 AND A.MKNO=@CARIID AND ISNULL(A.SIL,0)=0
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ENCOKSATAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_ENCOKSATAN] (@FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TARIH NVARCHAR(10)  )  RETURNS  table  AS   
RETURN
SELECT  TOP 10 ADSSATIR.STOKID,STOK.ADI AS URUNADI, SUM(ADET) AS MIKTAR 
FROM ADISYON WITH (NOLOCK) INNER JOIN ADSSATIR WITH (NOLOCK) ON ADISYON.FISCOUNTER=ADSSATIR.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
WHERE ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND ADISYON.SUBEID=@SUBEID AND ADISYON.TARIH>=@TARIH
GROUP BY ADSSATIR.STOKID,STOK.ADI ORDER BY SUM(ADET) DESC
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_POSSATISANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_POSSATISANALIZ] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,SB.SUBEADI,Y.GADI AS KASIYER,G.GADI AS GARSON,A.TUR,UG.GRUPADI,U.KODU,U.ADI AS URUNADI,D.KODU AS DEPKODU,D.ADI AS DEPOADI,
ADET AS MIKTAR, (ADET*BIRIMFIYAT)/NULLIF(ISNULL(ADET,0),0) AS BRUTFIYAT, ADET*BIRIMFIYAT AS BRUTTOPLAM, 
(ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0/NULLIF(ISNULL(ADET,0),0) AS NETFIYAT, 
(ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0 AS NETTOPLAM  
FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER
INNER JOIN STOK AS U WITH (NOLOCK) ON ADS.STOKID=U.STOKID
INNER JOIN SGRUP AS UG WITH (NOLOCK) ON U.GRUPID=UG.SGRUPID
LEFT JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID 
LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID 
LEFT JOIN GARSON AS Y WITH (NOLOCK) ON A.KASIYERID=Y.GARSONID
LEFT JOIN SUBELER AS SB WITH (NOLOCK) ON A.SUBEID=SB.SUBEID
WHERE ISNULL(A.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2
AND A.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_POSSATISANALIZ_OZET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_POSSATISANALIZ_OZET] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,SB.SUBEADI,Y.GADI AS KASIYER,G.GADI AS GARSON,A.TUR,UG.GRUPADI,U.KODU,U.ADI AS URUNADI,D.KODU AS DEPKODU,D.ADI AS DEPOADI,
SUM(ADET) AS MIKTAR, SUM(ADET*BIRIMFIYAT)/SUM(ADET) AS BRUTFIYAT, SUM(ADET*BIRIMFIYAT) AS BRUTTOPLAM, 
SUM((ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0)/SUM(ADET) AS NETFIYAT, 
SUM((ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0) AS NETTOPLAM  
FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER
INNER JOIN STOK AS U WITH (NOLOCK) ON ADS.STOKID=U.STOKID
INNER JOIN SGRUP AS UG WITH (NOLOCK) ON U.GRUPID=UG.SGRUPID
LEFT JOIN DEPART AS D WITH (NOLOCK) ON A.DEPID=D.DEPARTMANID 
LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONID=G.GARSONID 
LEFT JOIN GARSON AS Y WITH (NOLOCK) ON A.KASIYERID=Y.GARSONID
LEFT JOIN SUBELER AS SB WITH (NOLOCK) ON A.SUBEID=SB.SUBEID
WHERE ISNULL(A.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2
AND A.FIRMAID=@FIRMAID
GROUP BY TARIH,A.TUR,UG.GRUPADI,U.KODU,U.ADI,D.KODU,D.ADI,SB.SUBEADI,Y.GADI,G.GADI
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_ADISYON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_ADISYON] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
 RETURN
 SELECT     ADISYON.TARIH, CONVERT(NVARCHAR(2), ADISYON.ASAATI, 108) AS SAAT, DATEPART(DW, ADISYON.TARIH) AS HAFTANINGUNU, DAY(ADISYON.TARIH)  

                       AS AYINGUNU, MONTH(ADISYON.TARIH) AS AY, ADISYON.ADISYONNO, ADISYON.ASAATI, ADISYON.FISNO, DEPART.KODU AS DEPTKODU,  

                       dbo.DEPART.ADI AS DEPTADI, ADISYON.TUR, G.GKODU AS GARSONKODU, ADISYON.FISCOUNTER, dbo.CARIKART.KODU AS CARIKODU,  

                       CARIKART.UNVANI AS CARIUNVANI, ADISYON.INDORAN AS AINDORAN, ADISYON.MASANO, ADISYON.KSAATI, G2.GKODU AS YETKILIKODU, ADISYON.MUSTERIKODU,  

                       ADISYON.MUSTERIADI, ADISYON.TOPLAM/100*(ADISYON.INDORAN) AS INDTOPLAM, ADISYON.SERVISORAN, G2.GADI AS YETKILIADI, G.GADI AS GARSONADI, ADISYON.INDSEBEP, ADISYON.SECINDID, ADISYON.KASIYER,  

                       ADISYON.MODAADI, ADISYON.MUSTERIID, ADISYON.OTICKET4, ADISYON.OTICKET3, ADISYON.OTICKET2, ADISYON.FKISINO, ADISYON.FISLI, ADISYON.MKNO,  

                       ADISYON.MODANO, ADISYON.KISI, ADISYON.OACIK, ADISYON.OTICKET, ADISYON.OKK, ADISYON.ONAKIT, ADISYON.TOPLAM, ADISYON.SERVISTUTAR 
					 FROM dbo.ADISYON WITH (NOLOCK) 
					 LEFT OUTER JOIN dbo.GARSON AS G WITH (NOLOCK) ON ADISYON.GARSONID = G.GARSONID
					 LEFT JOIN GARSON AS G2 WITH (NOLOCK) ON ADISYON.KASIYERID=G2.GARSONID
					 LEFT OUTER JOIN dbo.DEPART ON ADISYON.DEPID = dbo.DEPART.DEPARTMANID 
					 LEFT JOIN CARIKART  ON CARIKART.CARIID= ADISYON.MUSTERIID 
					WHERE  ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  Table [dbo].[SAYIMFISARSIV]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFISARSIV](
	[SAYIMFISID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [datetime] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL,
	[DEVIR] [float] NULL,
	[DEVIRTUTAR] [float] NULL,
	[ALIM] [float] NULL,
	[ALIMTUTAR] [float] NULL,
 CONSTRAINT [PK_SayimFisArsiv] PRIMARY KEY CLUSTERED 
(
	[SAYIMFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKBAKIYE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKBAKIYE] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  F.TARIH,F.ADD_DATE AS ISLEMTARIH, 'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,STOK.GRUPID,
FI.STOKID,FI.RENKID,FI.BEDENID,STOK.KODU AS STOKKODU,FI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET, FI.BFIYAT, 
ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT,
F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE STOK.TURU='Hammadde' and  FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2 
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,STOK.GRUPID,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT, DFI.BFIYAT AS NFIYAT, DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE STOK.TURU='Hammadde' and  ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE STOK.TURU='Hammadde' and  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR*-1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE STOK.TURU='Hammadde' and ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   
 UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
    WHERE STOK.TURU='Hammadde' and  ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
    WHERE STOK.TURU='Hammadde' and  ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
/*SERVİS FORMU */
 UNION ALL
SELECT DF.TARIH,DF.TARIH AS ISLEMTARIH,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,STOK.GRUPID,
DFI.STOKID,NULL AS RENKID,NULL AS BEDENID,STOK.KODU AS STOKKODU,STOK.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKBAKIYE_SAYIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKBAKIYE_SAYIM] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,SUM(DEVIR) AS DEVIR, NULLIF(SUM(DEVIRTUTAR),0) AS DEVIRTUTAR, SUM(ALIM) AS ALIM, NULLIF(SUM(ALIMTUTAR),0) AS ALIMTUTAR, SUM(KALANMIKTAR) AS KALANMIKTAR, NULLIF(SUM(KALANTUTAR),0) AS KALANTUTAR, BIRIM,NULLIF(SUM(KALANTUTAR),0)/NULLIF(SUM(KALANMIKTAR),0) AS ORTFIYAT 
FROM (SELECT STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,0.00 AS DEVIR, 0.00 AS DEVIRTUTAR, 0.00 AS ALIM,0.00 AS ALIMTUTAR,  SUM(GCADET) AS KALANMIKTAR,NULLIF(SUM(GCADET*NFIYAT),0) AS KALANTUTAR, BIRIM,NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT 
FROM FNCQ_STOKBAKIYE  (@TARIH,@TARIH2,@FIRMAID) WHERE 1=1 GROUP BY STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,BIRIM
UNION ALL
SELECT STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,0.00 AS DEVIR, 0.00 AS DEVIRTUTAR, SUM(GCADET) AS ALIM,NULLIF(SUM(GCADET*NFIYAT),0) AS ALIMTUTAR, 0.00 AS KALANMIKTAR,0.00 AS KALANTUTAR, BIRIM, NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT 
FROM FNCQ_STOKBAKIYE  (@TARIH,@TARIH2,@FIRMAID) WHERE ISLEM IN('ALIS','SATIS') GROUP BY STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,BIRIM
UNION ALL
SELECT SYM.STOKID,STOK.KODU AS STOKKODU,STOK.GRUPID,SYM.SUBEID,SYM.DEPOID, SUM(SYM.FSAYIM) AS DEVIR,NULLIF(SUM(SYM.FSAYIM*SYM.ORTFIYAT),0) AS DEVIRTUTAR, 0.00 AS ALIM,0.00 AS ALIMTUTAR, SUM(SYM.FSAYIM) AS KALANMIKTAR,NULLIF(SUM(SYM.FSAYIM*SYM.ORTFIYAT),0) AS KALANTUTAR,SYM.SAYIMBIRIMI AS BIRIM,
NULLIF(SUM(SYM.FSAYIM*SYM.ORTFIYAT),0)/NULLIF(SUM(SYM.FSAYIM),0) AS ORTFIYAT
FROM SAYIMFISARSIV AS SYM INNER JOIN STOK ON SYM.STOKID=STOK.STOKID WHERE SYM.FIRMAID=@FIRMAID AND STOK.FIRMAID=@FIRMAID AND TARIH=DATEADD(DAY, -1, @TARIH)
/*(SELECT MAX(TARIH) FROM SAYIMFISARSIV WHERE FIRMAID=@FIRMAID) */
GROUP BY SYM.STOKID,STOK.KODU,STOK.GRUPID,SYM.SUBEID,SYM.DEPOID,SYM.SAYIMBIRIMI)
AS TBL GROUP BY STOKID,STOKKODU,GRUPID,SUBEID,DEPOID,BIRIM
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASAMUH]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_KASAMUH] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10)	)  RETURNS  table  AS   
RETURN
SELECT ISLEMTURU,TARIH,KASAMUH.FIRMAID,C.UNVANI, ACIKLAMA, SUM(DOVIZTUTAR) AS TUTAR, DOVIZKODU AS DVZ 
FROM KASAMUH INNER JOIN CARIKART AS C ON KASAMUH.CARIID=C.CARIID WHERE TARIH BETWEEN @TARIH AND @TARIH2 AND KASAMUH.FIRMAID=@FIRMAID
GROUP BY ISLEMTURU,TARIH,KASAMUH.FIRMAID,C.UNVANI, ACIKLAMA,DOVIZKODU




GO
/****** Object:  Table [dbo].[IKVARDIYAAYLIK_PER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYAAYLIK_PER](
	[IKVARDIYAAYLIKID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[YIL] [smallint] NULL,
	[AY] [smallint] NULL,
	[DEPARTMANID] [int] NULL,
	[PSICILID] [int] NULL,
	[V1] [int] NULL,
	[V2] [int] NULL,
	[V3] [int] NULL,
	[V4] [int] NULL,
	[V5] [int] NULL,
	[V6] [int] NULL,
	[V7] [int] NULL,
	[V8] [int] NULL,
	[V9] [int] NULL,
	[V10] [int] NULL,
	[V11] [int] NULL,
	[V12] [int] NULL,
	[V13] [int] NULL,
	[V14] [int] NULL,
	[V15] [int] NULL,
	[V16] [int] NULL,
	[V17] [int] NULL,
	[V18] [int] NULL,
	[V19] [int] NULL,
	[V20] [int] NULL,
	[V21] [int] NULL,
	[V22] [int] NULL,
	[V23] [int] NULL,
	[V24] [int] NULL,
	[V25] [int] NULL,
	[V26] [int] NULL,
	[V27] [int] NULL,
	[V28] [int] NULL,
	[V29] [int] NULL,
	[V30] [int] NULL,
	[V31] [int] NULL,
	[TMESAI] [int] NULL,
	[M1] [int] NULL,
	[M2] [int] NULL,
	[M3] [int] NULL,
	[M4] [int] NULL,
	[M5] [int] NULL,
	[M6] [int] NULL,
	[M7] [int] NULL,
	[M8] [int] NULL,
	[M9] [int] NULL,
	[M10] [int] NULL,
	[K1] [nvarchar](5) NULL,
	[K2] [nvarchar](5) NULL,
	[K3] [nvarchar](5) NULL,
	[K4] [nvarchar](5) NULL,
	[K5] [nvarchar](5) NULL,
	[K6] [nvarchar](5) NULL,
	[K7] [nvarchar](5) NULL,
	[K8] [nvarchar](5) NULL,
	[K9] [nvarchar](5) NULL,
	[K10] [nvarchar](5) NULL,
	[K11] [nvarchar](5) NULL,
	[K12] [nvarchar](5) NULL,
	[K13] [nvarchar](5) NULL,
	[K14] [nvarchar](5) NULL,
	[K15] [nvarchar](5) NULL,
	[K16] [nvarchar](5) NULL,
	[K17] [nvarchar](5) NULL,
	[K18] [nvarchar](5) NULL,
	[K19] [nvarchar](5) NULL,
	[K20] [nvarchar](5) NULL,
	[K21] [nvarchar](5) NULL,
	[K22] [nvarchar](5) NULL,
	[K23] [nvarchar](5) NULL,
	[K24] [nvarchar](5) NULL,
	[K25] [nvarchar](5) NULL,
	[K26] [nvarchar](5) NULL,
	[K27] [nvarchar](5) NULL,
	[K28] [nvarchar](5) NULL,
	[K29] [nvarchar](5) NULL,
	[K30] [nvarchar](5) NULL,
	[K31] [nvarchar](5) NULL,
	[TDIGER] [int] NULL,
 CONSTRAINT [PK_IKVARDIYAAYLIK_PER] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYAAYLIKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_AYLIK_VARDIYA_PER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE FUNCTION [dbo].[FNCQ_AYLIK_VARDIYA_PER] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT SB.SUBEKODU,SB.SUBEADI,PD.DEPADI,PER.GOREVI, PER.ADSOYAD, PER.TCKIMLIKNO, PER.ISEGIRIS, PER.ISTENAYRILIS, V.* 
FROM IKVARDIYAAYLIK_PER AS V WITH (NOLOCK) INNER JOIN SUBELER AS SB WITH (NOLOCK) ON V.SUBEID=SB.SUBEID
INNER JOIN PERDEPART AS PD WITH (NOLOCK) ON V.DEPARTMANID=PD.PERDEPARTMANID
INNER JOIN IKPERSONEL AS PER WITH (NOLOCK) ON V.PSICILID=PER.PSICILID
WHERE ISNULL(PER.SIL,0)=0 AND V.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EGITIMANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_EGITIMANALIZ] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT ISNULL(DURUMID,0) AS DURUMID, (CASE WHEN ISNULL(DURUMID,0)=0 THEN 'Katılmayan' ELSE 'Katılan' end) as DURUM, 1 AS KISI, IKEGITIMKATILIM.FIRMAID, IKEGITIMKATILIM.IKEGITIMKATILIMID, IKEGITIMKATILIM.SUBEID,SUBELER.SUBEKODU, SUBELER.SUBEADI, IKEGITIMKATILIM_DETAY.DEPARTMANID, 
PERDEPART.DEPKODU,PERDEPART.DEPADI,IKPERSONEL.ADSOYAD, IKPERSONEL.ISEGIRIS, IKPERSONEL.ISTENAYRILIS,
YEAR(TARIH) AS EGITIMYILI, MONTH(TARIH) AS EGITIMAY, TARIH,IKEGITIMTANIM.EGITIMADI FROM IKEGITIMKATILIM_DETAY WITH (NOLOCK)
INNER JOIN IKEGITIMKATILIM WITH (NOLOCK) ON  IKEGITIMKATILIM_DETAY.IKEGITIMKATILIMID=IKEGITIMKATILIM.IKEGITIMKATILIMID
INNER JOIN SUBELER WITH (NOLOCK) ON IKEGITIMKATILIM.SUBEID=SUBELER.SUBEID
INNER JOIN PERDEPART WITH (NOLOCK) ON IKEGITIMKATILIM.DEPARTMANID=PERDEPART.PERDEPARTMANID
INNER JOIN IKPERSONEL WITH (NOLOCK) ON IKEGITIMKATILIM_DETAY.PSICILID=IKPERSONEL.PSICILID
INNER JOIN IKEGITIMTANIM  WITH (NOLOCK) ON IKEGITIMKATILIM.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID
WHERE ISNULL(IKEGITIMKATILIM.SIL,0)=0 AND IKEGITIMKATILIM.FIRMAID=@FIRMAID
GO
/****** Object:  Table [dbo].[IKFAZLAMESAI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKFAZLAMESAI](
	[IKFAZLAMESAIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[DOKUMANNO] [nvarchar](20) NULL,
	[YAYINTARIHI] [smalldatetime] NULL,
	[REVIZYONTARIHI] [smalldatetime] NULL,
	[REVIZYONNO] [nvarchar](10) NULL,
	[ILKTARIH] [smalldatetime] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[ONAYTIPI] [smallint] NULL,
	[ONAYMESAJI] [nvarchar](150) NULL,
	[ONAYLAYAN] [nvarchar](30) NULL,
	[KILITLI] [smallint] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKFAZLAMESAI] PRIMARY KEY CLUSTERED 
(
	[IKFAZLAMESAIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKFAZLAMESAI_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKFAZLAMESAI_DETAY](
	[IKFAZLAMESAI_DETAYID] [int] IDENTITY(1,1) NOT NULL,
	[IKFAZLAMESAIID] [int] NULL,
	[PSICILID] [int] NULL,
	[MESAITARIHI] [smalldatetime] NULL,
	[MESAIGEREKCEID] [int] NULL,
	[MESAIGEREKCESI] [nvarchar](150) NULL,
	[MESAISAATI] [float] NULL,
	[IKACIKLAMA] [nvarchar](150) NULL,
	[OPRACIKLAMA] [nvarchar](150) NULL,
	[ONAYLANDI] [bit] NULL,
	[KULLANDI] [bit] NULL,
 CONSTRAINT [PK_IKFAZLAMESAI_DETAY] PRIMARY KEY CLUSTERED 
(
	[IKFAZLAMESAI_DETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKFAZLAMESAITANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKFAZLAMESAITANIM](
	[IKFAZLAMESAITANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[MESAIADI] [nvarchar](100) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKFAZLAMESAITANIM] PRIMARY KEY CLUSTERED 
(
	[IKFAZLAMESAITANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKMESAIKULLANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKMESAIKULLANIM](
	[IKMESAIKULLANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PSICILID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[MAZARET] [nvarchar](50) NULL,
	[SAAT] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKMESAIKULLANIM] PRIMARY KEY CLUSTERED 
(
	[IKMESAIKULLANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MESAIANALIZ2]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_MESAIANALIZ2] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT IKPERSONEL.TCKIMLIKNO, IKFAZLAMESAI.FIRMAID, IKFAZLAMESAI.IKFAZLAMESAIID, IKFAZLAMESAI.SUBEID,SUBELER.SUBEKODU, SUBELER.SUBEADI, IKFAZLAMESAI.DEPARTMANID, 
PERDEPART.DEPKODU,PERDEPART.DEPADI,IKPERSONEL.ADSOYAD, IKPERSONEL.ISEGIRIS, IKPERSONEL.ISTENAYRILIS,
YEAR(MESAITARIHI) AS MESAIYIL, MONTH(MESAITARIHI) AS MESAIAY, MESAITARIHI,MESAIGEREKCEID,ISNULL(IKFAZLAMESAITANIM.MESAIADI,MESAIGEREKCESI) AS MESAIADI, 
MESAIGEREKCESI,MESAISAATI, 0.00 AS KULLANILAN FROM IKFAZLAMESAI_DETAY WITH (NOLOCK)
INNER JOIN IKFAZLAMESAI WITH (NOLOCK) ON  IKFAZLAMESAI_DETAY.IKFAZLAMESAIID=IKFAZLAMESAI.IKFAZLAMESAIID
LEFT JOIN SUBELER WITH (NOLOCK) ON IKFAZLAMESAI.SUBEID=SUBELER.SUBEID
LEFT JOIN PERDEPART WITH (NOLOCK) ON IKFAZLAMESAI.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKPERSONEL WITH (NOLOCK) ON IKFAZLAMESAI_DETAY.PSICILID=IKPERSONEL.PSICILID
LEFT JOIN IKFAZLAMESAITANIM WITH (NOLOCK) ON IKFAZLAMESAI_DETAY.MESAIGEREKCEID=IKFAZLAMESAITANIM.IKFAZLAMESAITANIMID
WHERE ISNULL(IKFAZLAMESAI.SIL,0)=0 AND IKFAZLAMESAI.FIRMAID=@FIRMAID AND ONAYTIPI>=1
UNION ALL
SELECT IKPERSONEL.TCKIMLIKNO, IKMESAIKULLANIM.FIRMAID, -1 AS IKFAZLAMESAIID, IKMESAIKULLANIM.SUBEID,SUBELER.SUBEKODU, SUBELER.SUBEADI, IKMESAIKULLANIM.DEPARTMANID, 
PERDEPART.DEPKODU,PERDEPART.DEPADI,IKPERSONEL.ADSOYAD, IKPERSONEL.ISEGIRIS, IKPERSONEL.ISTENAYRILIS,
YEAR(TARIH) AS MESAIYIL, MONTH(TARIH) AS MESAIAY, TARIH AS MESAITARIHI,-1,MAZARET AS MESAIADI, 
MAZARET AS MESAIGEREKCESI, 0.00, SAAT AS SAAT FROM IKMESAIKULLANIM WITH (NOLOCK)
LEFT JOIN SUBELER WITH (NOLOCK) ON IKMESAIKULLANIM.SUBEID=SUBELER.SUBEID
LEFT JOIN PERDEPART WITH (NOLOCK) ON IKMESAIKULLANIM.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKPERSONEL WITH (NOLOCK) ON IKMESAIKULLANIM.PSICILID=IKPERSONEL.PSICILID
WHERE ISNULL(IKMESAIKULLANIM.SIL,0)=0 AND IKMESAIKULLANIM.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EGITIMRAPORU_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EGITIMRAPORU_DETAY] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT '01-PLANLAMA' AS DURUM,'' AS PERSONEL, IKEGITIMPLAN.FIRMAID, IKEGITIMPLAN.SUBEID,  SUBELER.SUBEKODU,SUBELER.SUBEADI, IKEGITIMPLAN.IKEGITIMPLANID, YIL,AY,TARIH,DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, IKEGITIMPLAN_DETAY.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI, 
EGITIMVEREN,IKEGITIMPLAN_DETAY.SURE,KATILIMCISAYISI,EGITIMYERID 
FROM IKEGITIMPLAN INNER JOIN IKEGITIMPLAN_DETAY ON IKEGITIMPLAN.IKEGITIMPLANID=IKEGITIMPLAN_DETAY.IKEGITIMPLANID
LEFT JOIN PERDEPART ON IKEGITIMPLAN.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKEGITIMTANIM ON IKEGITIMPLAN_DETAY.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID
LEFT JOIN SUBELER ON IKEGITIMPLAN.SUBEID=SUBELER.SUBEID
WHERE ISNULL(IKEGITIMPLAN.SIL,0)=0 AND IKEGITIMPLAN.FIRMAID=@FIRMAID
 UNION ALL
SELECT '02-GERCEKLESEN' AS DURUM, IKPERSONEL.AD+' '+IKPERSONEL.SOYAD AS PERSONELADSOYAD, IKEGITIMKATILIM.FIRMAID, IKEGITIMKATILIM.SUBEID, SUBELER.SUBEKODU,SUBELER.SUBEADI, IKEGITIMKATILIM.IKEGITIMKATILIMID,YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY,TARIH,IKEGITIMKATILIM.DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, 
IKEGITIMKATILIM.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI,(CASE WHEN ISNULL(IKEGITIMKATILIM.EGITIMCI,'')='' THEN IKPERSONEL2.AD+' '+IKPERSONEL2.SOYAD ELSE EGITIMCI END)  AS EGITIMVEREN,
IKEGITIMTANIM.SURE,SUM(DURUMID) AS KATILIMCISAYISI,NULL FROM IKEGITIMKATILIM 
INNER JOIN IKEGITIMKATILIM_DETAY ON IKEGITIMKATILIM.IKEGITIMKATILIMID=IKEGITIMKATILIM_DETAY.IKEGITIMKATILIMID
LEFT JOIN PERDEPART ON IKEGITIMKATILIM.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKEGITIMTANIM ON IKEGITIMKATILIM.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID
LEFT JOIN IKPERSONEL ON IKEGITIMKATILIM_DETAY.PSICILID=IKPERSONEL.PSICILID
LEFT JOIN SUBELER ON IKPERSONEL.SUBEID=SUBELER.SUBEID
LEFT JOIN IKPERSONEL AS IKPERSONEL2 ON IKEGITIMKATILIM.EGITIMIVERENID=IKPERSONEL2.PSICILID
WHERE ISNULL(IKEGITIMKATILIM.SIL,0)=0 AND IKEGITIMKATILIM.FIRMAID=@FIRMAID

GROUP BY IKEGITIMKATILIM.EGITIMCI,IKPERSONEL2.AD,IKPERSONEL2.SOYAD, IKEGITIMKATILIM.IKEGITIMKATILIMID,YEAR(TARIH), MONTH(TARIH),IKEGITIMKATILIM.DEPARTMANID,PERDEPART.DEPKODU,PERDEPART.DEPADI, IKEGITIMKATILIM.IKEGITIMTANIMID, IKEGITIMTANIM.EGITIMADI,
IKEGITIMTANIM.SURE,TARIH,IKEGITIMKATILIM.SUBEID, SUBELER.SUBEKODU,SUBELER.SUBEADI,IKEGITIMKATILIM.FIRMAID,IKPERSONEL.AD,IKPERSONEL.SOYAD
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MESAIANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MESAIANALIZ] (@FIRMAID INT)  RETURNS  table  AS   
RETURN
SELECT IKPERSONEL.TCKIMLIKNO, IKFAZLAMESAI.FIRMAID, IKFAZLAMESAI.IKFAZLAMESAIID, IKFAZLAMESAI.SUBEID,SUBELER.SUBEKODU, SUBELER.SUBEADI, IKFAZLAMESAI.DEPARTMANID, 
PERDEPART.DEPKODU,PERDEPART.DEPADI,IKPERSONEL.ADSOYAD, IKPERSONEL.ISEGIRIS, IKPERSONEL.ISTENAYRILIS,
YEAR(MESAITARIHI) AS MESAIYIL, MONTH(MESAITARIHI) AS MESAIAY, MESAITARIHI,MESAIGEREKCEID,ISNULL(IKFAZLAMESAITANIM.MESAIADI,MESAIGEREKCESI) AS MESAIADI, 
MESAIGEREKCESI,MESAISAATI FROM IKFAZLAMESAI_DETAY WITH (NOLOCK)
INNER JOIN IKFAZLAMESAI WITH (NOLOCK) ON  IKFAZLAMESAI_DETAY.IKFAZLAMESAIID=IKFAZLAMESAI.IKFAZLAMESAIID
LEFT JOIN SUBELER WITH (NOLOCK) ON IKFAZLAMESAI.SUBEID=SUBELER.SUBEID
LEFT JOIN PERDEPART WITH (NOLOCK) ON IKFAZLAMESAI.DEPARTMANID=PERDEPART.PERDEPARTMANID
LEFT JOIN IKPERSONEL WITH (NOLOCK) ON IKFAZLAMESAI_DETAY.PSICILID=IKPERSONEL.PSICILID
LEFT JOIN IKFAZLAMESAITANIM WITH (NOLOCK) ON IKFAZLAMESAI_DETAY.MESAIGEREKCEID=IKFAZLAMESAITANIM.IKFAZLAMESAITANIMID
WHERE ISNULL(IKFAZLAMESAI.SIL,0)=0 AND IKFAZLAMESAI.FIRMAID=@FIRMAID AND ONAYTIPI>=2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETTAHSILAT_YENI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETTAHSILAT_YENI] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TUKETIMFIS.TARIH,DEPO.DEPOADI, GERCEKTARIH AS ZAMAN,YETKILI AS KASIYER,ISNULL(NAKIT,0) AS NAKIT, ISNULL(KKARTI,0) AS KKARTI, ISNULL(ACIK,0) AS ACIK, 
ISNULL(TICKET1,0)+ISNULL(TICKET2,0)+ISNULL(TICKET3,0) AS DIGER, ISNULL(TOPLAM,0) AS TOPLAM FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND  TUKETIMFIS.FIRMAID=@FIRMAID AND TUKETIMFIS.TARIH BETWEEN @TARIH1 AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MESAIKONTROL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_MESAIKONTROL] (@YIL INT, @AY INT, @IKFAZLAMESAIID INT)  RETURNS  table  AS   
RETURN
SELECT  YEAR(MESAITARIHI) AS YIL, MONTH(MESAITARIHI) AS AY, IKFAZLAMESAI_DETAY.PSICILID, IKPERSONEL.AD+' '+IKPERSONEL.SOYAD AS ADSOYAD,  IKPERSONEL.MAXMESAI, SUM(MESAISAATI) AS KULLANILAN, IKPERSONEL.MAXMESAI-SUM(MESAISAATI) AS KALAN  
FROM IKFAZLAMESAI INNER JOIN  IKFAZLAMESAI_DETAY ON IKFAZLAMESAI.IKFAZLAMESAIID=IKFAZLAMESAI_DETAY.IKFAZLAMESAIID LEFT JOIN IKPERSONEL ON IKFAZLAMESAI_DETAY.PSICILID=IKPERSONEL.PSICILID
WHERE ISNULL(IKFAZLAMESAI.SIL,0)=0 AND YEAR(MESAITARIHI)=@YIL AND MONTH(MESAITARIHI)=@AY AND IKFAZLAMESAI_DETAY.PSICILID IN(SELECT PSICILID FROM IKFAZLAMESAI_DETAY WHERE IKFAZLAMESAIID=@IKFAZLAMESAIID)
GROUP BY YEAR(MESAITARIHI), MONTH(MESAITARIHI), 
IKFAZLAMESAI_DETAY.PSICILID, IKPERSONEL.MAXMESAI, IKPERSONEL.AD, IKPERSONEL.SOYAD
GO
/****** Object:  Table [dbo].[SERVISDURUM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERVISDURUM](
	[SERVISDURUMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[SERVISDURUMU] [nvarchar](50) NULL,
	[RENKKODU] [nvarchar](20) NULL,
	[SMSMAILSABLON] [nvarchar](90) NULL,
	[SMSGIDER] [bit] NULL,
	[MAILGIDER] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SERVISDURUM] PRIMARY KEY CLUSTERED 
(
	[SERVISDURUMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SERVISFORM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SERVISFORM] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH, SAAT, FORMNO, 1 AS MIKTAR,
SERVISDURUM.SERVISDURUMU, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN, BITISTARIH,BITISSAAT, UNVANI,MARKA,MODEL,PLAKANO,FIRMAYETKILI,CEPTEL, 
MUSTERITALEBI,YAPILANISLEMLER,TESLIMEDEN,TESLIMALAN,TOPLAM,INDIRIM,NETTOPLAM FROM SERVISFORM LEFT JOIN SERVISDURUM ON SERVISFORM.SERVISDURUMID=SERVISDURUM.SERVISDURUMID
WHERE ISNULL(SERVISFORM.SIL,0)=0 AND SERVISFORM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SONSAYIMTARIH]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SONSAYIMTARIH] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT MAX(TARIH) AS TARIH FROM SAYIMFISARSIV WHERE FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKORTFIYAT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKORTFIYAT] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT DEPOID,STOKID, ISNULL(NULLIF(SUM(TUTAR),0)/NULLIF(SUM(MIKTAR),0),0) AS ORTFIYAT
FROM 
(SELECT DEPOID,STOKID,ISNULL(SUM(GCADET*NFIYAT),0) AS TUTAR, ISNULL(SUM(GCADET),0) AS MIKTAR FROM FNCQ_STOKBAKIYE  (@TARIH,@TARIH2,@FIRMAID) WHERE GCADET>0 GROUP BY DEPOID,STOKID
UNION ALL
SELECT DEPOID,STOKID,ISNULL(SUM(SAYIMTUTAR),0) AS TUTAR, ISNULL(SUM(SAYIM),0) AS MIKTAR FROM SAYIMFISARSIV WHERE FIRMAID=@FIRMAID AND TARIH=(SELECT MAX(TARIH) FROM SAYIMFISARSIV WHERE FIRMAID=@FIRMAID) GROUP BY DEPOID,STOKID) AS TBL
WHERE 1=1 GROUP BY DEPOID,STOKID
GO
/****** Object:  Table [dbo].[YASLANDIRMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YASLANDIRMA](
	[YASLANDIRMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[VADE] [smalldatetime] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPID] [int] NULL,
	[BORC] [float] NULL,
	[ALACAK] [float] NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ODENMEYEN] [float] NULL,
	[DODENMEYEN] [float] NULL,
	[FISID] [int] NULL,
	[ISLEMID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[DAIREID] [int] NULL,
	[SOZLESMEID] [int] NULL,
	[ALTCARIID] [int] NULL,
 CONSTRAINT [PK_YASLANDIRMA] PRIMARY KEY CLUSTERED 
(
	[YASLANDIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_YASLANDIRMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE FUNCTION [dbo].[FNCQ_YASLANDIRMA] (@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),@FIRMAID NVARCHAR(10),@HESAPID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  * FROM YASLANDIRMA WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
	
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLEMLER_OKCRESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKISLEMLER_OKCRESMI] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT F.PROJEID, F.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,FI.FATISLID AS SATIRKNO, F.FIRMAID,F.FATID,FISHESAPID AS HESAPID, F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET) AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET) ) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,
(FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*FI.ADET as  TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON F.PROJEID=MUH_GRUP.GRUPID
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET) AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU,KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
NULL AS KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 

UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR*-1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
KDEPO.KODU CARIKODU, KDEPO.DEPOADI CARIUNVANI, (DFI.FBFIYAT * DFI.FMIKTAR) * - 1  AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   
 UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, (DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))  AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1)*ISNULL(DFI.DKURU,1) AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE OKCFISNO<>'' AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   

UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR  AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, (DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI, ((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR)*ISNULL(DFI.DKURU,1)  AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE OKCFISNO<>'' AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
/*SERVİS FORMU */
 UNION ALL
SELECT DF.PROJEID,DF.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.FIRMAID, DF.ARACKABULID AS FATID,DF.CARIID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  Table [dbo].[EMLAKSATIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATIS](
	[EMLAKSATISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[KENDIMULKUMUZ] [bit] NULL,
	[MULKSATICIHESAPID] [int] NULL,
	[MULKSATICIALTCARIID] [int] NULL,
	[SATICIADSOYAD] [nvarchar](80) NULL,
	[SATICIADRES] [nvarchar](200) NULL,
	[SATICITEL] [nvarchar](25) NULL,
	[SATICIEMAIL] [nvarchar](40) NULL,
	[ALICIHESAPID] [int] NULL,
	[ALICIALTCARIID] [int] NULL,
	[ALICIADSOYAD] [nvarchar](80) NULL,
	[ALICIADRES] [nvarchar](200) NULL,
	[ALICITEL] [nvarchar](25) NULL,
	[ALICIEMAIL] [nvarchar](40) NULL,
	[ALICIDOGUMTARIHI] [smalldatetime] NULL,
	[ALICIVATNO] [nvarchar](20) NULL,
	[ALICIANNEADI] [nvarchar](20) NULL,
	[ALICIBABAADI] [nvarchar](20) NULL,
	[ISLEMGRUPID1] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[DAIREID2] [int] NULL,
	[DAIREID3] [int] NULL,
	[PROJEMAH] [nvarchar](20) NULL,
	[PROJEADANO] [nvarchar](10) NULL,
	[PROJEPARSEL] [nvarchar](10) NULL,
	[BAGIMSIZBOLUM] [nvarchar](20) NULL,
	[KAT] [nvarchar](10) NULL,
	[GMACIKADRES] [nvarchar](200) NULL,
	[SATISTEMSILCIID] [int] NULL,
	[SATISTEMSILCI] [nvarchar](50) NULL,
	[SIRKETYETKILISI] [nvarchar](30) NULL,
	[LISTEFIYATI] [float] NULL,
	[REELFIYAT] [float] NULL,
	[SATISNOTLARI] [nvarchar](150) NULL,
	[EMLAKFIRMAHESAPID] [int] NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TAKSITSAYISI] [int] NULL,
	[ILKTAKSITVADE] [smalldatetime] NULL,
	[ILKTAKSITTUTAR] [float] NULL,
	[TAKSITACIKLAMA] [nvarchar](250) NULL,
	[SONTAKSITVADE] [smalldatetime] NULL,
	[ARACIFIRMASAHIS] [nvarchar](30) NULL,
	[BEYAZESYA] [nvarchar](20) NULL,
	[EKSTRATALEP] [nvarchar](50) NULL,
	[TRANSFER] [nvarchar](50) NULL,
	[BILETFIYATI] [float] NULL,
	[TAPUISKANES] [nvarchar](50) NULL,
	[MUHASEBELESTI] [smallint] NULL,
	[MUHFISID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[IPTALTARIH] [smalldatetime] NULL,
	[IPTALACIKLAMA] [nvarchar](50) NULL,
	[IPTALFISID] [int] NULL,
	[ACENTAHESAPID] [int] NULL,
	[KOMDAHIL] [bit] NULL,
	[DAIRELER] [nvarchar](150) NULL,
	[INDIRIM] [float] NULL,
	[TAPUTARIH] [smalldatetime] NULL,
	[TAPUDAKIAD] [nvarchar](50) NULL,
	[ELEKTRIKABONESI] [nvarchar](30) NULL,
	[SUABONESI] [nvarchar](30) NULL,
	[SIGORTAPOLICESI] [nvarchar](30) NULL,
	[SOZLESMENO] [nvarchar](20) NULL,
	[TAPUTARIHI] [smalldatetime] NULL,
	[REHBERHESAPID] [int] NULL,
	[REHBERALTCARIID] [int] NULL,
	[REHBER2HESAPID] [int] NULL,
	[REHBER2ALTCARIID] [int] NULL,
	[ACENTAALTCARIID] [int] NULL,
	[ALICIULKE] [nvarchar](30) NULL,
	[VEKALET] [nvarchar](5) NULL,
	[VEKALETNOT] [nvarchar](50) NULL,
	[SATISTEMSILCIHESAPID] [int] NULL,
	[SATISTEMSILCIALTCARIID] [int] NULL,
	[SATISKAPATANID] [int] NULL,
	[IMZAYETKILIID] [int] NULL,
	[TAAHTUTARI] [float] NULL,
	[TAAHDOVIZ] [nvarchar](5) NULL,
	[MASRAFKIMIN] [nvarchar](10) NULL,
	[BASKATASVARMI] [nvarchar](5) NULL,
	[SOZLESMETURU] [nvarchar](30) NULL,
 CONSTRAINT [PK_EMLAKSATIS] PRIMARY KEY CLUSTERED 
(
	[EMLAKSATISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EMLAKKOM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EMLAKKOM] (@FIRMAID NVARCHAR(10), @MASMERADI NVARCHAR(30))  RETURNS  table  AS   
RETURN
SELECT ALICIHESAPID, SUM(LISTEFIYATI) AS LISTEFIYATI, SUM(REELFIYAT) AS REELFIYAT, AVG(KOMISYONORAN) AS KOMORAN,
SUM(KOMISYONTUTAR) AS KOMISYONTUTAR, SUM(TAHSILEDILENKOM) AS TAHSILEDILENKOM, SUM(ODENENKOM) AS ODENENKOM, DOVIZ AS SATISDOVIZ FROM 
(SELECT EMLAKSATISID,ALICIHESAPID, DAIREID,DAIRE.GRUPADI AS DAIREADI, PROJEID, PROJE.GRUPADI AS PROJEADI, LISTEFIYATI,REELFIYAT,KOMISYONORAN,KOMISYONTUTAR,EMLAKSATIS.DOVIZ, 
ISNULL((SELECT  SUM(DTUTAR) AS ODENENKOMISYON  FROM  MUH_FIS WITH (NOLOCK) INNER JOIN MUH_HESAPISL WITH (NOLOCK) ON MUH_FIS.FISID=MUH_HESAPISL.FISID WHERE ISNULL(MUH_FIS.SIL,0)=0 AND EMLAKSATIS.DAIREID=MUH_FIS.OZELKODID AND EMLAKSATIS.PROJEID=MUH_FIS.PROJEID
 AND MUH_FIS.FISTURID IN(1,3) AND EMLAKSATIS.FIRMAID=@FIRMAID AND MUH_FIS.MASMERID=(SELECT DBO.FN_MASRAFMERKEZIBUL(@FIRMAID,@MASMERADI))),0) AS TAHSILEDILENKOM,
 ISNULL((SELECT  SUM(DTUTAR) AS ODENENKOMISYON  FROM  MUH_FIS WITH (NOLOCK) INNER JOIN MUH_HESAPISL WITH (NOLOCK) ON MUH_FIS.FISID=MUH_HESAPISL.FISID WHERE ISNULL(MUH_FIS.SIL,0)=0 AND EMLAKSATIS.DAIREID=MUH_FIS.OZELKODID AND EMLAKSATIS.PROJEID=MUH_FIS.PROJEID
 AND MUH_FIS.FISTURID IN(2,4) AND EMLAKSATIS.FIRMAID=@FIRMAID AND MUH_FIS.MASMERID=(SELECT DBO.FN_MASRAFMERKEZIBUL(@FIRMAID,@MASMERADI))),0) AS ODENENKOM
FROM EMLAKSATIS WITH (NOLOCK) LEFT JOIN MUH_GRUP AS PROJE WITH (NOLOCK) ON EMLAKSATIS.PROJEID=PROJE.GRUPID LEFT JOIN MUH_GRUP AS DAIRE WITH (NOLOCK) ON EMLAKSATIS.DAIREID=DAIRE.GRUPID  WHERE EMLAKSATIS.FIRMAID=@FIRMAID AND ISNULL(EMLAKSATIS.SIL,0)=0)
AS TBL GROUP BY ALICIHESAPID,DOVIZ
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASATESLIM_OZET_RESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_KASATESLIM_OZET_RESMI] (@FIRMAID INT, @SUBEID INT, @AKTIFZAMAN DATETIME)  RETURNS  table  AS   
RETURN
		SELECT YETKILI,'SATIS' AS ISLEM,SUM(ISNULL(TOPLAM,0)) AS TOPLAM, 
		SUM(ISNULL(INDTUTAR,0)) AS INDTUTAR, SUM(ISNULL(TOPLAM,0)-ISNULL(INDTUTAR,0))-SUM(ISNULL(ACIK,0)) AS NETTOPLAM, 0.00 as KASAACIKFAZLA 
		FROM TUKETIMFIS WHERE ISLEM='SATIS' AND OKCFISNO<>'' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 AND GERCEKTARIH<=@AKTIFZAMAN
		GROUP BY YETKILI
		UNION ALL
		SELECT NOVAUSER.ADSOYAD AS YETKILI,'TAHSILAT' AS ISLEM,SUM(TOPLAM) AS TOPLAM, 0.00,SUM(TOPLAM) AS TOPLAM,0.00 
		FROM MUH_FIS WITH (NOLOCK) LEFT JOIN NOVAUSER ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID  WHERE FISTURID IN(1,3) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY NOVAUSER.ADSOYAD
		UNION ALL
		SELECT YETKILI,'KASA TESLIM' AS ISLEM,TLTUTAR*-1 AS TOPLAM,0.00 AS INDTUTAR, TLTUTAR*-1 AS NETTOPLAM, KASAACIKFAZLA AS KASAACIKFAZLA 
		FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 AND AKTIFZAMAN<=@AKTIFZAMAN
		UNION ALL
		SELECT NOVAUSER.ADSOYAD AS YETKILI,'ÖDEMELER' AS ISLEM,SUM(TOPLAM)*-1 AS TOPLAM, 0.00,SUM(TOPLAM)*-1 AS TOPLAM,0.00 
		FROM MUH_FIS WITH (NOLOCK) LEFT JOIN NOVAUSER ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE FISTURID IN(2,4) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY NOVAUSER.ADSOYAD
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETTAHSILAT_YENI_OKCRESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETTAHSILAT_YENI_OKCRESMI] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TUKETIMFIS.TARIH,DEPO.DEPOADI, GERCEKTARIH AS ZAMAN,YETKILI AS KASIYER,ISNULL(NAKIT,0) AS NAKIT, ISNULL(KKARTI,0) AS KKARTI, ISNULL(ACIK,0) AS ACIK, 
ISNULL(TICKET1,0)+ISNULL(TICKET2,0)+ISNULL(TICKET3,0) AS DIGER, ISNULL(TOPLAM,0) AS TOPLAM FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID
WHERE OKCFISNO<>'' AND ISNULL(TUKETIMFIS.SIL,0)=0 AND  TUKETIMFIS.FIRMAID=@FIRMAID AND TUKETIMFIS.TARIH BETWEEN @TARIH1 AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETSATIS_OKCRESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETSATIS_OKCRESMI] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,TUKETIMFIS.SUBEID,TUKETIMFIS.CDEPOID AS DEPOID, DEPO.DEPOADI AS DEPOADI,NOVAUSER.ADSOYAD AS KASIYER, MUH_HESAP.ACIKLAMA AS MUHHESAPADI, 
TUKETIMFIS.ACIKLAMA,ISLEM,SUM(TOPLAM) AS SATISTOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, 
SUM(ACIK) AS ACIKHESAP
, SUM(ISNULL(TICKET1,0)) AS TICKET1 
, SUM(ISNULL(TICKET2,0)) AS TICKET2
, SUM(ISNULL(TICKET3,0)) AS TICKET3
, SUM(ISNULL(TICKET4,0)) AS TICKET4
, SUM(ISNULL(TICKET5,0)) AS TICKET5
FROM TUKETIMFIS WITH (NOLOCK) LEFT JOIN 
MUH_HESAP WITH (NOLOCK) ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID AND TUKETIMFIS.FIRMAID=MUH_HESAP.FIRMAID
LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID AND TUKETIMFIS.FIRMAID=NOVAUSER.FIRMAID
LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID AND TUKETIMFIS.FIRMAID=DEPO.FIRMAID
WHERE OKCFISNO<>'' AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2
GROUP BY TARIH,ISLEM,NOVAUSER.ADSOYAD,TUKETIMFIS.SUBEID, TUKETIMFIS.CDEPOID, MUH_HESAP.ACIKLAMA,TUKETIMFIS.ACIKLAMA,DEPO.DEPOADI
GO
/****** Object:  Table [dbo].[SATISTEMSILCI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SATISTEMSILCI](
	[SATISTEMSILCIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[TEL] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[GOREV] [nvarchar](30) NULL,
	[ADRES] [nvarchar](150) NULL,
	[KOMORANI] [float] NULL,
	[TIPI] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SATIST] PRIMARY KEY CLUSTERED 
(
	[SATISTEMSILCIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_SATIST] UNIQUE NONCLUSTERED 
(
	[SATISTEMSILCIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_TEMSILCISATIS_OKCRESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_TEMSILCISATIS_OKCRESMI] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN  
SELECT TUKETIMFIS.FIRMAID,SUBELER.SUBEADI, DEPO.DEPOADI, SATISTEMSILCI.ADSOYAD, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN, TARIH,ISLEM,TUKETIMFIS.YETKILI,NAKIT,
KKARTI AS KKARTI,ACIK,DKURU,DKODU, TOPLAM/100*(KOMORANI) AS KOMISYON, 
TTUTAR AS BRUTSATIS,INDORAN,INDTUTAR,TOPLAM AS NETSATIS  FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID LEFT JOIN SATISTEMSILCI ON TUKETIMFIS.KHESAPID=SATISTEMSILCI.SATISTEMSILCIID
INNER JOIN SUBELER ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
WHERE OKCFISNO<>'' AND KHESAPID>0 AND TUKETIMFIS.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETSATIS_STOK_OKCRESMI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETSATIS_STOK_OKCRESMI] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10),@MALIYET FLOAT)  RETURNS  table  AS   
RETURN
SELECT TARIH,TUKETIMFIS.SUBEID,TUKETIMFIS.CDEPOID AS DEPOID, DEPO.DEPOADI AS DEPOADI,NOVAUSER.ADSOYAD AS KASIYER, MUH_HESAP.ACIKLAMA AS MUHHESAPADI, 
TUKETIMFIS.ACIKLAMA,ISLEM, TUKETIMFISISL.BARKOD, TUKETIMFISISL.ACIKLAMA AS STOKADI, SUM(FMIKTAR) AS MIKTAR, FBIRIM, 
SUM(FMIKTAR*FBFIYAT) AS TUTAR, SUM(FMIKTAR*FBFIYAT/100*(100-TUKETIMFISISL.INDORAN)) AS NETTUTAR,SUM(FMIKTAR*ISNULL(FBMALIYET,FBFIYAT*@MALIYET)) AS MALIYETTUTAR FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK) ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID LEFT JOIN 
MUH_HESAP WITH (NOLOCK) ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID AND TUKETIMFIS.FIRMAID=MUH_HESAP.FIRMAID
LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID AND TUKETIMFIS.FIRMAID=NOVAUSER.FIRMAID
LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID AND TUKETIMFIS.FIRMAID=DEPO.FIRMAID
WHERE OKCFISNO<>'' AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2 AND ISLEM='SATIS' AND ISNULL(SILINDI,0)=0 
GROUP BY TARIH,ISLEM,NOVAUSER.ADSOYAD,TUKETIMFIS.SUBEID, TUKETIMFIS.CDEPOID, MUH_HESAP.ACIKLAMA,TUKETIMFIS.ACIKLAMA,DEPO.DEPOADI,TUKETIMFISISL.BARKOD,TUKETIMFISISL.ACIKLAMA,
TUKETIMFISISL.FBIRIM
GO
/****** Object:  Table [dbo].[STOKMARKA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKMARKA](
	[MARKAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[CARIIID] [int] NULL,
	[MARKAADI] [nvarchar](50) NOT NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_STOKMARKA] PRIMARY KEY CLUSTERED 
(
	[MARKAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_STOKMARKA] UNIQUE NONCLUSTERED 
(
	[MARKAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKANLASMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE FUNCTION [dbo].[FNCQ_STOKANLASMA] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT CARIID,H.ACIKLAMA AS CUNVANI,BTARIH,STARIH,SA.AKTIF,ANLASMANO,SA.ACIKLAMA,
SAD.STOKID,S.BARKOD,S.GRUP,S.KODU, S.ADI,S.BIRIM,SAD.BIRIM AS ANLASMABIRIM,KOTA,S.SFIYAT1 AS STOKFIYAT,
SAD.FIYAT AS ANLASMAFIYAT, SAD.NETMANUEL AS MANUELFIYAT, ISKONTOORAN,ISKONTOORAN2,ISKONTOORAN3,
(SAD.FIYAT/100*(100-ISKONTOORAN))/100*(100-ISKONTOORAN2) AS NETFIYAT, BEDELSIZ,MARKANOTE,
SAD.MARKAID,M.MARKAADI,SAD.DOVIZ
FROM STOK_ANLASMA AS SA WITH (NOLOCK) INNER JOIN STOK_ANLASMA_DETAY AS SAD WITH (NOLOCK) ON SA.ANLASMAID=SAD.ANLASMAID
INNER JOIN STOK AS S WITH (NOLOCK) ON SAD.STOKID=S.STOKID INNER JOIN MUH_HESAP AS H WITH (NOLOCK) 
ON SA.CARIID=H.HESAPID LEFT JOIN STOKMARKA AS M WITH (NOLOCK) ON SAD.MARKAID=M.MARKAID
WHERE ISNULL(SA.SIL,0)=0 AND S.FIRMAID=@FIRMAID AND H.FIRMAID=@FIRMAID
GO
/****** Object:  Table [dbo].[PERELEKTRASICIL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERELEKTRASICIL](
	[PERELEKTRAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[SICILID] [int] NULL,
	[AD] [nvarchar](20) NULL,
	[SOYAD] [nvarchar](20) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[FIRMA] [int] NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[UNVANID] [int] NULL,
	[DEPT] [nvarchar](10) NULL,
	[GOREVI] [nvarchar](50) NULL,
	[UCRET] [float] NULL,
	[UCRETTIPI] [nvarchar](10) NULL,
	[CALISIYOR] [int] NULL,
 CONSTRAINT [PK_PERELEKTRA] PRIMARY KEY CLUSTERED 
(
	[PERELEKTRAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[FU_OZETPERSONEL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_OZETPERSONEL]
AS
SELECT FIRMAID,FIRMA,UNVANID,DEPT,MAX(UCRET) AS UCRET FROM PERELEKTRASICIL
GROUP BY FIRMAID,FIRMA,UNVANID,DEPT
GO
/****** Object:  Table [dbo].[FATURAVERGI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAVERGI](
	[FATURAVERGIID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[VERGIID] [int] NULL,
	[HESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ORAN] [float] NULL,
 CONSTRAINT [PK_FATURAVERGI] PRIMARY KEY CLUSTERED 
(
	[FATURAVERGIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATISLVERGI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_FATISLVERGI] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT KM.KODU, KM.ACIKLAMA, FV.ORAN, F.NTOPLAM/100*FV.ORAN AS VTUTAR, F.NTOPLAM AS MATRAH 
FROM FATURAVERGI AS FV INNER JOIN KDVMUAFTANIM AS KM ON FV.VERGIID=KM.ID 
INNER JOIN FATURA AS F ON FV.FATID=F.FATID
WHERE FV.FATID=@FATID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATISLVERGI_ORJINAL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_FATISLVERGI_ORJINAL] (@FATID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT KM.KODU,KM.ACIKLAMA,FV.ORAN,
ROUND((ROUND(ABS(ADET)*NFIYAT,4)*FV.ORAN)/100,4) VTUTAR,
ROUND(ABS(ADET)*NFIYAT,4) MATRAH FROM FATURAVERGI FV
INNER JOIN FNCQ_FATISL(@FATID) FISL ON 1=1 
INNER JOIN KDVMUAFTANIM KM ON FV.VERGIID=KM.ID
WHERE FV.FATID=@FATID
GO
/****** Object:  Table [dbo].[KDVTANIMTEVKIFAT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KDVTANIMTEVKIFAT](
	[KDVTANIMDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KDVTANIMID] [int] NULL,
	[TEVKIFATORAN] [nvarchar](10) NULL,
	[TEVKALISHESAPID] [int] NULL,
	[TEVKALISIADEHESAPID] [int] NULL,
	[TEVKSATISHESAPID] [int] NULL,
	[TEVKSATISIADEHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[DEL_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[ADD_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[ADD_USERID] [int] NULL,
 CONSTRAINT [PK_KDVTANIMTEVKIFAT] PRIMARY KEY CLUSTERED 
(
	[KDVTANIMDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_KDVTANIMTEVKIFAT] UNIQUE NONCLUSTERED 
(
	[KDVTANIMDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATURAMUH]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_FATURAMUH] (@FATID NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10))  RETURNS  table  AS   
RETURN   
 /*Fatura Odeme Cari  */
  SELECT  'Fatura Ödeme Cari' AS TBL,    -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID, F.FISHESAPID AS HESAPID,NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(ISNULL(F.FISACIKLAMA,F.ACIKLAMA),'')+' Oto Ödeme' AS BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.FATNO+' Nolu Fatura Ödeme' as ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA, NULL AS MIKTAR,NULL AS BIRIM,NULL BIRIMFIYAT,
 NULL AS BELGETURU,NULL AS BELGETARIH  ,F.ODENMEYEN2 AS ODENMEYEN,'ODENMEYEN2' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID,0)<>0 AND ISNULL(F.ODENENTUTAR,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


/*Fatura Odeme Odeyen Hesap */
  SELECT  'Fatura Odeme Odeyen Hesap' AS TBL,    -1*F.FATID AS FISID,MH.ALTCARIID AS ALTCARIID,F.ODEMEHESAPID,F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DALACAK,   /*+F.ACIKLAMA  ÖDEME AÇIKLAMA ÖNCESİ BU VARDI */
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )   AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI, YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN3 AS ODENMEYEN,'ODENMEYEN3' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   FROM        
 FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 LEFT OUTER JOIN MUH_HESAP_ALTCARI MH ON F.ODEMEALTCARIID=MH.ALTCARIID  WHERE   F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID,0)<>0 AND ISNULL(F.ODENENTUTAR,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


/*Fatura Odeme Cari2  */
  SELECT  'Fatura Odeme Cari2' AS TBL,    -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,F.FISHESAPID,NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2  ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2 ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(ISNULL(F.FISACIKLAMA,F.ACIKLAMA),'')+' Oto Ödeme' AS BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.FATNO+' Nolu Fatura Ödeme' as ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN2 AS ODENMEYEN,'ODENMEYEN2' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   FROM        
 FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   WHERE   F.FATID=@FATID AND    ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID2,0)<>0 AND ISNULL(F.ODENENTUTAR2,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


/*Fatura Odeme Odeyen Hesap2 */
  SELECT  'Fatura Odeme Odeyen Hesap2' AS TBL,    -1*F.FATID AS FISID,MH.ALTCARIID AS ALTCARIID,F.ODEMEHESAPID2,F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,   F.ACIKLAMA,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,
 NULL AS BELGETARIH  ,F.ODENMEYEN3 AS ODENMEYEN,'ODENMEYEN3' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   LEFT OUTER JOIN MUH_HESAP_ALTCARI MH ON 
 F.ODEMEALTCARIID2=MH.ALTCARIID  WHERE   F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID2,0)<>0 AND ISNULL(F.ODENENTUTAR2,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


/*Fatura Cari */
  SELECT 'Fatura Cari' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,F.FISHESAPID, NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN F.GTOPLAM  ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN F.GTOPLAM  ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END)  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END)  ELSE 0 END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  
			  ISNULL(F.ACIKLAMA,ISNULL(FATNO,'')+' Nolu Fatura Entegrasyonu') as ACIKLAMA,NULL ISLEMID,NULL KDV,  (ISNULL(F.GTOPLAM,0)+ISNULL(F.VERGITOPLAM,0)-ISNULL(F.KDV,0)) AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH  ,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 WHERE   F.FATID=@FATID AND     ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    
 
  UNION ALL  
 

/*Fatura Vergi  */
  SELECT 'Fatura Vergi' AS TBL,     -1*F.FATID AS FISID,NULL AS ALTCARIID,ISNULL(MFV.HESAPID,-999),NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN MFV.ORAN* (ISNULL(F.TOPLAM,0)- (ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)))/100 ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN MFV.ORAN* (ISNULL(F.TOPLAM,0)- (ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)))/100 ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0 ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0 ELSE 0 END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,F.ACIKLAMA AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,
 NULL AS BELGETARIH  ,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID 
 FROM        FATURAVERGI MFV WITH (NOLOCK)  INNER JOIN FATURA F  ON MFV.FATID=F.FATID   FULL JOIN MUH_HESAPISL HI WITH (NOLOCK)  ON HI.ISLEMID=-1   
 WHERE  F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


/*Fatura Stok Satirlari  */
	  SELECT 'Fatura Stok Satirlari' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC) AS DBORC,SUM(DALACAK) AS DALACAK,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
	 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
	 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
	,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM ( SELECT      -1*F.FATID AS FISID,                
					(CASE  
					 WHEN ISNULL(FI.HESAPID,0)<>0 THEN FI.HESAPID  
					 WHEN ISNULL(CASE WHEN F.TUR=1 THEN SG.MUHALISHESAPID ELSE SG.MUHSATISHESAPID END,0)<>0 THEN  
								(CASE WHEN F.TUR=1 AND F.FISTURID IN(51,61) THEN SG.MUHALISHESAPID WHEN F.TUR=1 AND F.FISTURID IN(54,64) THEN SG.MUHSATISHESAPID 
								 WHEN F.TUR=-1 AND F.FISTURID IN(52,62) THEN SG.MUHSATISHESAPID when F.TUR=-1 AND F.FISTURID IN(53,63) THEN SG.MUHALISHESAPID ELSE SG.MUHSATISHESAPID END)  
				   ELSE -999 END) AS HESAPID,          
				  CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0)) / 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) <0)  THEN ABS( ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) ) ELSE 0 END  AS BORC,   
				  CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0))  / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) <0)  THEN 0 ELSE ABS( ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) ) END AS ALACAK, 
				  CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.DFBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.DFBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) <0)  THEN ABS( ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) ) ELSE 0 END  AS DBORC,   
				  CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.DFBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.DFBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) <0)  THEN 0 ELSE ABS( ((ISNULL(FI.DFBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
											/ 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
										   / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) ) END AS DALACAK, 
				  ISNULL(REPLACE(FI.DOVIZ,'TRL','TL'),'TL') AS DOVIZ,ISNULL(FI.KUR,0) AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID ,
	 ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  ISNULL(FI.MASMERID,F.MASMERID) AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA 
	,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
	 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM, NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH  
	  FROM        FATURA F WITH (NOLOCK) INNER JOIN               
				  FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID INNER JOIN  
										  STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
										  SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID  LEFT OUTER JOIN 
										  QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
										  WHERE   F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0) F 
	 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
	 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
	 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
	 HAVING  ABS(SUM(BORC)-SUM(ALACAK))>0.0005 
  UNION ALL  

/*Satis Fatura KDV  */
 SELECT 'Satis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN  F.FISTURID =55  OR F.FISTURID =52  OR F.FISTURID=62 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.SATISHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKSATISHESAPID,KDVT.TEVKSATISHESAPID),KDVT.SATISHESAPID) END ,-999)   
                                                                    WHEN F.FISTURID =53  OR F.FISTURID=63 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.ALISIADEHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKALISIADEHESAPID,KDVT.TEVKALISIADEHESAPID),KDVT.ALISIADEHESAPID) END ,-999)                 ELSE -999 END) AS HESAPID,0 AS BORC, ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *(1-CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )*(FI.KDV/100)  AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR,  (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NULL AS BELGETURU,NULL AS BELGETARIH    FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID                                       
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK)  ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND FI.TEVORAN=KDVTEV.TEVKIFATORAN   
									  WHERE  F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (55,52,53,62,63) AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
  GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
  HAVING  ABS(SUM(ALACAK))>0.0005 
  UNION ALL 
  SELECT 'Satis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID =55  OR  F.FISTURID =52  OR F.FISTURID=62 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.SATISHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKSATISHESAPID,KDVT.TEVKSATISHESAPID),KDVT.SATISHESAPID) END ,-999)   
                                                                    WHEN F.FISTURID =53  OR F.FISTURID=63 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.ALISIADEHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKALISIADEHESAPID,KDVT.TEVKALISIADEHESAPID),KDVT.ALISIADEHESAPID) END ,-999)                 ELSE -999 END) AS HESAPID,0 AS BORC, ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *(1-CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )*(FI.KDV2/100)  AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR,  (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NULL AS BELGETURU,NULL AS BELGETARIH    FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV2,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID                                       AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID                                       
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK)  ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND FI.TEVORAN=KDVTEV.TEVKIFATORAN   
									  WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(FI.KDV2,0)>0 AND F.FISTURID IN (55,52,53,62,63) AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
  GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
  HAVING  ABS(SUM(ALACAK))>0.0005 

  UNION ALL  


/*Alis Fatura KDV normal */
  SELECT 'Alis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVT.ALISHESAPID,-999)   
                                                                    WHEN F.FISTURID IN (54,64)    THEN ISNULL(KDVT.SATISIADEHESAPID,-999)                 ELSE -999 END) AS HESAPID, ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *(FI.KDV/100) AS BORC,0 AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM, NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
             FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE ISNULL(SG.ALKOLLU,0)=0 AND F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT, BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC))>0.0005 
 UNION ALL 
/*Alis Fatura KDV ALKOLLU */
  SELECT 'Alis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVT.ALISHESAPID,-999)   
                                                                    WHEN F.FISTURID IN (54,64)    THEN ISNULL(KDVT.SATISIADEHESAPID,-999)                 ELSE -999 END) AS HESAPID, ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *(FI.KDV/100) AS BORC,0 AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM, NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
             FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE ISNULL(SG.ALKOLLU,0)=1 AND F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT, BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC))>0.0005 
 UNION ALL 
 SELECT 'Alis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVT.ALISHESAPID,-999)   
                                                                    WHEN F.FISTURID IN (54,64)    THEN ISNULL(KDVT.SATISIADEHESAPID,-999)                 ELSE -999 END) AS HESAPID, ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *(FI.KDV2/100) AS BORC,0 AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
             FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV2,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(FI.KDV2,0)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC))>0.0005 

  UNION ALL  

/*Fatura OIV */
  SELECT 'Fatura OIV' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,(SELECT TOP 1 ALISHESAPID FROM KDVTANIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ACIKLAMA='OIV') AS FISHESAPID, F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OIV END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OIV END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OIV/F.Kur END) END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OIV/F.Kur END) END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA,NULL ISLEMID,NULL KDV,  0.00 AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH  ,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   WHERE  F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL 

/*Fatura OTV */
  SELECT 'Fatura OTV' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,(SELECT TOP 1 ALISHESAPID FROM KDVTANIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ACIKLAMA='OTV') AS FISHESAPID, F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OTV END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OTV END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OTV/F.Kur END) END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OTV/F.Kur END) END AS DALACAK, 
              REPLACE(F.DOVIZ,'TRL','TL') AS DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA,NULL ISLEMID,NULL KDV,  0.00 AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1  
 WHERE   F.FATID=@FATID AND    ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL 

/*Alis Fatura KDV Tevkifat  */
  SELECT 'Alis Fatura KDV Tevkifat' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),REPLACE(DOVIZ,'TRL','TL') AS DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVTEV.TEVKALISHESAPID,ISNULL(KDVT.TEVKALISHESAPID,-999))   
                                                                    WHEN F.FISTURID IN (54,64) THEN ISNULL(KDVTEV.TEVKSATISIADEHESAPID,ISNULL(KDVT.TEVKSATISIADEHESAPID,-999))                 ELSE -999 END) AS HESAPID,0 AS BORC,  ((ISNULL(FI.FBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.FADET,0) END)) *CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  *(FI.KDV/100) AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )   AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.FIRMAID,F.FIRMAID)=F.FIRMAID AND ISNULL(KDVT.ALKOLLU,0)=0 INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID   
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK) ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND KDVTEV.TEVKIFATORAN=FI.TEVORAN  
									  WHERE F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND   ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )   AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(ALACAK))>0.0005
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_YASLANDIRMA_ALTCARI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_YASLANDIRMA_ALTCARI] (@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),@FIRMAID NVARCHAR(10),@HESAPID NVARCHAR(10), @ALTCARIID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  * FROM YASLANDIRMA WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND HESAPID=@HESAPID AND ALTCARIID=@ALTCARIID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
GO
/****** Object:  Table [dbo].[DOVIZISL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DOVIZISL](
	[DOVIZISLID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[TARIH] [datetime] NULL,
	[KODU] [nvarchar](5) NULL,
	[DOVIZALIS] [float] NULL,
	[DOVIZSATIS] [float] NULL,
	[MBDOVIZALIS] [float] NULL,
	[MBDOVIZSATIS] [float] NULL,
	[EFEKTIFALIS] [float] NULL,
	[EFEKTIFSATIS] [float] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_DOVIZISL] PRIMARY KEY CLUSTERED 
(
	[DOVIZISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_DOVIZISL] UNIQUE NONCLUSTERED 
(
	[DOVIZISLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT3]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT3] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	AC.UNVANI AS ALTCARIUNVANI, CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, dbo.FN_AYISMI(MONTH(ISNULL(F.VADE,F.TARIH))) AS VADEAYADI, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, 
	YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, dbo.FN_AYISMI(MONTH(F.TARIH)) AS AYADI,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, F.BORC,F.ALACAK,F.KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(F.DOVIZ,'TL')=''  THEN 'TL' ELSE F.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(F.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(F.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	M.RDOVIZ,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORC,
	F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RALACAK,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1)-F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORCBAKIYE,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	F.ACIKLAMA AS ACIKLAMA,F.BELGEACIKLAMA,F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, M.HESAPTIPID, F.HESAPID, M.KODU AS HESAPKODU,
	M.KODU AS KODU,	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.DOVIZ AS HESAPDOVIZ,
	M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU, HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, FT.FISTURADI, FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.SOZLESMEID, F.MASMERID,  F.PROJEID, OZELKODID,    
	F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,F.ODENMEYEN, (CASE WHEN F.TARIH<=GETDATE() THEN F.ODENMEYEN ELSE 0.00 END) AS ODENMEYENGECMIS,
	F.ODENMEYENALANI,F.TABLOADI,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, 
	MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI,MGHESAP1.GRUPADI AS HESAPGRUBU1, 
	MGHESAP2.GRUPADI AS HESAPGRUBU2,ACENTA.ADSOYAD AS ACENTASI, ISNULL(PERSONEL.ADSOYAD,PERSONEL2.ADSOYAD) AS TEMSILCI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
/*Fis Baslik Tek Satir */
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

/*Fis Baslik Detayli */
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
  LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID
 LEFT OUTER JOIN EMLAKSATIS WITH (NOLOCK)  ON F.ALTCARIID=EMLAKSATIS.ALICIALTCARIID AND ISNULL(EMLAKSATIS.SIL,0)=0
 LEFT OUTER JOIN EMLAKSATIS as ES2 WITH (NOLOCK)  ON F.HESAPID=ES2.ALICIHESAPID AND F.PROJEID=ES2.PROJEID AND F.OZELKODID=ES2.DAIREID AND ISNULL(ES2.SIL,0)=0
 LEFT OUTER JOIN SATISTEMSILCI AS ACENTA WITH (NOLOCK)  ON EMLAKSATIS.ACENTAHESAPID=ACENTA.SATISTEMSILCIID
 LEFT OUTER JOIN SATISTEMSILCI AS PERSONEL WITH (NOLOCK)  ON EMLAKSATIS.SATISTEMSILCIID=PERSONEL.SATISTEMSILCIID
 LEFT OUTER JOIN SATISTEMSILCI AS PERSONEL2 WITH (NOLOCK)  ON ES2.SATISTEMSILCIID=PERSONEL2.SATISTEMSILCIID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 ORDER BY F.TARIH, F.FISID, MK.KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_YASLANDIRMA_DAIRE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_YASLANDIRMA_DAIRE] (@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),@FIRMAID NVARCHAR(10),@HESAPID NVARCHAR(10), @DAIREID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  * FROM YASLANDIRMA WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND HESAPID=@HESAPID AND DAIREID=@DAIREID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT3_VADE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT3_VADE] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	AC.UNVANI AS ALTCARIUNVANI, CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, F.BORC,F.ALACAK,F.KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	M.RDOVIZ,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORC,
	F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RALACAK,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1)-F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORCBAKIYE,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	F.ACIKLAMA AS ACIKLAMA,F.BELGEACIKLAMA,F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, M.HESAPTIPID, F.HESAPID, M.KODU AS HESAPKODU,
	M.KODU AS KODU,	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.DOVIZ AS HESAPDOVIZ,
	M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU, HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, FT.FISTURADI, FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.SOZLESMEID, F.MASMERID,  F.PROJEID, OZELKODID,    
	F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,F.ODENMEYEN,(CASE WHEN ISNULL(F.VADE,F.TARIH)<=GETDATE() THEN F.ODENMEYEN ELSE 0.00 END) AS ODENMEYENGECMIS,
	F.ODENMEYENALANI,F.TABLOADI,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, 
	MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI,MGHESAP1.GRUPADI AS HESAPGRUBU1, 
	MGHESAP2.GRUPADI AS HESAPGRUBU2,ACENTA.ADSOYAD AS ACENTASI, ISNULL(PERSONEL.ADSOYAD,PERSONEL2.ADSOYAD) AS TEMSILCI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
/*Fis Baslik Tek Satir */
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

/*Fis Baslik Detayli */
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
  LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID
 LEFT OUTER JOIN EMLAKSATIS WITH (NOLOCK)  ON F.ALTCARIID=EMLAKSATIS.ALICIALTCARIID AND ISNULL(EMLAKSATIS.SIL,0)=0
 LEFT OUTER JOIN EMLAKSATIS as ES2 WITH (NOLOCK)  ON F.HESAPID=ES2.ALICIHESAPID AND F.PROJEID=ES2.PROJEID AND F.OZELKODID=ES2.DAIREID AND ISNULL(ES2.SIL,0)=0
 LEFT OUTER JOIN SATISTEMSILCI AS ACENTA WITH (NOLOCK)  ON EMLAKSATIS.ACENTAHESAPID=ACENTA.SATISTEMSILCIID
 LEFT OUTER JOIN SATISTEMSILCI AS PERSONEL WITH (NOLOCK)  ON EMLAKSATIS.SATISTEMSILCIID=PERSONEL.SATISTEMSILCIID
 LEFT OUTER JOIN SATISTEMSILCI AS PERSONEL2 WITH (NOLOCK)  ON ES2.SATISTEMSILCIID=PERSONEL2.SATISTEMSILCIID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 ORDER BY F.TARIH, F.FISID, MK.KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_YASLANDIRMA_SOZLESME]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_YASLANDIRMA_SOZLESME] (@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),@FIRMAID NVARCHAR(10),@SOZLESMEID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  * FROM YASLANDIRMA WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND SOZLESMEID=@SOZLESMEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
GO
/****** Object:  Table [dbo].[MUH_FATVERGI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_FATVERGI](
	[VERGIID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[HESAPID] [int] NULL,
	[ORAN] [float] NULL,
	[FISTURID] [int] NULL,
 CONSTRAINT [PK_MUH_FATVERGI] PRIMARY KEY CLUSTERED 
(
	[VERGIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_FATVERGI] UNIQUE NONCLUSTERED 
(
	[VERGIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_FATURAMUH_YEDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_FATURAMUH_YEDEK] (@FATID NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10))  RETURNS  table  AS   
RETURN   
 --Fatura Odeme Cari 
  SELECT  'Fatura Ödeme Cari' AS TBL,    -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID, F.FISHESAPID AS HESAPID,NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(ISNULL(F.FISACIKLAMA,F.ACIKLAMA),'')+' Oto Ödeme' AS BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.FATNO+' Nolu Fatura Ödeme' as ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA, NULL AS MIKTAR,NULL AS BIRIM,NULL BIRIMFIYAT,
 NULL AS BELGETURU,NULL AS BELGETARIH  ,F.ODENMEYEN2 AS ODENMEYEN,'ODENMEYEN2' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID,0)<>0 AND ISNULL(F.ODENENTUTAR,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


--Fatura Odeme Odeyen Hesap
  SELECT  'Fatura Odeme Odeyen Hesap' AS TBL,    -1*F.FATID AS FISID,MH.ALTCARIID AS ALTCARIID,F.ODEMEHESAPID,F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR/F.GTOPLAM ELSE 0 END  ELSE 0 END AS DALACAK,   --+F.ACIKLAMA  ÖDEME AÇIKLAMA ÖNCESİ BU VARDI
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )   AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI, YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN3 AS ODENMEYEN,'ODENMEYEN3' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   FROM        
 FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 LEFT OUTER JOIN MUH_HESAP_ALTCARI MH ON F.ODEMEALTCARIID=MH.ALTCARIID  WHERE   F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID,0)<>0 AND ISNULL(F.ODENENTUTAR,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


--Fatura Odeme Cari2 
  SELECT  'Fatura Odeme Cari2' AS TBL,    -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,F.FISHESAPID,NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2  ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2 ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID         IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID  NOT    IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(ISNULL(F.FISACIKLAMA,F.ACIKLAMA),'')+' Oto Ödeme' AS BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.FATNO+' Nolu Fatura Ödeme' as ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN2 AS ODENMEYEN,'ODENMEYEN2' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   FROM        
 FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   WHERE   F.FATID=@FATID AND    ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID2,0)<>0 AND ISNULL(F.ODENENTUTAR2,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


--Fatura Odeme Odeyen Hesap2
  SELECT  'Fatura Odeme Odeyen Hesap2' AS TBL,    -1*F.FATID AS FISID,MH.ALTCARIID AS ALTCARIID,F.ODEMEHESAPID2,F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2   ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN ODENENTUTAR2   ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN CASE WHEN F.GTOPLAM<>0 THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END) *F.ODENENTUTAR2/F.GTOPLAM ELSE 0 END   ELSE 0 END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,   F.ACIKLAMA,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,
 NULL AS BELGETARIH  ,F.ODENMEYEN3 AS ODENMEYEN,'ODENMEYEN3' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   LEFT OUTER JOIN MUH_HESAP_ALTCARI MH ON 
 F.ODEMEALTCARIID2=MH.ALTCARIID  WHERE   F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(ODEMEHESAPID2,0)<>0 AND ISNULL(F.ODENENTUTAR2,0)<>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


--Fatura Cari
  SELECT 'Fatura Cari' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,F.FISHESAPID, NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN F.GTOPLAM  ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN F.GTOPLAM  ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END)  ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  (CASE WHEN F.KUR=0 THEN 0 ELSE F.GTOPLAM/F.Kur END)  ELSE 0 END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA,NULL ISLEMID,NULL KDV,  (ISNULL(F.GTOPLAM,0)+ISNULL(F.VERGITOPLAM,0)-ISNULL(F.KDV,0)) AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH  ,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   
 WHERE   F.FATID=@FATID AND     ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    
 
  UNION ALL  
 

--Fatura Vergi 
  SELECT 'Fatura Vergi' AS TBL,     -1*F.FATID AS FISID,NULL AS ALTCARIID,ISNULL(MFV.HESAPID,-999),NULL AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN MFV.ORAN* (ISNULL(F.TOPLAM,0)- (ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)))/100 ELSE 0 END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN MFV.ORAN* (ISNULL(F.TOPLAM,0)- (ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)))/100 ELSE 0 END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0 ELSE 0 END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0 ELSE 0 END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,F.ACIKLAMA AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,
 NULL AS BELGETARIH  ,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID 
 FROM        MUH_FATVERGI MFV WITH (NOLOCK)  INNER JOIN FATURA F  ON MFV.FATID=F.FATID   FULL JOIN MUH_HESAPISL HI WITH (NOLOCK)  ON HI.ISLEMID=-1   
 WHERE  F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL  


--Fatura Stok Satirlari 
  SELECT 'Fatura Stok Satirlari' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC) AS DBORC,SUM(DALACAK) AS DALACAK,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM ( SELECT      -1*F.FATID AS FISID,                
				(CASE  
                 WHEN ISNULL(FI.HESAPID,0)<>0 THEN FI.HESAPID  
                 WHEN ISNULL(CASE WHEN F.TUR=1 THEN SG.MUHALISHESAPID ELSE SG.MUHSATISHESAPID END,0)<>0 THEN  
                            (CASE WHEN F.TUR=1 AND F.FISTURID IN(51,61) THEN SG.MUHALISHESAPID WHEN F.TUR=1 AND F.FISTURID IN(54,64) THEN SG.MUHSATISHESAPID 
							 WHEN F.TUR=-1 AND F.FISTURID IN(52,62) THEN SG.MUHSATISHESAPID when F.TUR=-1 AND F.FISTURID IN(53,63) THEN SG.MUHALISHESAPID ELSE SG.MUHSATISHESAPID END)  
               ELSE -999 END) AS HESAPID,          
              CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0)) / 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) <0)  THEN ABS( ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) ) ELSE 0 END  AS BORC,   
              CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0))  / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) <0)  THEN 0 ELSE ABS( ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) ) END AS ALACAK, 
              CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) <0)  THEN ABS( ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) ) ELSE 0 END  AS DBORC,   
              CASE WHEN (F.TUR=1 AND  ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) >0) OR  (F.TUR<>1 AND  ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) <0)  THEN 0 ELSE ABS( ((ISNULL(FI.DBFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) ) END AS DALACAK, 
              ISNULL(FI.DOVIZ,'TL') AS DOVIZ,ISNULL(FI.KUR,0) AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID ,
 ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  ISNULL(FI.MASMERID,F.MASMERID) AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA 
,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM, NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH  
  FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID INNER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID  LEFT OUTER JOIN 
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE   F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC)-SUM(ALACAK))>0.0005 
  UNION ALL  

--Satis Fatura KDV 
 SELECT 'Satis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN  F.FISTURID =55  OR F.FISTURID =52  OR F.FISTURID=62 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.SATISHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKSATISHESAPID,KDVT.TEVKSATISHESAPID),KDVT.SATISHESAPID) END ,-999)   
                                                                    WHEN F.FISTURID =53  OR F.FISTURID=63 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.ALISIADEHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKALISIADEHESAPID,KDVT.TEVKALISIADEHESAPID),KDVT.ALISIADEHESAPID) END ,-999)                 ELSE -999 END) AS HESAPID,0 AS BORC, ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) *(1-CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )*(FI.KDV/100)  AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR,  (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NULL AS BELGETURU,NULL AS BELGETARIH    FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.SUBEID,F.SUBEID)=F.SUBEID                                       AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID                                       
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK)  ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND FI.TEVORAN=KDVTEV.TEVKIFATORAN   
									  WHERE  F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (55,52,53,62,63) AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
  GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
  HAVING  ABS(SUM(ALACAK))>0.0005 
  UNION ALL 
  SELECT 'Satis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID  FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID =55  OR  F.FISTURID =52  OR F.FISTURID=62 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.SATISHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKSATISHESAPID,KDVT.TEVKSATISHESAPID),KDVT.SATISHESAPID) END ,-999)   
                                                                    WHEN F.FISTURID =53  OR F.FISTURID=63 THEN       ISNULL(CASE WHEN TEVORAN IS NULL THEN KDVT.ALISIADEHESAPID ELSE ISNULL(ISNULL(KDVTEV.TEVKALISIADEHESAPID,KDVT.TEVKALISIADEHESAPID),KDVT.ALISIADEHESAPID) END ,-999)                 ELSE -999 END) AS HESAPID,0 AS BORC, ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) *(1-CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  )*(FI.KDV2/100)  AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR,  (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NULL AS BELGETURU,NULL AS BELGETARIH    FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV2,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.SUBEID,F.SUBEID)=F.SUBEID                                       AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID                                       
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK)  ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND FI.TEVORAN=KDVTEV.TEVKIFATORAN   
									  WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(FI.KDV2,0)>0 AND F.FISTURID IN (55,52,53,62,63) AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
  GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
  HAVING  ABS(SUM(ALACAK))>0.0005 

  UNION ALL  


--Alis Fatura KDV 
  SELECT 'Alis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVT.ALISHESAPID,-999)   
                                                                    WHEN F.FISTURID IN (54,64)    THEN ISNULL(KDVT.SATISIADEHESAPID,-999)                 ELSE -999 END) AS HESAPID, ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) *(FI.KDV/100) AS BORC,0 AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM, NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
             FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.SUBEID,F.SUBEID)=F.SUBEID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT, BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC))>0.0005 
 UNION ALL 
 SELECT 'Alis Fatura KDV' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVT.ALISHESAPID,-999)   
                                                                    WHEN F.FISTURID IN (54,64)    THEN ISNULL(KDVT.SATISIADEHESAPID,-999)                 ELSE -999 END) AS HESAPID, ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) *(FI.KDV2/100) AS BORC,0 AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
             FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      STOK STOK WITH (NOLOCK) ON FI.STOKID=STOK.STOKID LEFT OUTER JOIN 
                                      SGRUP SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID LEFT OUTER JOIN 
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV2,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.SUBEID,F.SUBEID)=F.SUBEID  AND ISNULL(KDVT.ALKOLLU,0)=(CASE WHEN ISNULL(SG.ALKOLLU,0)=0 THEN 0 ELSE 1 END)   INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID  
									  WHERE  F.FATID=@FATID AND   ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND ISNULL(FI.KDV2,0)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )  AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(BORC))>0.0005 

  UNION ALL  

--Fatura OIV
  SELECT 'Fatura OIV' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,(SELECT TOP 1 ALISHESAPID FROM KDVTANIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ACIKLAMA='OIV') AS FISHESAPID, F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OIV END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OIV END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OIV/F.Kur END) END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OIV/F.Kur END) END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA,NULL ISLEMID,NULL KDV,  0.00 AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH  ,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1   WHERE  F.FATID=@FATID AND       ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL 

--Fatura OTV
  SELECT 'Fatura OTV' AS TBL,     -1*F.FATID AS FISID,ISNULL(HI.ALTCARIID,F.ALTCARIID) AS ALTCARIID,(SELECT TOP 1 ALISHESAPID FROM KDVTANIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ACIKLAMA='OTV') AS FISHESAPID, F.FISHESAPID AS KARSIHESAPID,               CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OTV END AS BORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN 0  ELSE F.OTV END AS ALACAK, 
              CASE WHEN  F.FISTURID  NOT IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OTV/F.Kur END) END AS DBORC,   
              CASE WHEN  F.FISTURID      IN (51,54,61,64,65,66,67 )  THEN  0  ELSE (CASE WHEN F.KUR=0 THEN 0 ELSE F.OTV/F.Kur END) END AS DALACAK, 
              F.DOVIZ,F.KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )  AS BELGENO,ISNULL(F.FISACIKLAMA,F.ACIKLAMA) AS BELGEACIKLAMA,NULL ODEMEYONTEMI,NULL YEVSATIRSIRANO, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , F.OZELKOD1, F.OZELKOD2,  F.OZELKOD3,  F.ISLEMGRUPID1,  F.ISLEMGRUPID2,  F.ISLEMGRUPID3,  F.MASMERID,      F.PROJEID,       ISNULL(F.VADE,F.TARIH) AS VADE,  F.ACIKLAMA,NULL ISLEMID,NULL KDV,  0.00 AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL,NULL,NULL,NULL AS BELGETURU,NULL AS BELGETARIH,
 F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'FATURA' AS TABLOADI,F.FATID AS TABLOKAYITID   
 FROM        FATURA F WITH (NOLOCK)  FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1  
 WHERE   F.FATID=@FATID AND    ISNULL(F.FISIVAR,0)=0  AND ISNULL(F.FISTURID,1)>0 AND  ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )    

  UNION ALL 

--Alis Fatura KDV Tevkifat 
  SELECT 'Alis Fatura KDV Tevkifat' AS TBL,  FISID,NULL AS ALTCARIID,HESAPID,F.FISHESAPID AS KARSIHESAPID, SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,SUM(DBORC),SUM(DALACAK),DOVIZ,KUR,BELGENO,BELGEACIKLAMA,NULL ODEMEYONTEMI, NULL YEVSATIRSIRANO,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
,0 AS ODENMEYEN,NULL AS ODENMEYENALANI,NULL AS TABLOADI,NULL AS TABLOKAYITID FROM (SELECT    -1*F.FATID AS FISID,              (CASE  
                                                                    WHEN F.FISTURID IN (51,61,65,66,67) THEN ISNULL(KDVTEV.TEVKALISHESAPID,ISNULL(KDVT.TEVKALISHESAPID,-999))   
                                                                    WHEN F.FISTURID IN (54,64) THEN ISNULL(KDVTEV.TEVKSATISIADEHESAPID,ISNULL(KDVT.TEVKSATISIADEHESAPID,-999))                 ELSE -999 END) AS HESAPID,0 AS BORC,  ((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))    
                                        / 100 * (100 - ISNULL(FI.SATIRIND2,0))/ 100 * (100 - ISNULL(FI.SATIRIND3,0))/ 100 * (100 - ISNULL(FI.SATIRIND4,0)) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))    
                                       / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END)) *CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END             
                        /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  *(FI.KDV/100) AS ALACAK, 0 AS DBORC,   0 AS DALACAK, 
              'TL' AS DOVIZ,0 AS KUR, (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END )   AS BELGENO, F.ACIKLAMA  AS BELGEACIKLAMA, F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID , ISNULL(FI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(FI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,  ISNULL(FI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(FI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,  ISNULL(FI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(FI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,  (CASE WHEN ISNULL(F.VERGIMASMERATA,0)>0 THEN ISNULL(FI.MASMERID,F.MASMERID) ELSE NULL END)  AS MASMERID,      ISNULL(FI.PROJEID,F.PROJEID)           AS PROJEID,       ISNULL(ISNULL(FI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL( (CASE WHEN F.FATNO IS NULL OR F.FATNO='' THEN  (CASE WHEN F.FATSERINO IS NULL OR F.FATSERINO='' THEN F.FATNO ELSE F.FATSERINO+'-'+ F.FATNO END )   ELSE F.FATNO END ) ,'')+' Nolu '+ISNULL(F.UNVANI,'')+' Faturası' AS ACIKLAMA ,NULL ISLEMID,NULL KDV, NULL   AS BABSTUTAR,'FATURA' AS ENTKAYNAK,F.FATID ENTKAYITID,0 AS SILINDI, 
 NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, NULL AS BELGETURU,NULL AS BELGETARIH   FROM        FATURA F WITH (NOLOCK) INNER JOIN               
              FATISL FI WITH (NOLOCK) ON  F.FATID =  FI.FATID LEFT OUTER JOIN  
                                      KDVTANIM KDVT WITH (NOLOCK) ON ISNULL(FI.KDV,0)=ISNULL(KDVT.ORAN,0) AND ISNULL(KDVT.SUBEID,F.SUBEID)=F.SUBEID AND ISNULL(KDVT.ALKOLLU,0)=0 INNER JOIN  
                                      QMUH_FISTUR FT  WITH (NOLOCK) ON F.FISTURID = FT.FISTURID   
									  LEFT OUTER JOIN KDVTANIMTEVKIFAT KDVTEV WITH (NOLOCK) ON KDVT.KDVTANIMID=KDVTEV.KDVTANIMID AND KDVTEV.TEVKIFATORAN=FI.TEVORAN  
									  WHERE F.FATID=@FATID AND  ISNULL(F.FISIVAR,0)=0  AND   ISNULL(F.FISTURID,1)>0 AND F.FISTURID IN (51,54,61,64,65,66,67) AND     ((F.FISTURID>50 AND F.FISTURID<70 AND F.FISDURUMID>=0) )   AND ISNULL(FI.SILINDI,0)=0  ) F 
 GROUP BY  FISID,HESAPID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,F.TARIH, F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID, F.SUBEID 
 ,OZELKOD1,OZELKOD2, OZELKOD3, ISLEMGRUPID1, ISLEMGRUPID2,ISLEMGRUPID3, MASMERID,PROJEID,VADE, ACIKLAMA,      
 ISLEMID,KDV,BABSTUTAR,ENTKAYNAK,ENTKAYITID,SILINDI,TEVKIFATKODU,TEVKIFATYUZDE,TVKKDVPAY,TVKKDVPAYDA, CEKID,SSIRA,MIKTAR,BIRIM,BIRIMFIYAT,BELGETURU,BELGETARIH   
 HAVING  ABS(SUM(ALACAK))>0.0005
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_TEMSILCISATIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_TEMSILCISATIS] (@FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN  
SELECT TUKETIMFIS.FIRMAID,SUBELER.SUBEADI, DEPO.DEPOADI, SATISTEMSILCI.ADSOYAD, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN, TARIH,ISLEM,TUKETIMFIS.YETKILI,NAKIT,
KKARTI AS KKARTI,ACIK,DKURU,DKODU, TOPLAM/100*(KOMORANI) AS KOMISYON, 
TTUTAR AS BRUTSATIS,INDORAN,INDTUTAR,TOPLAM AS NETSATIS  FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID LEFT JOIN SATISTEMSILCI ON TUKETIMFIS.KHESAPID=SATISTEMSILCI.SATISTEMSILCIID
INNER JOIN SUBELER ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
WHERE KHESAPID>0 AND TUKETIMFIS.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT3_OZET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT3_OZET] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	AC.UNVANI AS ALTCARIUNVANI, CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, F.BORC,F.ALACAK,F.KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	M.RDOVIZ,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORC,
	F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RALACAK,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1)-F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORCBAKIYE,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	F.ACIKLAMA AS ACIKLAMA,F.BELGEACIKLAMA,F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, M.HESAPTIPID, F.HESAPID, M.KODU AS HESAPKODU,
	M.KODU AS KODU,	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.DOVIZ AS HESAPDOVIZ,
	M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU, HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, FT.FISTURADI, FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.SOZLESMEID, F.MASMERID,  F.PROJEID, OZELKODID,    
	F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,F.ODENMEYEN, (CASE WHEN F.TARIH<=GETDATE() THEN F.ODENMEYEN ELSE 0.00 END) AS ODENMEYENGECMIS,
	F.ODENMEYENALANI,F.TABLOADI,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, 
	MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI,MGHESAP1.GRUPADI AS HESAPGRUBU1, 
	MGHESAP2.GRUPADI AS HESAPGRUBU2, cast('Genel' as nvarchar(10)) AS ACENTASI, cast('Genel' as nvarchar(10)) AS TEMSILCI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
/*Fis Baslik Tek Satir */
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			    ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID,ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

/*Fis Baslik Detayli */
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID,ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
  LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 ORDER BY F.TARIH, F.FISID, MK.KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT3_OZET_VADE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT3_OZET_VADE] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	AC.UNVANI AS ALTCARIUNVANI, CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, F.BORC,F.ALACAK,F.KUR,
	(ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0))*-1 AS BORCBAKIYE,
	CASE WHEN ISNULL(F.DOVIZ,'TL')=''  THEN 'TL' ELSE F.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(F.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(F.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	M.RDOVIZ,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORC,
	F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RALACAK,
	F.BORC/NULLIF(DOVIZISL.MBDOVIZALIS,1)-F.ALACAK/NULLIF(DOVIZISL.MBDOVIZALIS,1) AS RBORCBAKIYE,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	F.ACIKLAMA AS ACIKLAMA,F.BELGEACIKLAMA,F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, M.HESAPTIPID,F.HESAPID, M.KODU AS HESAPKODU,
	M.KODU AS KODU,	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.DOVIZ AS HESAPDOVIZ,
	M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU, HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, FT.FISTURADI, FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.SOZLESMEID, F.MASMERID,  F.PROJEID, OZELKODID,    
	F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,F.ODENMEYEN,(CASE WHEN ISNULL(F.VADE,F.TARIH)<=GETDATE() THEN F.ODENMEYEN ELSE 0.00 END) AS ODENMEYENGECMIS,
	F.ODENMEYENALANI,F.TABLOADI,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, 
	MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI,MGHESAP1.GRUPADI AS HESAPGRUBU1, 
	MGHESAP2.GRUPADI AS HESAPGRUBU2, cast('Genel' as nvarchar(10)) AS ACENTASI, cast('Genel' as nvarchar(10)) AS TEMSILCI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
/*Fis Baslik Tek Satir */
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

/*Fis Baslik Detayli */
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(HI.VADE,ISNULL(F.VADE,F.TARIH)) BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
  LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID AND MG1.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID AND MG2.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID AND MG3.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID AND MG4.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID AND MG5.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID AND MG6.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID AND MGHESAP1.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID AND MGHESAP2.FIRMAID=@FIRMAID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 ORDER BY F.TARIH, F.FISID, MK.KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_YASLANDIRMA_ISLEMGRUPID1]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_YASLANDIRMA_ISLEMGRUPID1] (@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),
@FIRMAID NVARCHAR(10),@HESAPID NVARCHAR(10), @ISLEMGRUPID1 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  * FROM YASLANDIRMA WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND HESAPID=@HESAPID 
AND ISLEMGRUPID1=@ISLEMGRUPID1 AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID, F.ISLEMGRUPID1, F.ISLEMGRUPID2,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
/*Fis Baslik Detayli */
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,   ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,   ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, PROJEID, ISLEMGRUPID1,ISLEMGRUPID2, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE 1=1  AND M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLEMLER_RAPOR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKISLEMLER_RAPOR] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT 1 AS FTIPI,FI.FATISLID AS SATIRKNO,F.FIRMAID,F.FATID,FISHESAPID AS HESAPID, F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * STOK.SALISFIYAT) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,F.TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU,KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
NULL AS KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 

UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
KDEPO.KODU CARIKODU, KDEPO.DEPOADI CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   
 UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * -1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, (DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))  AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET) AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI, ((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * -1)*ISNULL(DFI.DKURU,1) AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   

UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET) AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI, ((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR)*ISNULL(DFI.DKURU,1) AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
/*SERVİS FORMU */
 UNION ALL
SELECT 1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.FIRMAID, DF.ARACKABULID AS FATID,DF.CARIID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_FATURA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_FATURA] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID, F.ISLEMGRUPID1, F.ISLEMGRUPID2, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(ISNULL(HI.DOVIZ,F.DOVIZ),'TL') AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,     ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,     ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
/*Fis Baslik Detayli */
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,   ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC,0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  /*ALIS FATURA ODEMESI ODEMEHESAPID */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ODENENTUTAR,0) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  /*ALIS FATURA ODEMESI ODEMEHESAPID2 */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID2 AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR2,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ODENENTUTAR2,0) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID2 IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2, PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  
  UNION ALL
 SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0)  AS ALACAK, 0.00 AS DBORC,(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))/ISNULL(NULLIF(KUR,0),1) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  
  UNION ALL
  /*SATIS FATURA TAHSILATI ODEMEHESAPID */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, ISNULL(ODENENTUTAR,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0) AS DBORC, 0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  /*SATIS FATURA TAHSILATI ODEMEHESAPID2 */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID2 AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR2,0) AS DBORC, 0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID2 IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  /*1-SATIS ACIK>0 BORC YAZILMASI */
  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(ACIK,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK,
  ISNULL(DKODU,'TL') AS  DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ACIK>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
  UNION ALL
  /*1-SATIS ACIK<0 İADE YAZILMASI */
  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(ACIK,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ACIK,0) AS DALACAK,
  ISNULL(DKODU,'TL') AS  DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış iade Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış İADE Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış İADE Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ACIK<0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
/*  UNION ALL */
/*  --2-SATIS NAKIT>0 CARI HESABINA BORC YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC,0.00 AS ALACAK, ISNULL(NAKIT,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  */
/*  UNION ALL */
/*--3-SATIS KKARTI>0 CARI HESABINA BORC YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC,0.00 AS ALACAK, ISNULL(KKARTI,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  */
/*  UNION ALL */
/*  --4-SATIS NAKIT>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NAKITHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(NAKIT,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  */
/*  UNION ALL */
/*--5-SATIS KKARTI>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  KKARTIHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(KKARTI,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  */
/*  UNION ALL */
/*  --6-SATIS NAKIT KISMININ YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,NAKITHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKITHESAPID>0 AND ISLEM='SATIS' AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND NAKITHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*--7-SATIS KKARTI KISMININ YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,KKARTIHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTIHESAPID>0 AND ISLEM='SATIS' AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND KKARTIHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --1-ALIS ACIK>0 ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(ACIK,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE ACIK>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --2-ALIS NAKIT>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --3-ALIS KKARTI>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --4-ALIS KKARTI>0 CARI HESABINA KKARTI KISMI BORC YAZILMASI  */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  KKARTIHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC, 0.00 AS ALACAK, ISNULL(KKARTI,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*--5-ALIS NAKIT>0 CARI HESABINA KASA KISMI BORC YAZILMASI  */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NAKITHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC, 0.00 AS ALACAK, ISNULL(NAKIT,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --6-ALIS NAKIT KISMIN YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,NAKITHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKITHESAPID>0 AND ISLEM='ALIS' AND  ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND NAKITHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */
/*  UNION ALL */
/*  --7-ALIS KKARTI KISMIN YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,KKARTIHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTIHESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND KKARTIHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')    */

  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKBAKIYE2]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKBAKIYE2] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT F.FIRMAID, F.TARIH,F.ADD_DATE AS ISLEMTARIH, 'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,STOK.GRUPID,
FI.STOKID,FI.RENKID,FI.BEDENID,STOK.KODU AS STOKKODU,FI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET, FI.BFIYAT, 
ISNULL((((((((FI.BFIYAT*(100-FI.SATIRIND)/100)*(100-FI.SATIRIND2)/100)*(100-ISNULL(F.INDORAN1,0))/100)*(100+ISNULL(F.EKORAN1,0))/100)*(100-ISNULL(F.INDORAN2,0))/100)*(100+ISNULL(F.EKORAN2,0))/100) 
          * (100 - ISNULL(F.INDORAN3,0)) / 100) * (100 + ISNULL(F.EKORAN3,0)) / 100, 0) AS NFIYAT,SFIYAT1, 
		  (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) 
		  *
		  STOK.SALISBFIYAT AS MALIYETTUTAR,STOK.SALISBFIYAT,

		  (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) 
		  *
		  STOK.SFIYAT1 AS SATISTUTAR,
F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN   
		  SGRUP WITH (NOLOCK) ON STOK.GRUPID=SGRUP.SGRUPID LEFT JOIN
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2 and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID
UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI, DF.ISLEM,STOK.GRUPID,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT, DFI.BFIYAT AS NFIYAT,SFIYAT1, DFI.MIKTAR*ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS MALIYETTUTAR, ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS SALISBFIYAT, DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR, DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID
UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI, 'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,SFIYAT1,DFI.MIKTAR*ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS MALIYETTUTAR, ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS SALISBFIYAT, DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR, DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID  INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID

UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI,
'TUKETIM' AS ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR*-1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,SFIYAT1,DFI.MIKTAR*ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS MALIYETTUTAR, ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS SALISBFIYAT, DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID   INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID
 UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI,
DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,SFIYAT1,DFI.MIKTAR*ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS MALIYETTUTAR, ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS SALISBFIYAT, DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR, DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID    INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID

UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI,DF.ISLEM,STOK.GRUPID,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR  AS GCADET,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS NFIYAT,SFIYAT1,DFI.MIKTAR*ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS MALIYETTUTAR, ISNULL(DFI.FBMALIYET,STOK.SALISFIYAT) AS SALISBFIYAT,DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  and STOK.TURU='Hammadde' AND STOK.FIRMAID=@FIRMAID
/*SERVİS FORMU */
 UNION ALL
SELECT DF.FIRMAID, DF.TARIH,DF.TARIH AS ISLEMTARIH,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,SGRUP.GRUPKODU,SGRUP.GRUPADI,'SATIS' AS ISLEM,STOK.GRUPID,
DFI.STOKID,NULL AS RENKID,NULL AS BEDENID,STOK.KODU AS STOKKODU,STOK.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DFI.BFIYAT,DFI.BFIYAT AS NFIYAT,SFIYAT1,DFI.MIKTAR*STOK.SALISBFIYAT AS MALIYETTUTAR, STOK.SALISBFIYAT,DFI.MIKTAR*STOK.SFIYAT1 AS SATISTUTAR, DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) LEFT JOIN SGRUP WITH (NOLOCK) ON  STOK.GRUPID=SGRUP.SGRUPID  INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 and STOK.TURU='Hammadde'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUHMIZAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_QMUHMIZAN] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.TARIH,ISNULL(F.VADE,F.TARIH) AS VADE, OZELKODID, FISID,F.FISTURID,F.FISTURU,F.BELGENO,F.ACIKLAMA,F.FISNO,F.SUBEID,SUBEADI,
	F.MASMERID,MG.GRUPKODU AS MASMERKODU,MG.GRUPADI AS MASMERADI, F.ISLEMGRUPID1,F.ISLEMGRUPID2,
	F.PROJEID, MG1.GRUPKODU AS PROJEKODU, MG1.GRUPADI AS PROJEADI, 
	F.HESAPID,F.ALTCARIID,F.KHESAPID,F.KALTCARIID,
	M.KODU, M.HESAPGRUPID1, ISNULL(HG1.GRUPADI,M1.ACIKLAMA) AS HESAPGRUPADI, M.HESAPGRUPID2, M.KODU AS HESAPKODU,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	M.ACIKLAMA AS HESAPADI, M.KODU+' : '+M.ACIKLAMA AS HESAPKODUveADI, M1.KODU AS KARSIHESAPKODU, M1.ACIKLAMA AS KARSIHESAPADI,
	A.KODU AS ALTCARIKODU, A.UNVANI AS ALTCARIUNVAN, A1.KODU AS KARSIALTCARI, A1.UNVANI AS KARSIALTCARIUNVAN,  M.SEVIYE AS HESAPSEVIYE,M.HESAPTIPID,M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	F.BORC AS BORC, F.ALACAK AS ALACAK, F.BABSTUTAR, ISNULL(F.DOVIZ,'TL') AS DOVIZ, M.DOVIZ AS HESAPDOVIZ, F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,F.KUR,	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,ENTKAYNAK
	 FROM (SELECT F.FISID,F.FISTURID,TARIH,HI.VADE, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISTURU, F.BELGENO,HI.ACIKLAMA,F.FISNO, F.FIRMAID,ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,
	 ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1, ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2, ISNULL(F.PROJEID,HI.PROJEID) AS PROJEID, F.SUBEID,  HI.HESAPID, HI.ALTCARIID, F.FISHESAPID AS KHESAPID, F.ALTCARIID AS KALTCARIID, 
	 HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK, HI.BABSTUTAR,
              HI.DOVIZ AS DOVIZ,HI.KUR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT F.FISID,F.FISTURID,TARIH,F.VADE, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISTURU, F.BELGENO,F.ACIKLAMA,F.FISNO,F.FIRMAID, ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)  AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)  AS ISLEMGRUPID2,  ISNULL(HI.PROJEID,F.PROJEID)  AS PROJEID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, HI.HESAPID AS KHESAPID, HI.ALTCARIID AS KALTCARIID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,F.BABSTUTAR,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1  

UNION ALL
/*Fis Baslik Detayli */
  SELECT F.FISID,F.FISTURID,TARIH, ISNULL(HI.VADE,F.VADE) AS VADE, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISTURU, F.BELGENO,F.ACIKLAMA,F.FISNO,F.FIRMAID,ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)  AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)  AS ISLEMGRUPID2,  ISNULL(HI.PROJEID,F.PROJEID)  AS PROJEID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, HI.HESAPID AS KHESAPID, HI.ALTCARIID AS KALTCARIID,
  HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 HI.BABSTUTAR,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK FROM    MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 

  UNION ALL

  SELECT  SERVISFORMID*-1 AS FISID, 5 AS FISTURID, TARIH, TARIH AS VADE, NULL AS OZELKODID, 'Borç Dekontu' AS FISTURU, FORMNO AS BELGENO,
FORMNO+' Nolu Servis Formu' AS ACIKLAMA,FORMNO AS FISNO, FIRMAID,NULL AS MASMERID,NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2,
PROJEID,SUBEID, CARIID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
NETTOPLAM AS BORC, 0.00 AS ALACAK, NETTOPLAM AS DBORC, 0.00 AS DALACAK, NULL AS BABSTUTAR, 'TL' HDOVIZ,1 AS KUR, NULL AS ENTKAYNAK
 FROM SERVISFORM
  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND ABS(NETTOPLAM)>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID
) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT JOIN MUH_HESAP AS M1				WITH (NOLOCK)   ON F.KHESAPID=M1.HESAPID
 LEFT JOIN MUH_HESAP_ALTCARI AS A		WITH (NOLOCK)   ON F.ALTCARIID=A.ALTCARIID
 LEFT JOIN MUH_HESAP_ALTCARI AS A1		WITH (NOLOCK)	ON F.KALTCARIID=A1.ALTCARIID
 LEFT JOIN MUH_GRUP AS MG				WITH (NOLOCK)	ON F.MASMERID=MG.GRUPID AND MG.TIPID=6
 LEFT JOIN MUH_GRUP AS MG1				WITH (NOLOCK)	ON F.PROJEID=MG1.GRUPID AND MG1.TIPID=7
 LEFT JOIN MUH_GRUP AS HG1				WITH (NOLOCK)	ON M1.HESAPGRUPID1=HG1.GRUPID AND HG1.TIPID=1
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE 1=1  AND M.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MUHFIS_FISID]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE FUNCTION [dbo].[FNCQ_MUHFIS_FISID] (@FISID NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND   F.FIRMAID=@FIRMAID 
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND  F.FIRMAID=@FIRMAID
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DBORC,
			 HI.DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND  F.FIRMAID=@FIRMAID) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUHMIZAN_FATURA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_QMUHMIZAN_FATURA] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.TARIH,ISNULL(F.VADE,F.TARIH) AS VADE, ISLEMID, OZELKODID, FISID,F.FISTURID,F.FISTURU,F.BELGENO,F.ACIKLAMA,F.FISNO,F.SUBEID,SUBEADI,
	F.SOZLESMEID, F.MASMERID,MG.GRUPKODU AS MASMERKODU,MG.GRUPADI AS MASMERADI, F.ISLEMGRUPID1,F.ISLEMGRUPID2,F.ISLEMGRUPID3,
	F.PROJEID, MG1.GRUPKODU+'X' AS PROJEKODU, MG1.GRUPADI AS PROJEADI, 
	F.HESAPID,F.ALTCARIID,F.KHESAPID,F.KALTCARIID,
	M.KODU, M.HESAPGRUPID1, ISNULL(HG1.GRUPADI,M1.ACIKLAMA) AS HESAPGRUPADI, M.HESAPGRUPID2, M.KODU AS HESAPKODU,M.ACIKLAMA AS HESAPADI, M.KODU+' : '+M.ACIKLAMA AS HESAPKODUveADI, M1.KODU AS KARSIHESAPKODU, M1.ACIKLAMA AS KARSIHESAPADI,
	A.KODU AS ALTCARIKODU, A.UNVANI AS ALTCARIUNVAN, A1.KODU AS KARSIALTCARI, A1.UNVANI AS KARSIALTCARIUNVAN,  M.SEVIYE AS HESAPSEVIYE,M.HESAPTIPID,M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	F.BORC AS BORC, F.ALACAK AS ALACAK, F.BABSTUTAR, ISNULL(F.DOVIZ,'TL') AS DOVIZ, M.DOVIZ AS HESAPDOVIZ, F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,F.KUR,	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,F.ADD_DATE,F.ADD_USERID,F.EDIT_DATE,F.EDIT_USERID
	 FROM (SELECT HI.ISLEMID, ISNULL(HI.OZELKODID, F.OZELKODID) AS OZELKODID, F.FISID,F.FISTURID,TARIH,HI.VADE, F.FISTURU, F.BELGENO,HI.ACIKLAMA,F.FISNO, F.FIRMAID,ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID,  ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,
	 ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1, ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2, ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3)  AS ISLEMGRUPID3, ISNULL(F.PROJEID,HI.PROJEID) AS PROJEID, F.SUBEID,  HI.HESAPID, HI.ALTCARIID, F.FISHESAPID AS KHESAPID, F.ALTCARIID AS KALTCARIID, 
	 HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK, HI.BABSTUTAR,
              HI.DOVIZ AS DOVIZ,HI.KUR, F.ADD_DATE,F.ADD_USERID,F.EDIT_DATE,F.EDIT_USERID FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT HI.ISLEMID, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISID,F.FISTURID,TARIH,F.VADE, F.FISTURU, F.BELGENO,F.ACIKLAMA,F.FISNO,F.FIRMAID, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,  
   ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)  AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)  AS ISLEMGRUPID2, ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3)  AS ISLEMGRUPID3, ISNULL(HI.PROJEID,F.PROJEID)  AS PROJEID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, HI.HESAPID AS KHESAPID, HI.ALTCARIID AS KALTCARIID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,F.BABSTUTAR,
               F.DOVIZ AS DOVIZ,F.KUR,F.ADD_DATE,F.ADD_USERID,F.EDIT_DATE,F.EDIT_USERID FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1  

UNION ALL
/*Fis Baslik Detayli */
  SELECT HI.ISLEMID, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISID,F.FISTURID,TARIH, ISNULL(HI.VADE,F.VADE) AS VADE, F.FISTURU, F.BELGENO,HI.ACIKLAMA,F.FISNO,F.FIRMAID,ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS SOZLESMEID, ISNULL(HI.MASMERID,F.MASMERID) AS MASMERID,  
  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)  AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)  AS ISLEMGRUPID2,  
  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3)  AS ISLEMGRUPID3,  ISNULL(HI.PROJEID,F.PROJEID)  AS PROJEID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, HI.HESAPID AS KHESAPID, HI.ALTCARIID AS KALTCARIID,
  HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 HI.BABSTUTAR,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR, F.ADD_DATE,F.ADD_USERID,F.EDIT_DATE,F.EDIT_USERID FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 

  UNION ALL

  SELECT SERVISFORMID,  NULL, SERVISFORMID*-1 AS FISID, 5 AS FISTURID, TARIH, TARIH AS VADE, 'Borç Dekontu' AS FISTURU, FORMNO AS BELGENO,
FORMNO+' Nolu Servis Formu' AS ACIKLAMA,FORMNO AS FISNO, FIRMAID,NULL AS SOZLESMEID, NULL AS MASMERID, 
NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2,NULL AS ISLEMGRUPID3,
PROJEID,SUBEID, CARIID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
NETTOPLAM AS BORC, 0.00 AS ALACAK, NETTOPLAM AS DBORC, 0.00 AS DALACAK, NULL AS BABSTUTAR, 'TL' HDOVIZ,1 AS KUR, SERVISFORM.ADD_DATE,SERVISFORM.ADD_USERID,SERVISFORM.EDIT_DATE,SERVISFORM.EDIT_USERID
 FROM SERVISFORM
  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND ABS(NETTOPLAM)>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID

    UNION ALL

  SELECT FATID,  NULL, FATID*-1 AS FISID, FISTURID, TARIH, TARIH AS VADE, FISTURADI AS FISTURU, FATNO AS BELGENO,
FATNO+' Nolu Satış Fatura' AS ACIKLAMA,FATNO AS FISNO, FIRMAID,NULL AS SOZLESMEID,NULL AS MASMERID,
NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,SUBEID, FISHESAPID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
GTOPLAM AS BORC, 0.00 AS ALACAK, DTOPLAM AS DBORC, 0.00 AS DALACAK, TOPLAM AS BABSTUTAR, DOVIZ HDOVIZ, KUR, FATURA.ADD_DATE,FATURA.ADD_USERID,FATURA.EDIT_DATE,FATURA.EDIT_USERID
 FROM FATURA
  WHERE FISDURUMID>=0 AND  FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID

    UNION ALL

  SELECT FATID, NULL, FATID*-1 AS FISID, FISTURID, TARIH, TARIH AS VADE, FISTURADI AS FISTURU, FATNO AS BELGENO,
FATNO+' Nolu Alış Fatura' AS ACIKLAMA,FATNO AS FISNO, FIRMAID,NULL AS SOZLESMEID, NULL AS MASMERID,NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,SUBEID, FISHESAPID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
0.00 AS BORC, GTOPLAM AS ALACAK, 0.00 AS DBORC, DTOPLAM AS DALACAK, TOPLAM AS BABSTUTAR, DOVIZ HDOVIZ, KUR, FATURA.ADD_DATE,FATURA.ADD_USERID,FATURA.EDIT_DATE,FATURA.EDIT_USERID
 FROM FATURA
  WHERE FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID
  UNION ALL
  SELECT FATID, NULL, FATID*-1 AS FISID, FISTURID, TARIH, TARIH AS VADE, FISTURADI AS FISTURU, FATNO AS BELGENO,
FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,FATNO AS FISNO,  FIRMAID, NULL AS SOZLESMEID, NULL AS MASMERID,NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,SUBEID, FISHESAPID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC, 0.00 AS DALACAK, TOPLAM AS BABSTUTAR, DOVIZ HDOVIZ, KUR, FATURA.ADD_DATE,FATURA.ADD_USERID,FATURA.EDIT_DATE,FATURA.EDIT_USERID
 FROM FATURA
  WHERE abs(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 and FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID
  UNION ALL
  SELECT FATID, NULL, FATID*-1 AS FISID, FISTURID, TARIH, TARIH AS VADE, FISTURADI AS FISTURU, FATNO AS BELGENO,
FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,FATNO AS FISNO,  FIRMAID, NULL AS SOZLESMEID, NULL AS MASMERID,NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,SUBEID, FISHESAPID AS HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
0.00 AS BORC, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DALACAK, TOPLAM AS BABSTUTAR, DOVIZ HDOVIZ, KUR, FATURA.ADD_DATE,FATURA.ADD_USERID,FATURA.EDIT_DATE,FATURA.EDIT_USERID
 FROM FATURA
  WHERE abs(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 and FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID  
  UNION ALL
  SELECT DEPOFISID,  NULL, DEPOFISID*-1 AS FISID, -1 AS FISTURID, TARIH, TARIH AS VADE, 'Perakende Satış' as FISTURU, CAST(DEPOFISID AS NVARCHAR(10)) AS BELGENO,
ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS ACIKLAMA,CAST(DEPOFISID AS NVARCHAR(10)) AS FISNO, TUKETIMFIS.FIRMAID, NULL AS SOZLESMEID, 
NULL AS MASMERID,NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,DEPO.ACIKSUBEID AS SUBEID, HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
ISNULL(ACIK,0) AS BORC, 0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR, DKODU AS HDOVIZ, DKURU AS KUR, TUKETIMFIS.ADD_DATE,TUKETIMFIS.ADD_USERID,TUKETIMFIS.EDIT_DATE,TUKETIMFIS.EDIT_USERID
FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE ABS(ACIK)>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID 
  UNION ALL
  SELECT DEPOFISID,  NULL, DEPOFISID*-1 AS FISID, -1 AS FISTURID, TARIH, TARIH AS VADE, 'Alış Fişi' as FISTURU, CAST(DEPOFISID AS NVARCHAR(10)) AS BELGENO,
ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS ACIKLAMA,CAST(DEPOFISID AS NVARCHAR(10)) AS FISNO, TUKETIMFIS.FIRMAID, NULL AS SOZLESMEID, NULL AS MASMERID,
NULL AS ISLEMGRUPID1, NULL AS ISLEMGRUPID2, NULL AS ISLEMGRUPID3,
PROJEID,DEPO.ACIKSUBEID AS SUBEID, HESAPID,NULL AS ALTCARIID, NULL AS KHESAPID, NULL AS KALTCARIID,
0.00 AS BORC, ISNULL(ACIK,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ACIK,0) AS DALACAK, 0.00 AS BABSTUTAR, DKODU AS HDOVIZ, DKURU AS KUR, TUKETIMFIS.ADD_DATE,TUKETIMFIS.ADD_USERID,TUKETIMFIS.EDIT_DATE,TUKETIMFIS.EDIT_USERID
FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.GDEPOID=DEPO.DEPOID  WHERE ABS(ACIK)>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID 
) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT JOIN MUH_HESAP AS M1				WITH (NOLOCK)   ON F.KHESAPID=M1.HESAPID
 LEFT JOIN MUH_HESAP_ALTCARI AS A		WITH (NOLOCK)   ON F.ALTCARIID=A.ALTCARIID
 LEFT JOIN MUH_HESAP_ALTCARI AS A1		WITH (NOLOCK)	ON F.KALTCARIID=A1.ALTCARIID
 LEFT JOIN MUH_GRUP AS MG				WITH (NOLOCK)	ON F.MASMERID=MG.GRUPID AND MG.TIPID=6
 LEFT JOIN MUH_GRUP AS MG1				WITH (NOLOCK)	ON F.PROJEID=MG1.GRUPID AND MG1.TIPID=7
 LEFT JOIN MUH_GRUP AS HG1				WITH (NOLOCK)	ON M1.HESAPGRUPID1=HG1.GRUPID AND HG1.TIPID=1
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE 1=1 AND M.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_FATURA_03112021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






 



--SELECT * FROM  [FNCQ_HESAPDETAY_FATURA] ('2020-01-01', '2021-12-31', '93', '1020002')

CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_FATURA_03112021] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, NULL AS ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, TOPLAM AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID 
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_FATURA_HESAPID]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_FATURA_HESAPID] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID, F.ISLEMGRUPID1,F.ISLEMGRUPID2,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(ISNULL(HI.DOVIZ,F.DOVIZ),'TL') AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID=@KODU
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
 UNION ALL
/*Fis Baslik Detayli */
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE HI.DALACAK END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE HI.DBORC END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,   ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,   ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, ISLEMGRUPID1, ISLEMGRUPID2, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID=@KODU
  UNION ALL
SELECT FIRMAID,FATID AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2, PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
 SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC,0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  /*ALIS FATURA ODEMESI ODEMEHESAPID */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ODENENTUTAR,0) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID=@KODU
  UNION ALL
  /*ALIS FATURA ODEMESI ODEMEHESAPID2 */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID2 AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR2,0) AS ALACAK, 0.00 AS DBORC, ISNULL(ODENENTUTAR2,0) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura Ödemesi' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura Ödemesi' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura Ödemesi' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID2=@KODU
  UNION ALL 
  SELECT FIRMAID,FATID AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2, PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  /*SATIŞ FATURASI CARİ TAHSİL EDİLEN KISMI İÇİN */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0)  AS ALACAK, 0.00 AS DBORC,(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))/ISNULL(NULLIF(KUR,0),1) AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
/*SATIS FATURA TAHSILATI ODEMEHESAPID */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, ISNULL(ODENENTUTAR,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR,0) AS DBORC, 0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID=@KODU
  UNION ALL
  /*SATIS FATURA TAHSILATI ODEMEHESAPID2 */
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,ODEMEHESAPID2 AS HESAPID,
  FISHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT, ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, ISNULL(ODENENTUTAR2,0) AS DBORC, 0.00 AS DALACAK,
  ISNULL(DOVIZ,'TL') AS DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura Tahsilatı' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, MASMERID, ISLEMGRUPID1,  ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura Tahsilatı' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Fatura Tahsilatı' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE ABS(ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND ODEMEHESAPID2=@KODU
  UNION ALL
  /*1-SATIS ACIK>0 BORC YAZILMASI */
  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(ACIK,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK,
  ISNULL(DKODU,'TL') AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ACIK>0 AND ISLEM='SATIS' AND 
  ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU
  /*1-SATIS ACIK<0 İADE ALACAK YAZILMASI */
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(abs(ACIK),0) AS ALACAK, 0.00 AS DBORC, ISNULL(abs(ACIK),0)  AS DALACAK,
  ISNULL(DKODU,'TL') AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış iade Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ACIK<0 AND ISLEM='SATIS' AND 
  ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND HESAPID=174921
        
/*  UNION ALL */
/*  --2-SATIS NAKIT>0 CARI HESABINA BORC YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC,0.00 AS ALACAK, ISNULL(NAKIT,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*--3-SATIS KKARTI>0 CARI HESABINA BORC YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC,0.00 AS ALACAK, ISNULL(KKARTI,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --4-SATIS NAKIT>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NAKITHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(NAKIT,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*--5-SATIS KKARTI>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  KKARTIHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(KKARTI,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND ISLEM='SATIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --6-SATIS NAKIT KISMININ YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,NAKITHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE NAKITHESAPID>0 AND ISLEM='SATIS' AND  ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND NAKITHESAPID=@KODU */
/*  UNION ALL */
/*--7-SATIS KKARTI KISMININ YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,KKARTIHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC,0.00 AS ALACAK, ISNULL(ACIK,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE KKARTIHESAPID>0 AND ISLEM='SATIS' AND  ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND KKARTIHESAPID=@KODU */
/*  UNION ALL */
/*  --1-ALIS ACIK>0 ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(ACIK,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE ACIK>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --2-ALIS NAKIT>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --3-ALIS KKARTI>0 CARI HESABINA ALACAK YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --4-ALIS KKARTI>0 CARI HESABINA KKARTI KISMI BORC YAZILMASI  */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  KKARTIHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(KKARTI,0) AS BORC, 0.00 AS ALACAK, ISNULL(KKARTI,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTI>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*--5-ALIS NAKIT>0 CARI HESABINA KASA KISMI BORC YAZILMASI  */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID, */
/*  NAKITHESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(NAKIT,0) AS BORC, 0.00 AS ALACAK, ISNULL(NAKIT,0) AS DBORC,0.00 AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKIT>0 AND HESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU */
/*  UNION ALL */
/*  --6-ALIS NAKIT KISMIN YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,NAKITHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(NAKIT,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE NAKITHESAPID>0 AND ISLEM='ALIS' AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND NAKITHESAPID=@KODU */
/*  UNION ALL */
/*  --7-ALIS KKARTI KISMIN YAZILMASI */
/*  SELECT TUKETIMFIS.FIRMAID,DEPOFISID AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,KKARTIHESAPID AS HESAPID, */
/*  HESAPID AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC,ISNULL(KKARTI,0) AS ALACAK, 0.00 AS DBORC,ISNULL(ACIK,0) AS DALACAK, */
/*  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'ALIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'ALIS') AS FISNO, */
/*  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID, */
/*  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,TUKETIMFIS.SUBEID) AS SUBEID, MASMERID, ISLEMGRUPID1, ISLEMGRUPID2,  PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alş Fişi') AS ACIKLAMA, */
/*  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU, */
/*  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH, */
/*  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID, */
/*  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Alış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO  */
/*  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID WHERE KKARTIHESAPID>0 AND ISLEM='ALIS' AND  ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND KKARTIHESAPID=@KODU */
 ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_TESTTT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






 



--SELECT * FROM  [FNCQ_HESAPDETAY_FATURA] ('2020-01-01', '2021-12-31', '93', '1020002')

CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_TESTTT] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID=@KODU
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID=@KODU
  UNION ALL
SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@KODU
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, NULL AS ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, TOPLAM AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID=@KODU
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_HESAPID]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_HESAPID] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	M.RDOVIZ,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DBORC ELSE F.BORC/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RBORC,
	(CASE WHEN F.DOVIZ=DOVIZISL.KODU THEN F.DALACAK ELSE F.ALACAK/NULLIF(DOVIZISL.MBDOVIZSATIS,1) END) AS RALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID, F.ISLEMGRUPID1, F.ISLEMGRUPID2, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID, ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,     ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID=@KODU
UNION ALL
/*Fis Baslik Tek Satir */
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID, ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,     ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
 UNION ALL
/*Fis Baslik Detayli */
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE HI.DALACAK END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE HI.DBORC END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ,ISNULL(F.KUR,HI.KUR) AS KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1)         AS ISLEMGRUPID1,  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2)         AS ISLEMGRUPID2,    ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,F.ENTKAYNAK) AS ENTKAYNAK, ISNULL(HI.ENTKAYITID,F.ENTKAYNAKID) AS ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID=@KODU
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN DOVIZISL WITH (NOLOCK) ON F.TARIH=DOVIZISL.TARIH AND F.SUBEID=DOVIZISL.SUBEID AND M.RDOVIZ=DOVIZISL.KODU
 WHERE M.FIRMAID=@FIRMAID AND M.HESAPID=@KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SERVISFORM_ANALIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SERVISFORM_ANALIZ] (@FIRMAID INT, @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT SERVISFORM.FIRMAID, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, DAY(TARIH) AS GUN,MUH_GRUP.GRUPADI AS PROJEADI, ISLEM1.GRUPADI AS ISLEMGRUBU1, ISLEM2.GRUPADI AS ISLEMGRUBU2, TARIH, SAAT,BITISSAAT, FIRMAYETKILI, UNVANI, ADSOYAD KULLANICI, 
CAST((CASE WHEN convert(varchar(5), DateDiff(Minute, SAAT , BITISSAAT))='*' THEN 0 ELSE convert(varchar(5), DateDiff(Minute, SAAT , BITISSAAT)) END) AS INT) AS SURE,
CAST((CASE WHEN convert(varchar(5), DateDiff(Minute, SAAT , BITISSAAT))='*' THEN 0 ELSE convert(varchar(5), DateDiff(Minute, SAAT , BITISSAAT)) END) AS INT)/60.00 AS SURESAAT, 1 AS SAYI 
FROM SERVISFORM INNER JOIN NOVAUSER ON SERVISFORM.ISIBITIRENUSERID=NOVAUSER.NOVAUSERID
LEFT JOIN MUH_GRUP ON SERVISFORM.PROJEID=MUH_GRUP.GRUPID
LEFT JOIN MUH_GRUP AS ISLEM1 ON SERVISFORM.ISLEMGRUPID1=ISLEM1.GRUPID
LEFT JOIN MUH_GRUP AS ISLEM2 ON SERVISFORM.ISLEMGRUPID2=ISLEM2.GRUPID
WHERE ISNULL(SERVISFORM.SIL,0)=0 AND SERVISFORM.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2

GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_EMLAKKOM_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_EMLAKKOM_DETAY] (@FIRMAID NVARCHAR(10), @MASMERADI NVARCHAR(30))  RETURNS  table  AS   
RETURN
SELECT EMLAKSATISID,ALICIHESAPID, EMLAKSATIS.SUBEID,DAIREID,DAIRE.GRUPADI AS DAIREADI, PROJEID, PROJE.GRUPADI AS PROJEADI, LISTEFIYATI,REELFIYAT,KOMISYONORAN,KOMISYONTUTAR,EMLAKSATIS.DOVIZ, 
ISNULL((SELECT  SUM(DTUTAR) AS ODENENKOMISYON  FROM  MUH_FIS WITH (NOLOCK) INNER JOIN MUH_HESAPISL WITH (NOLOCK) ON MUH_FIS.FISID=MUH_HESAPISL.FISID WHERE ISNULL(MUH_FIS.SIL,0)=0 AND EMLAKSATIS.DAIREID=MUH_FIS.OZELKODID AND EMLAKSATIS.PROJEID=MUH_FIS.PROJEID
 AND MUH_FIS.FISTURID IN(1,3) AND EMLAKSATIS.FIRMAID=@FIRMAID AND ISNULL(MUH_FIS.MASMERID,MUH_HESAPISL.MASMERID)=(SELECT DBO.FN_MASRAFMERKEZIBUL(@FIRMAID,@MASMERADI))),0) AS TAHSILEDILENKOM,
 ISNULL((SELECT  SUM(DTUTAR) AS ODENENKOMISYON  FROM  MUH_FIS WITH (NOLOCK) INNER JOIN MUH_HESAPISL WITH (NOLOCK) ON MUH_FIS.FISID=MUH_HESAPISL.FISID WHERE ISNULL(MUH_FIS.SIL,0)=0 AND EMLAKSATIS.DAIREID=MUH_FIS.OZELKODID AND EMLAKSATIS.PROJEID=MUH_FIS.PROJEID
 AND MUH_FIS.FISTURID IN(2,4) AND EMLAKSATIS.FIRMAID=@FIRMAID AND ISNULL(MUH_FIS.MASMERID,MUH_HESAPISL.MASMERID)=(SELECT DBO.FN_MASRAFMERKEZIBUL(@FIRMAID,@MASMERADI))),0) AS ODENENKOM
FROM EMLAKSATIS WITH (NOLOCK) LEFT JOIN MUH_GRUP AS PROJE WITH (NOLOCK) ON EMLAKSATIS.PROJEID=PROJE.GRUPID LEFT JOIN MUH_GRUP AS DAIRE 
WITH (NOLOCK) ON EMLAKSATIS.DAIREID=DAIRE.GRUPID  WHERE EMLAKSATIS.FIRMAID=@FIRMAID AND ISNULL(EMLAKSATIS.SIL,0)=0
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETSATIS_STOK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETSATIS_STOK] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10),@MALIYET FLOAT)  RETURNS  table  AS   
RETURN
SELECT TARIH,TUKETIMFIS.SUBEID,TUKETIMFIS.CDEPOID AS DEPOID, DEPO.DEPOADI AS DEPOADI,NOVAUSER.ADSOYAD AS KASIYER, MUH_HESAP.ACIKLAMA AS MUHHESAPADI, 
TUKETIMFIS.ACIKLAMA,ISLEM, TUKETIMFISISL.BARKOD, TUKETIMFISISL.ACIKLAMA AS STOKADI, SUM(FMIKTAR) AS MIKTAR, FBIRIM, 
SUM(FMIKTAR*FBFIYAT) AS TUTAR, SUM(FMIKTAR*FBFIYAT/100*(100-TUKETIMFISISL.INDORAN)) AS NETTUTAR,SUM(FMIKTAR*ISNULL(FBMALIYET,FBFIYAT*@MALIYET)) AS MALIYETTUTAR FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK) ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID LEFT JOIN 
MUH_HESAP WITH (NOLOCK) ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID AND TUKETIMFIS.FIRMAID=MUH_HESAP.FIRMAID
LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID AND TUKETIMFIS.FIRMAID=NOVAUSER.FIRMAID
LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID AND TUKETIMFIS.FIRMAID=DEPO.FIRMAID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2 AND ISLEM='SATIS' AND ISNULL(SILINDI,0)=0 
GROUP BY TARIH,ISLEM,NOVAUSER.ADSOYAD,TUKETIMFIS.SUBEID, TUKETIMFIS.CDEPOID, MUH_HESAP.ACIKLAMA,TUKETIMFIS.ACIKLAMA,DEPO.DEPOADI,TUKETIMFISISL.BARKOD,TUKETIMFISISL.ACIKLAMA,
TUKETIMFISISL.FBIRIM
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + '_' + CAST(F.FISID AS nvarchar(20)) +
	'_' + ISNULL(MK.KODU,'') + '_' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+'.Çeyrek' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+'.Hft' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO, ISNULL(F.TFISID,F.FISID) AS TFISID,
	ISNULL(F.TFISNO,F.FISNO) AS TFISNO,ISNULL(F.TFISTARIH,F.TARIH) AS TFISTARIH,
	ISNULL(F.TFISACIKLAMA,F.ACIKLAMA) AS TFISACIKLAMA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+' '+MGF.ACIKLAMA,M.KODU+' '+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  PROJEID, OZELKODID,    
	F.ADD_DATE, F.ADD_USERID,  ISNULL(USER_ADD.ADSOYAD,USER_ADD.KODU) AS EKLEYEN,  F.EDIT_DATE,F.EDIT_USERID,
	ISNULL(USER_UPD.ADSOYAD,USER_UPD.KODU) AS GUNCELLEYEN, F.DEL_DATE ,F.DEL_USERID,
	ISNULL(USER_DEL.ADSOYAD,USER_DEL.KODU) AS SILEN, F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
--Fis Baslik Tek Satir
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

--Fis Baslik Detayli
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID AND MGF.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_ADD WITH (NOLOCK)   ON F.ADD_USERID       = USER_ADD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_UPD WITH (NOLOCK)   ON F.EDIT_USERID        = USER_UPD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_DEL WITH (NOLOCK)   ON F.DEL_USERID        = USER_DEL.NOVAUSERID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID
LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID
 
 ORDER BY F.TARIH, F.FISID, MK.KODU, ISLEMID
GO
/****** Object:  Table [dbo].[SPAMEKAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAMEKAN](
	[SPAMEKANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[MEKANADI] [nvarchar](30) NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[AKTIF] [bit] NULL,
	[KAPASITE] [int] NULL,
	[SORUMLUSU] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SPAMEKAN] PRIMARY KEY CLUSTERED 
(
	[SPAMEKANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_SPAANALIZ_PIVOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_SPAANALIZ_PIVOT] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
	 RETURN
	SELECT SPAFIS.FIRMAID, KAPANDI AS [Kapalı Satış],SUBELER.SUBEADI AS [Şube Adı], SPAMEKAN.MEKANADI as [Mekan Adı], ISNULL(convert(varchar, [START], 23),SATISTARIHI) AS SATISTARIHI, ISNULL(convert(varchar, [START], 23),SATISTARIHI) AS [Satış Tarihi], 1 AS [Miktar], GOREVLI.GOREVLIADI as [Görevli Adı],GOREVLI.PRIMORAN AS [Görevli Prim Oranı], 
	ISNULL(GOREVLI.PRIMTUTAR,0) AS [Görevli Prim Tutar],   GOREVLI.DOVIZ AS [Görevli Prim Döviz], 
	ISNULL(GOREVLI.PRIMTUTAR,0)*ISNULL(AJANDA.KUR,1) AS [Görevli Prim TL Tutar], 
	ISNULL(GOREVLI.PRIMSURE,0) AS [Görevli Prim Süre], 
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR ELSE 0.00 END) AS [Görevli Prim Süre Kazanç],
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS [Görevli Prim Süre Kazanç TL],
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR 
	WHEN GOREVLI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*GOREVLI.PRIMORAN WHEN GOREVLI.PRIMTUTAR>0 THEN GOREVLI.PRIMTUTAR  ELSE 0.00 END) 
	AS [Görevli Toplam Prim],
	(CASE WHEN GOREVLI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(GOREVLI.PRIMSURE,0)*GOREVLI.PRIMTUTAR 
	WHEN GOREVLI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*GOREVLI.PRIMORAN WHEN GOREVLI.PRIMTUTAR>0 THEN GOREVLI.PRIMTUTAR  ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) 
	AS [Görevli Toplam Prim TL],

	SATISCI.GOREVLIADI AS [Satışcı Adı], ISNULL(SATISCI.PRIMORAN,0) AS [Satışcı Prim Oran], 
	ISNULL(SATISCI.PRIMTUTAR,0) AS [Satışcı Prim Tutar], SATISCI.DOVIZ AS [Satışçı Prim Döviz], 
	ISNULL(SATISCI.PRIMTUTAR,0)*ISNULL(AJANDA.KUR,1) AS [Satışcı Prim Tutar TL], ISNULL(SATISCI.PRIMSURE,0) AS [Satışcı Prim Süre],
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR ELSE 0.00 END) AS [Satışçı Prim Süre Kazanç],
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) AS [Satışçı Prim Süre Kazanç TL],
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0)*SATISCI.PRIMTUTAR 
	WHEN SATISCI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*SATISCI.PRIMORAN WHEN SATISCI.PRIMTUTAR>0 THEN SATISCI.PRIMTUTAR  ELSE 0.00 END) 
	AS [Satışçı Toplam Prim],
	(CASE WHEN SATISCI.PRIMSURE>0 THEN NULLIF(AJANDA.SURE,0)/NULLIF(SATISCI.PRIMSURE,0) 
	WHEN SATISCI.PRIMORAN>0 THEN (BIRIMFIYAT/100*(100-AJANDA.INDORAN))/100*SATISCI.PRIMORAN WHEN SATISCI.PRIMTUTAR>0 THEN SATISCI.PRIMTUTAR  ELSE 0.00 END)*ISNULL(AJANDA.KUR,1) 
	AS [Satışçı Toplam Prim TL],
	ISNULL(P.ADI,'GENEL') AS [Paket Adı], 
	S.ADI AS [Hizmet Adı], AJANDA.SURE as [Süre], BIRIMFIYAT as [Tutar], BIRIMFIYAT*ISNULL(AJANDA.KUR,1) AS [Tutar TL], AJANDA.INDORAN as [İnd%],
	BIRIMFIYAT-(BIRIMFIYAT/100*(100-AJANDA.INDORAN)) AS [İnd.Tutar],
	(BIRIMFIYAT-(BIRIMFIYAT/100*(100-AJANDA.INDORAN)))*ISNULL(AJANDA.KUR,1) AS [İnd.Tutar TL],
	BIRIMFIYAT/100*(100-AJANDA.INDORAN) AS [Net Tutar], (BIRIMFIYAT/100*(100-AJANDA.INDORAN))*ISNULL(AJANDA.KUR,1) AS [Net Tutat TL],
	AJANDA.KUR [Kur], AJANDA.DOVIZ as [Döviz] FROM AJANDA WITH (NOLOCK) 
	INNER JOIN SPAFIS ON AJANDA.SPAFISID=SPAFIS.SPAFISID 
	INNER JOIN STOK AS S WITH (NOLOCK) ON AJANDA.STOKID=S.STOKID
	LEFT JOIN STOK AS P WITH (NOLOCK) ON AJANDA.ANASTOKID=P.STOKID
	LEFT JOIN SPAGOREVLI AS GOREVLI WITH (NOLOCK) on AJANDA.SPAGOREVLIID=GOREVLI.SPAGOREVLIID
	LEFT JOIN SPAGOREVLI AS SATISCI WITH (NOLOCK) on SPAFIS.SPAGOREVLIID=SATISCI.SPAGOREVLIID
	INNER JOIN SUBELER ON SPAFIS.SUBEID=SUBELER.SUBEID
	INNER JOIN SPAMEKAN ON SPAFIS.SPAMEKANID=SPAMEKAN.SPAMEKANID
	WHERE ISNULL(SPAFIS.SIL,0)=0 AND ISNULL(AJANDA.SIL,0)=0 AND SPAFIS.FIRMAID=@FIRMAID AND ISNULL(convert(varchar, [START], 23),AJANDA.SATISTARIHI) BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_CEKKARNEDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO










CREATE FUNCTION [dbo].[FNCQ_CEKKARNEDETAY] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.CEKID>0
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.CEKID>0
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.CEKID>0
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1  AND M.FIRMAID=@FIRMAID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASATESLIM_OZET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_KASATESLIM_OZET] (@FIRMAID INT, @SUBEID INT, @AKTIFZAMAN DATETIME)  RETURNS  table  AS   
RETURN
		SELECT YETKILI,'SATIS' AS ISLEM,SUM(ISNULL(TOPLAM,0)) AS TOPLAM, 
		SUM(ISNULL(INDTUTAR,0)) AS INDTUTAR, SUM(ISNULL(TOPLAM,0)-ISNULL(INDTUTAR,0))-SUM(ISNULL(ACIK,0)) AS NETTOPLAM, 0.00 as KASAACIKFAZLA 
		FROM TUKETIMFIS WHERE ISLEM='SATIS' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 AND GERCEKTARIH<=@AKTIFZAMAN
		GROUP BY YETKILI
		UNION ALL
		SELECT NOVAUSER.ADSOYAD AS YETKILI,'TAHSILAT' AS ISLEM,SUM(TOPLAM) AS TOPLAM, 0.00,SUM(TOPLAM) AS TOPLAM,0.00 
		FROM MUH_FIS WITH (NOLOCK) LEFT JOIN NOVAUSER ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID  WHERE FISTURID IN(1,3) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY NOVAUSER.ADSOYAD
		UNION ALL
		SELECT YETKILI,'KASA TESLIM' AS ISLEM,TLTUTAR*-1 AS TOPLAM,0.00 AS INDTUTAR, TLTUTAR*-1 AS NETTOPLAM, KASAACIKFAZLA AS KASAACIKFAZLA 
		FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND ISNULL(SIL,0)=0 AND AKTIFZAMAN<=@AKTIFZAMAN
		UNION ALL
		SELECT NOVAUSER.ADSOYAD AS YETKILI,'ÖDEMELER' AS ISLEM,SUM(TOPLAM)*-1 AS TOPLAM, 0.00,SUM(TOPLAM)*-1 AS TOPLAM,0.00 
		FROM MUH_FIS WITH (NOLOCK) LEFT JOIN NOVAUSER ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE FISTURID IN(2,4) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY NOVAUSER.ADSOYAD
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKISLEMLER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKISLEMLER] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT F.PROJEID, F.USERID, MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,FI.FATISLID AS SATIRKNO, F.FIRMAID,F.FATID,FISHESAPID AS HESAPID, F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET) AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET) ) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,
(FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100)*FI.ADET as  TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON F.PROJEID=MUH_GRUP.GRUPID
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET) AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU,KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI, 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
NULL AS KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 

UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,NULL,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'TUKETIM' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR*-1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
KDEPO.KODU CARIKODU, KDEPO.DEPOADI CARIUNVANI, (DFI.FBFIYAT * DFI.FMIKTAR) * - 1  AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
		  LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   
 UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, (DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))  AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1)*ISNULL(DFI.DKURU,1) AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   

UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR  AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT*ISNULL(DFI.DKURU,1) AS FBFIYAT, (DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)))*ISNULL(DFI.DKURU,1) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT*ISNULL(DFI.DKURU,1) AS BFIYAT,ISNULL(STOK.SALISFIYAT,STOK.MALIYET)  AS BIRIMMALIYET, ISNULL(DFI.BMALIYET,STOK.MALIYET) AS BMALIYET, ISNULL(DFI.FBMALIYET,STOK.MALIYET) AS FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.MALIYET)  AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI, ((DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR)*ISNULL(DFI.DKURU,1)  AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
/*SERVİS FORMU */
 UNION ALL
SELECT DF.PROJEID,DF.USERID,MUH_GRUP.GRUPKODU AS PROJEKODU,MUH_GRUP.GRUPADI AS PROJEADI,1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.FIRMAID, DF.ARACKABULID AS FATID,DF.CARIID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
		 LEFT JOIN MUH_GRUP WITH (NOLOCK) ON DF.PROJEID=MUH_GRUP.GRUPID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MARKETSATIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_MARKETSATIS] (@FIRMAID NVARCHAR(10), @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT TARIH,TUKETIMFIS.SUBEID,TUKETIMFIS.CDEPOID AS DEPOID, DEPO.DEPOADI AS DEPOADI,NOVAUSER.ADSOYAD AS KASIYER, MUH_HESAP.ACIKLAMA AS MUHHESAPADI, 
TUKETIMFIS.ACIKLAMA,ISLEM,SUM(TOPLAM) AS SATISTOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, 
SUM(ACIK) AS ACIKHESAP
, SUM(ISNULL(TICKET1,0)) AS TICKET1 
, SUM(ISNULL(TICKET2,0)) AS TICKET2
, SUM(ISNULL(TICKET3,0)) AS TICKET3
, SUM(ISNULL(TICKET4,0)) AS TICKET4
, SUM(ISNULL(TICKET5,0)) AS TICKET5
FROM TUKETIMFIS WITH (NOLOCK) LEFT JOIN 
MUH_HESAP WITH (NOLOCK) ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID AND TUKETIMFIS.FIRMAID=MUH_HESAP.FIRMAID
LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID AND TUKETIMFIS.FIRMAID=NOVAUSER.FIRMAID
LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID AND TUKETIMFIS.FIRMAID=DEPO.FIRMAID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2
GROUP BY TARIH,ISLEM,NOVAUSER.ADSOYAD,TUKETIMFIS.SUBEID, TUKETIMFIS.CDEPOID, MUH_HESAP.ACIKLAMA,TUKETIMFIS.ACIKLAMA,DEPO.DEPOADI
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPSTOKISLEMLER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE FUNCTION [dbo].[FNCQ_HESAPSTOKISLEMLER] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT 1 AS FTIPI,FI.FATISLID AS SATIRKNO,F.FIRMAID,F.FATID,FISHESAPID AS HESAPID, F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * STOK.SALISFIYAT) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,F.TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND FISHESAPID=@HESAPID AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  
 UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))  AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE DF.HESAPID=@HESAPID AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   

UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE DF.HESAPID=@HESAPID AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
--SERVİS FORMU
 UNION ALL
SELECT 1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.FIRMAID, DF.ARACKABULID AS FATID,DF.CARIID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE DF.CARIID=@HESAPID AND ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_QMUH_HESAPISL2]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE FUNCTION [dbo].[FNCQ_QMUH_HESAPISL2] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + '_' + CAST(F.FISID AS nvarchar(20)) +
	'_' + ISNULL(MK.KODU,'') + '_' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+'.Çeyrek' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+'.Hft' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO, ISNULL(F.TFISID,F.FISID) AS TFISID,
	ISNULL(F.TFISNO,F.FISNO) AS TFISNO,ISNULL(F.TFISTARIH,F.TARIH) AS TFISTARIH,
	ISNULL(F.TFISACIKLAMA,F.ACIKLAMA) AS TFISACIKLAMA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+' '+MGF.ACIKLAMA,M.KODU+' '+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  PROJEID,     
	F.ADD_DATE, F.ADD_USERID,  ISNULL(USER_ADD.ADSOYAD,USER_ADD.KODU) AS EKLEYEN,  F.EDIT_DATE,F.EDIT_USERID,
	ISNULL(USER_UPD.ADSOYAD,USER_UPD.KODU) AS GUNCELLEYEN, F.DEL_DATE ,F.DEL_USERID,
	ISNULL(USER_DEL.ADSOYAD,USER_DEL.KODU) AS SILEN, F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
--Fis Baslik Tek Satir
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

--Fis Baslik Detayli
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID AND MGF.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_ADD WITH (NOLOCK)   ON F.ADD_USERID       = USER_ADD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_UPD WITH (NOLOCK)   ON F.EDIT_USERID        = USER_UPD.NOVAUSERID
 LEFT OUTER JOIN dbo.[NOVAUSER] AS USER_DEL WITH (NOLOCK)   ON F.DEL_USERID        = USER_DEL.NOVAUSERID
 WHERE  M.FIRMAID=@FIRMAID 
 ORDER BY F.TARIH, F.FISID, MK.KODU, ISLEMID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKDETAY] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @STOKID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT 1 AS FTIPI,FISDURUMID,CARI.HESAPID, FI.FATISLID AS SATIRKNO,F.FATID,F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,FI.RENKID,FI.BEDENID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
ISNULL(FI.ACIKLAMA,F.ACIKLAMA) AS ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * STOK.SALISFIYAT) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,F.TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  AND FI.STOKID=@STOKID
UNION ALL
SELECT 1 AS FTIPI,0,NULL, DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU,KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID  
UNION ALL
SELECT 1 AS FTIPI,0,NULL,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR*-1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
NULL AS KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  AND DFI.STOKID=@STOKID  

UNION ALL
SELECT 1 AS FTIPI,0,NULL,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR*-1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
KDEPO.KODU CARIKODU, KDEPO.DEPOADI CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  AND DFI.STOKID=@STOKID   
 UNION ALL
SELECT 1 AS FTIPI,0,DF.HESAPID, DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND  ISNULL(DFI.SILINDI,0)=0 AND DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  AND DFI.STOKID=@STOKID   

UNION ALL
SELECT 1 AS FTIPI,0,DF.HESAPID,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
DFI.INDORAN AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR  AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID   
/*SERVİS FORMU */
 UNION ALL
SELECT 1 AS FTIPI,0,DF.CARIID AS HESAPID, DF.ARACKABULID AS SATIRKNO,DF.ARACKABULID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,NULL AS RENKID,NULL AS BEDENID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_TEST]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO










CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_TEST] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, NULL AS ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, NULL AS ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, TOPLAM AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS INNER JOIN DEPO ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1 AND M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_STOKBAKIYEOZET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_STOKBAKIYEOZET] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @STOKID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  F.TARIH,F.ADD_DATE AS ISLEMTARIH, 'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,FI.RENKID,FI.BEDENID,STOK.KODU AS STOKKODU,FI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND FI.STOKID=@STOKID
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0    AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID 
UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,'TUKETIM' AS ISLEM,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR AS GCADET,DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 
	AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID 

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'DEPOFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
'TUKETIM' AS ISLEM,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR*-1 AS GCADET,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID  
 UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
DF.ISLEM,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  AND DFI.STOKID=@STOKID

UNION ALL
SELECT DF.TARIH,DF.GERCEKTARIH AS ISLEMTARIH,'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,
DEPO.DEPOADI,DF.ISLEM,DFI.STOKID,DFI.RENKID,DFI.BEDENID,STOK.KODU AS STOKKODU,DFI.BARKOD,STOK.ADI AS STOKADI,STOK.BIRIM,DFI.MIKTAR AS GCADET,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID   
    WHERE ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND   DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  AND DFI.STOKID=@STOKID
/*SERVİS FORMU */
 UNION ALL
SELECT DF.TARIH,DF.TARIH AS ISLEMTARIH,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,NULL AS RENKID, NULL AS BEDENID,STOK.KODU AS STOKKODU,STOK.BARKOD, STOK.ADI AS STOKADI,STOK.BIRIM,
DFI.MIKTAR * - 1 AS GCADET,DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2 AND DFI.STOKID=@STOKID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPSTOKISLEMLER2]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[FNCQ_HESAPSTOKISLEMLER2] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT 1 AS FTIPI,FI.FATISLID AS SATIRKNO,F.FIRMAID,F.FATID,FISHESAPID AS HESAPID, F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
'FATURA' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN 'ALIS' ELSE 'SATIS' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * STOK.SALISFIYAT) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,F.TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID
    FROM  FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE FISTURID>50 AND FISHESAPID=@HESAPID AND ISNULL(F.SIL,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND F.FIRMAID=@FIRMAID AND F.TARIH BETWEEN @TARIH AND @TARIH2  
 UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))  AS DNFIYAT,
DFI.BFIYAT,ISNULL(DFI.BMALIYET,STOK.SALISFIYAT) AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * ISNULL(DFI.BMALIYET,STOK.SALISFIYAT) AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.MUHFC,0)=0 AND DF.HESAPID=@HESAPID AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.CDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2   

UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.FIRMAID, DF.DEPOFISID AS FATID,DF.HESAPID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GERCEKTARIH AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN ('TUKETIM','TÜKETİM') THEN 3 ELSE 2 END SAYIMSIRA,
'TUKETIMFIS' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS NFIYAT, DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0)) AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID = SG.SGRUPID LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.MUHFC,0)=0 AND DF.HESAPID=@HESAPID AND ISNULL(DF.SIL,0)=0 AND ISNULL(DFI.SILINDI,0)=0 AND  DF.GDEPOID > 0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2  
/*SERVİS FORMU */
 UNION ALL
SELECT 1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.FIRMAID, DF.ARACKABULID AS FATID,DF.CARIID, DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,'SATIS' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,'SATIS' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
'Servis Formu' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,SG.MUHAISKHESAPID,SG.MUHALISHESAPID,SG.MUHALISIADEHESAPID,SG.MUHISKONTOHESAPID,
SG.MUHSARFHESAPID,SG.MUHSATISHESAPID,SG.MUHSATISIADEHESAPID,SG.MUHSISKHESAPID,SG.MUHVIRMANHESAPID

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUPID= SG.SGRUPID LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE ISNULL(DF.FATID,0)=0 AND DF.CARIID=@HESAPID AND ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND DF.FIRMAID=@FIRMAID AND DF.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_MUHFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE FUNCTION [dbo].[FNCQ_MUHFIS] (@FISID NVARCHAR(10), @TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH=@TARIH AND F.FIRMAID=@FIRMAID 
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH=@TARIH AND F.FIRMAID=@FIRMAID
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DBORC,
			 HI.DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.FISID=@FISID AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH=@TARIH AND F.FIRMAID=@FIRMAID) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPANALIZ_PIVOT2]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_HESAPANALIZ_PIVOT2] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10))  RETURNS  table  AS   
RETURN
 SELECT  TOP 100 PERCENT
 	AC.UNVANI AS ALTCARIUNVANI, CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE,MONTH(ISNULL(F.VADE,F.TARIH)) AS VADEAY, YEAR(ISNULL(F.VADE,F.TARIH)) AS VADEYIL, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,'TL')=''  THEN 'TL' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,'TL')='TL'  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	F.ACIKLAMA AS ACIKLAMA,F.BELGEACIKLAMA,F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, M.KODU AS HESAPKODU,
	M.KODU AS KODU,	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.DOVIZ AS HESAPDOVIZ,
	M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	CASE WHEN CHARINDEX('.',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX('.',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX('.',REVERSE(M.KODU))+1,100)) USTHESAPKODU, HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, FT.FISTURADI, FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  PROJEID, OZELKODID,    
	F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.FISTOPLAM,ODEMEYONTEMI,MG1.GRUPKODU AS ISLEMGRUPKODU1,MG1.GRUPADI AS ISLEMGRUPADI1,
	MG2.GRUPKODU AS ISLEMGRUPKODU2,MG2.GRUPADI AS ISLEMGRUPADI2, MG3.GRUPKODU AS ISLEMGRUPKODU3,
	MG3.GRUPADI AS ISLEMGRUPADI3, MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, MG5.GRUPKODU AS PROJEKODU,     MG5.GRUPADI AS PROJEADI, MG6.GRUPKODU AS DAIREKODU, MG6.GRUPADI AS DAIREADI,MGHESAP1.GRUPADI AS HESAPGRUBU1, MGHESAP2.GRUPADI AS HESAPGRUBU2 FROM 
 
 (SELECT     F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0)
  UNION ALL
--Fis Baslik Tek Satir
   SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL)

 UNION ALL

--Fis Baslik Detayli
  SELECT     F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND ISNULL(F.SIL,0)=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0) AS F  
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID AND M.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID AND MK.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID AND AC.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID 
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
  LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID AND SUBELER.FIRMAID=@FIRMAID
 LEFT OUTER JOIN dbo.MUH_GRUP MG1       WITH (NOLOCK)   ON F.ISLEMGRUPID1      = MG1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG2       WITH (NOLOCK)   ON F.ISLEMGRUPID2      = MG2.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG3       WITH (NOLOCK)   ON F.ISLEMGRUPID3      = MG3.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG5       WITH (NOLOCK)   ON F.PROJEID           = MG5.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MG6       WITH (NOLOCK)   ON F.OZELKODID          = MG6.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP1  WITH (NOLOCK)   ON M.HESAPGRUPID1      = MGHESAP1.GRUPID
 LEFT OUTER JOIN dbo.MUH_GRUP MGHESAP2  WITH (NOLOCK)   ON M.HESAPGRUPID2      = MGHESAP2.GRUPID
 
 ORDER BY F.TARIH, F.FISID, MK.KODU
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_SATIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO









CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_SATIS] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.OZELKOD2='SATIS' AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE F.OZELKOD2='SATIS' AND ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE F.OZELKOD2='SATIS' AND ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM
  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1 AND M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_KASATESLIM_MOBIL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[FNCQ_KASATESLIM_MOBIL] (@FIRMAID INT, @AKTIFZAMAN DATETIME)  RETURNS  table  AS   
RETURN
		SELECT SUBELER.SUBEADI, TUKETIMFIS.YETKILI,'SATIS' AS ISLEM,SUM(ISNULL(TOPLAM,0)) AS TOPLAM, 
		SUM(ISNULL(INDTUTAR,0)) AS INDTUTAR, SUM(ISNULL(TOPLAM,0)-ISNULL(INDTUTAR,0))-SUM(ISNULL(ACIK,0)) AS NETTOPLAM, 0.00 as KASAACIKFAZLA 
		FROM TUKETIMFIS LEFT JOIN SUBELER ON TUKETIMFIS.SUBEID=SUBELER.SUBEID WHERE ISLEM='SATIS' AND TUKETIMFIS.FIRMAID=@FIRMAID AND ISNULL(TUKETIMFIS.SIL,0)=0 AND GERCEKTARIH<=@AKTIFZAMAN
		GROUP BY TUKETIMFIS.YETKILI,SUBELER.SUBEADI
		UNION ALL

		SELECT SUBELER.SUBEADI,MUH_FIS.ADD_USERID,'TAHSILAT' AS ISLEM,SUM(TOPLAM) AS TOPLAM, 0.00,SUM(TOPLAM) AS TOPLAM,0.00 
		FROM MUH_FIS INNER JOIN SUBELER ON MUH_FIS.SUBEID=SUBELER.SUBEID WHERE FISTURID IN(1,3) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY SUBELER.SUBEADI,MUH_FIS.ADD_USERID

		UNION ALL
		SELECT SUBELER.SUBEADI,KASATESLIM.YETKILI,'KASA TESLIM' AS ISLEM,TLTUTAR*-1 AS TOPLAM,0.00 AS INDTUTAR, TLTUTAR*-1 AS NETTOPLAM, KASAACIKFAZLA AS KASAACIKFAZLA 
		FROM KASATESLIM LEFT JOIN SUBELER ON KASATESLIM.SUBEID=SUBELER.SUBEID 
		WHERE KASATESLIM.FIRMAID=@FIRMAID AND ISNULL(KASATESLIM.SIL,0)=0 AND AKTIFZAMAN<=@AKTIFZAMAN

		UNION ALL

		SELECT SUBELER.SUBEADI,MUH_FIS.ADD_USERID,'ÖDEMELER' AS ISLEM,SUM(TOPLAM)*-1 AS TOPLAM, 0.00,SUM(TOPLAM)*-1 AS TOPLAM,0.00 
		FROM MUH_FIS INNER JOIN SUBELER ON MUH_FIS.SUBEID=SUBELER.SUBEID WHERE FISTURID IN(2,4) AND FISDEPOID>0
		AND MUH_FIS.FIRMAID=@FIRMAID AND ISNULL(MUH_FIS.SIL,0)=0 AND MUH_FIS.ADD_DATE<=@AKTIFZAMAN
		GROUP BY SUBELER.SUBEADI,MUH_FIS.ADD_USERID
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_HESAPDETAY_FATURA_YDK_05032022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO











 



--SELECT * FROM  [FNCQ_HESAPDETAY_FATURA] ('2020-01-01', '2021-12-31', '93', '1020002')

CREATE FUNCTION [dbo].[FNCQ_HESAPDETAY_FATURA_YDK_05032022] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	ISNULL(F.DOVIZ,'TL') AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID,
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,F.BELGENO) AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,ISNULL(F.BELGENO,HI.BELGENO) AS BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
    SELECT FIRMAID,NULL AS ENTKAYNAKID, SERVISFORMID*-1 AS FISID, NULL AS ALTCARIID,CARIID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,NETTOPLAM AS BORC,0.00 AS ALACAK, NETTOPLAM AS DBORC,0.00 AS DALACAK,
  'TL' AS DOVIZ, 1 AS KUR, FORMNO AS BELGENO,FORMNO+' Nolu Servis Formu' AS BELGEACIKLAMA,TARIH,FORMNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,5 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FORMNO+' Nolu Servis Formu' AS ACIKLAMA,
  SERVISFORMID AS ISLEMID,NULL AS KDV, NULL AS BABSTUTAR, 'SERVIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'SERVISFORM' AS TABLOADI, SERVISFORMID AS TABLOKAYITID,
  FORMNO+' Nolu Servis Formu' AS FISACIKLAMA,NETTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM SERVISFORM WITH (NOLOCK)
  WHERE ISNULL(FATID,0)=0 AND ABS(NETTOPLAM)>0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND CARIID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,0.00 AS BORC, ISNULL(GTOPLAM,0) AS ALACAK, 0.00 AS DBORC,DTOPLAM AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Alış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Alış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Alış Fatura' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND  FISTURID IN(51,54,61,64,65,67) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')
  UNION ALL
  SELECT FIRMAID,NULL AS ENTKAYNAKID, FATID*-1 AS FISID, ALTCARIID,FISHESAPID AS HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(GTOPLAM,0) AS BORC,0.00 AS ALACAK, DTOPLAM AS DBORC,0.00 AS DALACAK,
  DOVIZ, KUR, FATNO AS BELGENO,FATNO+' Nolu Satış Fatura' AS BELGEACIKLAMA,TARIH,FATNO AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, ADD_DATE, ADD_USERID,FISTURID, FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE,FATNO+' Nolu Satış Fatura' AS ACIKLAMA,
  FATID AS ISLEMID,NULL AS KDV, TOPLAM AS BABSTUTAR, 'FATURA' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'FATURA' AS TABLOADI, FATID AS TABLOKAYITID,
  FATNO+' Nolu Satış Formu' AS FISACIKLAMA,GTOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO FROM FATURA WITH (NOLOCK)
  WHERE FISDURUMID>=0 AND FISTURID IN(52,53,62,63,66) AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%')  
  UNION ALL
  SELECT TUKETIMFIS.FIRMAID,NULL AS ENTKAYNAKID, DEPOFISID*-1 AS FISID, ALTCARIID,HESAPID,
  NULL AS KARSIHESAPID, NULL AS MIKTAR,NULL AS BIRIM,NULL AS BIRIMFIYAT,ISNULL(TOPLAM,0) AS BORC,0.00 AS ALACAK, ACIK AS DBORC,0.00 AS DALACAK,
  DKODU AS DOVIZ, DKURU AS KUR, ISNULL(TUKETIMFIS.ENO,'SATIS') AS BELGENO,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS BELGEACIKLAMA,TARIH, ISNULL(TUKETIMFIS.ENO,'SATIS') AS FISNO,
  NULL AS YEVMNO, NULL AS YEVMTARIH, NULL AS YEVMACIKLAMA, TUKETIMFIS.ADD_DATE, TUKETIMFIS.ADD_USERID,-11 AS FISTURID, 1 AS FISDURUMID, NULL AS YETKIID,
  NULL AS FISHESAPID, ISNULL(DEPO.ACIKSUBEID,CSUBEID) AS SUBEID, NULL AS MASMERID, NULL AS PROJEID, NULL AS OZELKODID, TARIH AS VADE, ISNULL(ACIKLAMA,ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi') AS ACIKLAMA,
  DEPOFISID AS ISLEMID,NULL AS KDV, 0.00 AS BABSTUTAR, 'TUKETIMFIS' AS ENTKAYNAK,NULL AS ENTKAYNAKID, NULL AS SILINDI, NULL AS TEVKIFATKODU,
  NULL AS TEVKIFATYUZDE, NULL AS TVKKDVPAY, NULL AS TVKKDVPAYDA, NULL AS CEKID, NULL AS SSIRA, NULL AS BELGETURU, NULL AS BELGETARIH,
  NULL AS ODENMEYEN, 'ODENMEYEN' AS ODENMEYENALAN, 'TUKETIMFIS' AS TABLOADI, DEPOFISID AS TABLOKAYITID,
  ISNULL(TUKETIMFIS.ENO,'')+' Nolu Satış Fişi' AS FISACIKLAMA,TOPLAM AS FISTOPLAM, NULL AS ODEMEYONTEMI, NULL AS YEVSATIRSIRANO 
  FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND KODU LIKE @KODU+'%') 
  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID 
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE M.FIRMAID=@FIRMAID AND M.KODU LIKE @KODU+'%'
GO
/****** Object:  UserDefinedFunction [dbo].[FNCQ_DAIREDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO








CREATE FUNCTION [dbo].[FNCQ_DAIREDETAY] (@TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @OZELKODID NVARCHAR(20))  RETURNS  table  AS   
RETURN
SELECT  TOP 100 PERCENT
	F.FISID,F.ENTKAYNAKID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN 'B' ELSE 'A' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.MIKTAR, F.BIRIM, F.BIRIMFIYAT,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'')='' THEN ISNULL(F.BELGENO,'')+' Nolu '+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'')+' '+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'')='' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+' '+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+' '+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, OZELKODID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.ENTKAYNAKID,F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND HI.HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND ISNULL(HI.OZELKODID,F.OZELKODID)=@OZELKODID)
UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID, F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT,
              CASE WHEN FT.ALANTIPI='BORC'   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI='BORC'   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI='ALACAK' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,'ODENMEYEN' AS ODENMEYENALANI,'MUH_FIS' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) 
 AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND ISNULL(HI.OZELKODID,F.OZELKODID)=@OZELKODID) 
 UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,  F.ENTKAYNAKID, F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID,HI.MIKTAR, HI.BIRIM, HI.BIRIMFIYAT, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             HI.DALACAK AS DBORC,
			 HI.DBORC AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID, ISNULL(HI.OZELKODID,F.OZELKODID)           AS OZELKODID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, 'ODENMEYEN2' AS ODENMEYENALANI,'MUH_HESAPISL' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 
  AND F.TARIH BETWEEN @TARIH AND @TARIH2 AND F.FIRMAID=@FIRMAID AND F.FISHESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND ISNULL(HI.OZELKODID,F.OZELKODID)=@OZELKODID)
) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1
GO
/****** Object:  UserDefinedFunction [dbo].[fn_RoundBanker]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE FUNCTION [dbo].[fn_RoundBanker]  
( @NumToRound money, 
  @Digits Int
) RETURNS money 

WITH SCHEMABINDING
as

BEGIN

  set @NumToRound = @NumToRound * power( 10, @Digits ) 

  return case 

           when @NumToRound = floor( @NumToRound ) 
           then @NumToRound 
           
           else case sign( ceiling( @NumToRound ) - 2 * @NumToRound + floor( @NumToRound ) ) 
                  
                  when 1 
                  then floor( @NumToRound ) 
                  
                  when -1 
                  then ceiling( @NumToRound ) 
                  
                  else 2 * round( @NumToRound / 2, 0 ) 
                  
                end 

         end / power( 10, @Digits ) 

END
GO
/****** Object:  Table [dbo].[ADATFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADATFIS](
	[ADATFISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[FAIZORANI] [float] NULL,
	[ISLEMGRUPID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[KURTIPI] [nvarchar](10) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[MUHFC] [int] NULL,
	[UUID] [uniqueidentifier] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_ADATFIS] PRIMARY KEY CLUSTERED 
(
	[ADATFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADATISLEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADATISLEM](
	[ADATISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[ADATFISID] [int] NOT NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[BAKIYE] [float] NULL,
	[DBAKIYE] [float] NULL,
	[FAIZ] [float] NULL,
	[DFAIZ] [float] NULL,
	[TBAKIYE] [float] NULL,
	[TDBAKIYE] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[FISID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
 CONSTRAINT [PK_ADATISLEM] PRIMARY KEY CLUSTERED 
(
	[ADATISLEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADISYON59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADISYON59](
	[FISCOUNTER] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPKODU] [nvarchar](15) NULL,
	[MASANO] [nvarchar](40) NULL,
	[TARIH] [datetime] NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[FISNO] [int] NULL,
	[ODERNO] [nvarchar](50) NULL,
	[ADISYONNO] [nvarchar](15) NULL,
	[GARSONKODU] [nvarchar](15) NULL,
	[YETKILIKODU] [nvarchar](15) NULL,
	[TUR] [nvarchar](10) NULL,
	[MUSTERIKODU] [nvarchar](30) NULL,
	[MUSTERIADI] [nvarchar](50) NULL,
	[MUSTERITELEFON] [nvarchar](20) NULL,
	[MUSTERIBAKIYE] [float] NULL,
	[INDORAN] [float] NULL,
	[SERVISORAN] [float] NULL,
	[SERVISTUTAR] [float] NULL,
	[TOPLAM] [float] NULL,
	[FUNVANI] [nvarchar](50) NULL,
	[FADRESI1] [nvarchar](250) NULL,
	[FADRESI2] [nvarchar](150) NULL,
	[FVD] [nvarchar](25) NULL,
	[FVDNO] [nvarchar](25) NULL,
	[KDV] [float] NULL,
	[MATRAH] [float] NULL,
	[ONAKIT] [float] NULL,
	[OKK] [float] NULL,
	[OTICKET] [float] NULL,
	[OACIK] [float] NULL,
	[YTOPLAM] [float] NULL,
	[ITOPLAM] [float] NULL,
	[FYAZIYLA] [nvarchar](80) NULL,
	[KISI] [int] NULL,
	[MODANO] [nvarchar](15) NULL,
	[MKNO] [float] NULL,
	[FISLI] [bit] NULL,
	[STOPLAM] [float] NULL,
	[YAZCOUNT] [int] NULL,
	[KKTURU] [nvarchar](50) NULL,
	[TICKETTURU] [nvarchar](50) NULL,
	[DIRTY] [int] NULL,
	[DTURU] [nvarchar](50) NULL,
	[DTOPLAM] [float] NULL,
	[FKISINO] [nvarchar](50) NULL,
	[OTICKET2] [float] NULL,
	[OTICKET3] [float] NULL,
	[OTICKET4] [float] NULL,
	[OTICKET5] [float] NULL,
	[OTICKET6] [float] NULL,
	[VPARA] [float] NULL,
	[MUSTERIID] [int] NULL,
	[MODAADI] [nvarchar](50) NULL,
	[DOVIZTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[KASIYER] [nvarchar](15) NULL,
	[SECINDID] [int] NULL,
	[INDSEBEP] [nvarchar](50) NULL,
	[PBAKIYE] [float] NULL,
	[MID] [int] NULL,
	[KALANKREDI] [float] NULL,
	[ODENMEZTOPLAM] [float] NULL,
	[MASASTATU] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[MARS] [int] NULL,
	[MARSSAATI] [datetime] NULL,
	[ODERSERINO] [nvarchar](50) NULL,
	[CALLSIPARISID] [int] NULL,
	[MUSKARTNO] [nvarchar](20) NULL,
	[SIL] [smallint] NULL,
	[SSAATI] [datetime] NULL,
	[MCOUNTER] [int] NULL,
	[ILKMASANO] [nvarchar](40) NULL,
	[OKCUNQNUMBER] [nvarchar](30) NULL,
	[OKCFISNO] [nvarchar](20) NULL,
	[OKCSTATU] [nvarchar](30) NULL,
	[DEPID] [int] NULL,
	[GARSONID] [int] NULL,
	[KASIYERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADSODEME]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADSODEME](
	[ADSODEMEID] [int] IDENTITY(1,1) NOT NULL,
	[FISCOUNTER] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL,
 CONSTRAINT [PK_ADSODEME] PRIMARY KEY CLUSTERED 
(
	[ADSODEMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADSODEME59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADSODEME59](
	[ADSODEMEID] [int] NOT NULL,
	[FISCOUNTER] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADSSATIR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADSSATIR59](
	[COUNTER] [int] NOT NULL,
	[FISCOUNTER] [int] NULL,
	[ILKFISCOUNTER] [int] NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ADET] [float] NULL,
	[BIRIMFIYAT] [float] NULL,
	[TUTAR] [float] NULL,
	[YAZ] [bit] NULL,
	[GARSONKODU] [nvarchar](5) NULL,
	[BARKOD] [nvarchar](50) NULL,
	[H] [int] NULL,
	[SIP] [bit] NULL,
	[INDORAN] [float] NULL,
	[INDID] [nvarchar](100) NULL,
	[GGRUP] [nvarchar](5) NULL,
	[HHOUR] [bit] NULL,
	[ZAYII] [bit] NULL,
	[IADE] [bit] NULL,
	[BEKLET] [int] NULL,
	[SAAT] [datetime] NULL,
	[GONDERILDI] [bit] NULL,
	[MALIYET] [float] NULL,
	[SERVIS] [int] NULL,
	[SIPADET] [float] NULL,
	[BUCUKLU] [bit] NULL,
	[IKRAM] [bit] NULL,
	[CALLSIPARISID] [int] NULL,
	[EKFIYAT] [float] NULL,
	[DKODU] [nvarchar](10) NULL,
	[DKURU] [float] NULL,
	[MENUSTOKID] [int] NULL,
	[ODENENADET] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[ADSSATIRUUID] [uniqueidentifier] NULL,
	[SIL] [smallint] NULL,
	[GARSONID] [int] NULL,
	[SEC] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ADSSATIRILAVE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ADSSATIRILAVE](
	[ADSSATIRILAVEID] [int] IDENTITY(1,1) NOT NULL,
	[FISCOUNTER] [int] NULL,
	[ADSSATIRUUID] [uniqueidentifier] NULL,
	[STOKID] [int] NULL,
	[EKOZELLIKID] [int] NULL,
	[YSEKOZELLIKID] [nvarchar](50) NULL,
	[RECETEID] [int] NULL,
 CONSTRAINT [PK_ADSSATIRILAVE] PRIMARY KEY CLUSTERED 
(
	[ADSSATIRILAVEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AIDATFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AIDATFIS](
	[AIDATFISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[GELIRHESABI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[TARIH] [smalldatetime] NULL,
	[TAKSITSAYISI] [int] NULL,
	[FIYATTIPI] [smallint] NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DOVIZKURU] [float] NULL,
	[BELGENO] [nvarchar](20) NULL,
	[VADEGUN] [int] NULL,
 CONSTRAINT [PK_AIDATFIS] PRIMARY KEY CLUSTERED 
(
	[AIDATFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AIDATFIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AIDATFIS59](
	[AIDATFISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[GELIRHESABI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BELGENO] [nvarchar](20) NULL,
	[TARIH] [smalldatetime] NULL,
	[VADEGUN] [int] NULL,
	[TAKSITSAYISI] [int] NULL,
	[FIYATTIPI] [smallint] NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[DOVIZKURU] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AIDATISLEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AIDATISLEM](
	[AIDATISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[AIDATFISID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[MHESAPID] [int] NULL,
	[MALTCARIID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[FISID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[EMLAKTIPID] [int] NULL,
	[VADESI] [smalldatetime] NULL,
 CONSTRAINT [PK_AIDATISLEM] PRIMARY KEY CLUSTERED 
(
	[AIDATISLEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AIDATISLEM_SIL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AIDATISLEM_SIL](
	[AIDATISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[AIDATFISID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[MHESAPID] [int] NULL,
	[MALTCARIID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[VADESI] [smalldatetime] NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[FISID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[DELDATE] [datetime] NULL,
	[FISUUID] [uniqueidentifier] NULL,
 CONSTRAINT [PK_AIDATISLEM_SIL] PRIMARY KEY CLUSTERED 
(
	[AIDATISLEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AIDATISLEM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AIDATISLEM59](
	[AIDATISLEMID] [int] NOT NULL,
	[AIDATFISID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[MHESAPID] [int] NULL,
	[MALTCARIID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[VADESI] [smalldatetime] NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[FISID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[FISUUID] [uniqueidentifier] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AJANDA59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AJANDA59](
	[ID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[PARENTID] [int] NULL,
	[TYPE] [int] NULL,
	[START] [smalldatetime] NULL,
	[FINISH] [smalldatetime] NULL,
	[OPTIONS] [int] NULL,
	[CAPTION] [nvarchar](255) NULL,
	[RECURRENCEINDEX] [int] NULL,
	[LOCATION] [nvarchar](255) NULL,
	[MESSAGE] [nvarchar](255) NULL,
	[REMINDERDATE] [smalldatetime] NULL,
	[REMINDERMINUTES] [int] NULL,
	[STATE] [int] NULL,
	[LABELCOLOR] [int] NULL,
	[ACTUALSTART] [smalldatetime] NULL,
	[ACTUALFINISH] [smalldatetime] NULL,
	[SYNCIDFFIELD] [nvarchar](255) NULL,
	[RESOURCEID] [int] NULL,
	[RECUREENCEINFO] [ntext] NULL,
	[HKIMLIKID] [int] NULL,
	[SPAFISID] [int] NULL,
	[ISLEMID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NULL,
	[BIRIMFIYAT] [float] NULL,
	[INDORAN] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SPAGOREVLIID] [int] NULL,
	[SPAMEKANID] [int] NULL,
	[KOMORAN] [float] NULL,
	[KOMTUTAR] [float] NULL,
	[KOMDOVIZ] [nvarchar](5) NULL,
	[SATISTARIHI] [smalldatetime] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[SURE] [int] NULL,
	[RESIM] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AJANDAKAYNAK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AJANDAKAYNAK](
	[RESOURCEID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[REOSURCECOLOR] [int] NULL,
	[RESOURCENAME] [nvarchar](255) NULL,
	[RESOURCEIMAGEINDEX] [int] NULL,
	[AKTIF] [int] NULL,
	[KOMORAN] [float] NULL,
 CONSTRAINT [PK_AJANDAKAYNAK] PRIMARY KEY CLUSTERED 
(
	[RESOURCEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_AJANDAKAYNAK] UNIQUE NONCLUSTERED 
(
	[RESOURCEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AJANDAKAYNAK59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AJANDAKAYNAK59](
	[RESOURCEID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[REOSURCECOLOR] [int] NULL,
	[RESOURCENAME] [nvarchar](255) NULL,
	[RESOURCEIMAGEINDEX] [int] NULL,
	[AKTIF] [int] NULL,
	[KOMORAN] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKADONEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKADONEM](
	[BANKADONEMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[FAIZHESAPID300] [int] NULL,
	[FAIZHESAPID400] [int] NULL,
	[FAIZGIDERHESAPID] [int] NULL,
	[KKDFHESAPID] [int] NULL,
	[BSMVHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_BANKADONEM] PRIMARY KEY CLUSTERED 
(
	[BANKADONEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKAEXTRETANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKAEXTRETANIM](
	[BANKAEXTRETANIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BANKAID] [int] NULL,
	[SATIRBASLANGIC] [int] NULL,
	[TARIH] [int] NULL,
	[ACIKLAMA] [int] NULL,
	[BELGENO] [int] NULL,
	[TUTAR] [int] NULL,
	[AD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_BANKAEXTRETANIM] PRIMARY KEY CLUSTERED 
(
	[BANKAEXTRETANIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKAKREDI59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKAKREDI59](
	[BANKAKREDIID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KREDITARIHI] [smalldatetime] NULL,
	[BITISTARIHI] [smalldatetime] NULL,
	[KREDITURID] [int] NULL,
	[KREDITUTARI] [float] NULL,
	[FAIZORANI] [float] NULL,
	[KKDFORANI] [float] NULL,
	[BSMVORANI] [float] NULL,
	[TAKSITSAYISI] [float] NULL,
	[TAKSITTUTARI] [float] NULL,
	[GERIODEMETUTARI] [float] NULL,
	[AYLIKMALIYET] [float] NULL,
	[YILLIKMALIYET] [float] NULL,
	[BANKAID] [int] NULL,
	[ANAPARAHESAPID] [int] NULL,
	[FAIZHESAPID] [int] NULL,
	[KKDFHESAPID] [int] NULL,
	[BSMVHESAPID] [int] NULL,
	[MUHFISID] [int] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[FISIVAR] [bit] NULL,
	[GELECEKGIDERID] [int] NULL,
	[GELECEKGIDERID2] [int] NULL,
	[GELECEKANAPARAHESAPID] [int] NULL,
	[GIDERHESAPID] [int] NULL,
	[FAIZHESAPID2] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKAKREDIDETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKAKREDIDETAY59](
	[BANKAKREDIDETAYID] [int] NOT NULL,
	[BANKAKREDIID] [int] NULL,
	[TAKSITNO] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TAKSITTUTARI] [float] NULL,
	[ANAPARA] [float] NULL,
	[FAIZ] [float] NULL,
	[KKDF] [float] NULL,
	[BSMV] [float] NULL,
	[KALANANAPARA] [float] NULL,
	[MUHFISID] [int] NULL,
	[ODENENTUTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BANKALIST]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BANKALIST](
	[BANKAKODU] [nvarchar](255) NULL,
	[KISAADI] [nvarchar](255) NULL,
	[BANKAADI] [nvarchar](255) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKOD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKOD](
	[BARKODID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[MARKA] [int] NULL,
	[MARKAID] [int] NULL,
	[BIRIMID] [int] NULL,
	[MOTORNO] [nvarchar](50) NULL,
	[SASINO] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](20) NULL,
	[EKKODU] [nvarchar](20) NULL,
	[KTARIHI] [datetime] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[DMIKTAR] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FIYATI] [float] NULL,
	[BMIKTAR] [float] NULL,
	[SIL] [smallint] NULL,
	[OLDSTOKID] [int] NULL,
 CONSTRAINT [PK_BARKOD] PRIMARY KEY CLUSTERED 
(
	[BARKODID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IXUQe_FIRMAID_BARKOD] UNIQUE NONCLUSTERED 
(
	[FIRMAID] ASC,
	[BARKOD] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKOD_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKOD_TEMP](
	[BARKODID] [int] NOT NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[MARKA] [int] NULL,
	[BIRIM_OLD] [int] NULL,
	[MARKAID] [int] NULL,
	[BIRIMID] [int] NULL,
	[MOTORNO] [nvarchar](50) NULL,
	[SASINO] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](20) NULL,
	[EKKODU] [nvarchar](20) NULL,
	[KTARIHI] [smalldatetime] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[DMIKTAR] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FIYATI] [float] NULL,
	[BMIKTAR] [float] NULL,
	[STOKID_V6] [int] NULL,
	[FIRMAID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKOD59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKOD59](
	[BARKODID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[MARKA] [int] NULL,
	[MARKAID] [int] NULL,
	[BIRIMID] [int] NULL,
	[MOTORNO] [nvarchar](50) NULL,
	[SASINO] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](20) NULL,
	[EKKODU] [nvarchar](20) NULL,
	[KTARIHI] [datetime] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[DMIKTAR] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FIYATI] [float] NULL,
	[BMIKTAR] [float] NULL,
	[SIL] [smallint] NULL,
	[OLDSTOKID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKODADET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKODADET](
	[BARKODADETID] [int] IDENTITY(1,1) NOT NULL,
	[BADET] [int] NULL,
	[BASILDI] [bit] NULL,
	[DEPOFISID] [int] NULL,
	[DEPOID] [int] NULL,
	[STOKID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[BIRIM] [nvarchar](20) NULL,
	[SACIKLAMA] [nvarchar](50) NULL,
	[FIYATI] [float] NULL,
	[BRENKID] [int] NULL,
	[BBEDENID] [int] NULL,
 CONSTRAINT [PK_BARKODADET] PRIMARY KEY CLUSTERED 
(
	[BARKODADETID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_BARKODADET] UNIQUE NONCLUSTERED 
(
	[BARKODADETID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKODW]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKODW](
	[BARKODID] [int] NOT NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[MARKA] [int] NULL,
	[BIRIM_OLD] [int] NULL,
	[MARKAID] [int] NULL,
	[BIRIMID] [int] NULL,
	[MOTORNO] [nvarchar](50) NULL,
	[SASINO] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](20) NULL,
	[EKKODU] [nvarchar](20) NULL,
	[KTARIHI] [smalldatetime] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[DMIKTAR] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FIYATI] [float] NULL,
	[BMIKTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BARKODX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BARKODX](
	[BARKODID] [int] NOT NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[MARKA] [int] NULL,
	[BIRIM_OLD] [int] NULL,
	[MARKAID] [int] NULL,
	[BIRIMID] [int] NULL,
	[MOTORNO] [nvarchar](50) NULL,
	[SASINO] [nvarchar](50) NULL,
	[PLAKA] [nvarchar](20) NULL,
	[EKKODU] [nvarchar](20) NULL,
	[KTARIHI] [smalldatetime] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[DMIKTAR] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FIYATI] [float] NULL,
	[BMIKTAR] [float] NULL,
	[OLDSTOKID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BAYI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BAYI](
	[BAYIID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BAYI] [nvarchar](50) NULL,
	[BKOMORAN] [float] NULL,
 CONSTRAINT [PK_BAYI] PRIMARY KEY CLUSTERED 
(
	[BAYIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_BAYI] UNIQUE NONCLUSTERED 
(
	[BAYIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BEDENLER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BEDENLER](
	[BEDENLERID] [int] IDENTITY(1000,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BEDEN] [nvarchar](20) NULL,
	[BEDENACIKLAMA] [nvarchar](100) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDBEDENLERID] [int] NULL,
 CONSTRAINT [PK_BEDENLER] PRIMARY KEY CLUSTERED 
(
	[BEDENLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BEDENLER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BEDENLER59](
	[BEDENLERID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BEDEN] [nvarchar](20) NULL,
	[BEDENACIKLAMA] [nvarchar](100) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDBEDENLERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BELGELER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BELGELER](
	[BELGELERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TABLO] [nvarchar](30) NULL,
	[TABLOID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[BELGEADI] [nvarchar](80) NULL,
	[BELGETURU] [nvarchar](10) NULL,
	[BELGEGUID] [uniqueidentifier] NULL,
	[BELGEACIKLAMA] [nvarchar](100) NULL,
	[SILMEZAMANI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ZIBLIDOSYA] [bit] NULL,
	[ZIPLIDOSYA] [bit] NULL,
 CONSTRAINT [PK_BELGELER] PRIMARY KEY CLUSTERED 
(
	[BELGELERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[BELGELER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BELGELER59](
	[BELGELERID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TABLO] [nvarchar](30) NULL,
	[TABLOID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[BELGEADI] [nvarchar](80) NULL,
	[BELGETURU] [nvarchar](10) NULL,
	[BELGEGUID] [uniqueidentifier] NULL,
	[BELGEACIKLAMA] [nvarchar](100) NULL,
	[SILMEZAMANI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ZIPLIDOSYA] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CALLSIPARIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CALLSIPARIS](
	[CALLSIPARISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[CIKISSAATI] [datetime] NULL,
	[CARIID] [int] NULL,
	[TEL] [nvarchar](20) NULL,
	[KODU] [nvarchar](20) NULL,
	[BOLGE] [nvarchar](30) NULL,
	[PAKETDURUMU] [nvarchar](30) NULL,
	[FISCOUNTER] [int] NULL,
 CONSTRAINT [PK_CALLSIPARIS] PRIMARY KEY CLUSTERED 
(
	[CALLSIPARISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_CALLSIPARIS] UNIQUE NONCLUSTERED 
(
	[CALLSIPARISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARI_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARI_TEMP](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[UNVANI] [nvarchar](250) NULL,
	[VD] [nvarchar](50) NULL,
	[VDNO] [nvarchar](50) NULL,
 CONSTRAINT [PK_CARI_TEMP] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIBILET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIBILET](
	[CARIBILETID] [int] IDENTITY(1,1) NOT NULL,
	[CARIID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[BILETNO] [nvarchar](50) NULL,
	[INDORAN] [float] NULL,
	[KULLANILDI] [bit] NULL,
	[KULLANIMTARIH] [smalldatetime] NULL,
	[FISCOUNTER] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_CARIBILET] PRIMARY KEY CLUSTERED 
(
	[CARIBILETID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIBILET59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIBILET59](
	[CARIBILETID] [int] NOT NULL,
	[CARIID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[BILETNO] [nvarchar](50) NULL,
	[INDORAN] [float] NULL,
	[KULLANILDI] [bit] NULL,
	[KULLANIMTARIH] [smalldatetime] NULL,
	[FISCOUNTER] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIDAIRE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIDAIRE](
	[CARIDAIREID] [int] IDENTITY(1,1) NOT NULL,
	[HESAPID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[AKTIF] [bit] NULL,
 CONSTRAINT [PK_CARIDAIRE] PRIMARY KEY CLUSTERED 
(
	[CARIDAIREID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIEKKART]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIEKKART](
	[CARIEKKARTID] [int] IDENTITY(1,1) NOT NULL,
	[CARIID] [int] NULL,
	[KARTNO] [nvarchar](20) NULL,
	[BASLANGIC] [smalldatetime] NULL,
	[BITIS] [smalldatetime] NULL,
	[ODANO] [nvarchar](10) NULL,
	[AKTIF] [bit] NULL,
 CONSTRAINT [PK_CARIEKKART] PRIMARY KEY CLUSTERED 
(
	[CARIEKKARTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIEKKART59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIEKKART59](
	[CARIEKKARTID] [int] NOT NULL,
	[CARIID] [int] NULL,
	[KARTNO] [nvarchar](20) NULL,
	[BASLANGIC] [smalldatetime] NULL,
	[BITIS] [smalldatetime] NULL,
	[ODANO] [nvarchar](10) NULL,
	[AKTIF] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CARIKART59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CARIKART59](
	[CARIID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[KODU] [nvarchar](100) NULL,
	[UNVANI] [nvarchar](255) NULL,
	[ADRES1] [nvarchar](100) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](100) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](100) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[TEL1] [nvarchar](50) NULL,
	[TEL2] [nvarchar](50) NULL,
	[FAX] [nvarchar](50) NULL,
	[GSM] [nvarchar](20) NULL,
	[STDIND] [float] NULL,
	[VADEGUN] [int] NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISIND] [float] NULL,
	[TIP] [nvarchar](15) NULL,
	[ADISOYADI] [nvarchar](25) NULL,
	[DYERI] [nvarchar](15) NULL,
	[BABAADI] [nvarchar](15) NULL,
	[DTARIHI] [datetime] NULL,
	[TCKIMLIKNO] [nvarchar](12) NULL,
	[CINSIYETI] [nvarchar](1) NULL,
	[YAZISMA] [nvarchar](2) NULL,
	[UYENOT] [nvarchar](15) NULL,
	[CEPTEL] [nvarchar](14) NULL,
	[GRUBU] [nvarchar](10) NULL,
	[MESLEK] [nvarchar](20) NULL,
	[KARTNO] [nvarchar](25) NULL,
	[STATUSU] [nvarchar](15) NULL,
	[HESAPID] [int] NULL,
	[NOTLAR] [nvarchar](500) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[CGRUBU] [nvarchar](15) NULL,
	[KLIMITI] [float] NULL,
	[GKODU] [nvarchar](10) NULL,
	[KARTTURU] [nvarchar](10) NULL,
	[INDORAN] [float] NULL,
	[ASIMORAN] [float] NULL,
	[KSKODU] [nvarchar](100) NULL,
	[GRUPID] [int] NULL,
	[SUBEID] [int] NULL,
	[SKODU] [nvarchar](50) NULL,
	[HESAPNO] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[IBANKODU] [nvarchar](50) NULL,
	[ADRES3] [nvarchar](100) NULL,
	[BANKAADI] [nvarchar](50) NULL,
	[FIRMA] [nvarchar](15) NULL,
	[ISADRES] [nvarchar](55) NULL,
	[ISTEL] [nvarchar](14) NULL,
	[ISTEL2] [nvarchar](14) NULL,
	[EVADRES] [nvarchar](40) NULL,
	[EVADRES2] [nvarchar](40) NULL,
	[EVPKODU] [nvarchar](50) NULL,
	[EVTEL] [nvarchar](14) NULL,
	[EVFAX] [nvarchar](14) NULL,
	[GOREVI] [nvarchar](15) NULL,
	[ARACTEL] [nvarchar](14) NULL,
	[ESIADI] [nvarchar](25) NULL,
	[COCUK1] [nvarchar](15) NULL,
	[COCUK2] [nvarchar](15) NULL,
	[EVLILIKT] [datetime] NULL,
	[SAC] [nvarchar](10) NULL,
	[BOY] [int] NULL,
	[KILO] [int] NULL,
	[HASTALIKLAR] [nvarchar](100) NULL,
	[KANGRUBU] [nvarchar](7) NULL,
	[UYENO] [nvarchar](15) NULL,
	[UYEBASLAMA] [datetime] NULL,
	[UYEBITIS] [datetime] NULL,
	[UYELIKTIPI] [nvarchar](15) NULL,
	[UYEKISITIPI] [nvarchar](10) NULL,
	[ACILDURUM] [nvarchar](100) NULL,
	[REF1] [nvarchar](50) NULL,
	[REF2] [nvarchar](50) NULL,
	[SATISTEMSIL] [nvarchar](15) NULL,
	[SATISTID] [int] NULL,
	[EKTUTAR1] [float] NULL,
	[EKTUTAR2] [float] NULL,
	[EKTUTAR3] [float] NULL,
	[EKTUTAR4] [float] NULL,
	[EKTARIH1] [datetime] NULL,
	[EKTARIH2] [datetime] NULL,
	[EKTARIH3] [datetime] NULL,
	[SIL] [smallint] NULL,
	[RESIM] [image] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKDURUM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKDURUM](
	[CEKDURUMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [datetime] NULL,
	[CEKID] [int] NULL,
	[FISID] [int] NULL,
	[CEKFISTURID] [int] NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[CEKHESAPID] [int] NULL,
	[CEKALTCARIID] [int] NULL,
 CONSTRAINT [PK_CEKDURUM] PRIMARY KEY CLUSTERED 
(
	[CEKDURUMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKKARNEDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKKARNEDETAY](
	[CEKKARNEDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[CEKKARNESIID] [int] NULL,
	[SERI] [nvarchar](5) NULL,
	[CEKNO] [nvarchar](10) NULL,
	[CEKDURUMID] [int] NULL,
	[CEKID] [int] NULL,
	[SIL] [smallint] NULL,
	[IPTALIADE] [smallint] NULL,
	[IADETARIHI] [smalldatetime] NULL,
	[BANKAYAIADE] [bit] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
 CONSTRAINT [PK_CEKKARNEDETAY] PRIMARY KEY CLUSTERED 
(
	[CEKKARNEDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKKARNEDETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKKARNEDETAY59](
	[CEKKARNEDETAYID] [int] NOT NULL,
	[CEKKARNESIID] [int] NULL,
	[SERI] [nvarchar](5) NULL,
	[CEKNO] [nvarchar](10) NULL,
	[CEKDURUMID] [int] NULL,
	[CEKID] [int] NULL,
	[SIL] [smallint] NULL,
	[IPTALIADE] [smallint] NULL,
	[IADETARIHI] [smalldatetime] NULL,
	[BANKAYAIADE] [bit] NULL,
	[ACIKLAMA] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKKARNESI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKKARNESI](
	[CEKKARNESIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BANKAHESAPID] [int] NULL,
	[BANKAID] [int] NULL,
	[BANKASUBE] [nvarchar](30) NULL,
	[TESLIMTARIHI] [smalldatetime] NULL,
	[BASIMTARIHI] [smalldatetime] NULL,
	[SERI] [nvarchar](5) NULL,
	[MIKTAR] [int] NULL,
	[ILKNO] [nvarchar](10) NULL,
	[SONNO] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_CEKKARNESI] PRIMARY KEY CLUSTERED 
(
	[CEKKARNESIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKKARNESI59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKKARNESI59](
	[CEKKARNESIID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BANKAHESAPID] [int] NULL,
	[BANKAID] [int] NULL,
	[BANKASUBE] [nvarchar](30) NULL,
	[TESLIMTARIHI] [smalldatetime] NULL,
	[BASIMTARIHI] [smalldatetime] NULL,
	[SERI] [nvarchar](5) NULL,
	[MIKTAR] [int] NULL,
	[ILKNO] [nvarchar](10) NULL,
	[SONNO] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CEKLER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CEKLER59](
	[CEKID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[CEKTURID] [int] NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[TURU] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[BANKA] [nvarchar](50) NULL,
	[SUBE] [nvarchar](50) NULL,
	[HESAPNO] [nvarchar](50) NULL,
	[CEKNO] [nvarchar](50) NULL,
	[ILKSAHIBI] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](50) NULL,
	[NOTLAR] [nvarchar](250) NULL,
	[DTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[TLTUTAR] [float] NULL,
	[SILINDI] [int] NULL,
	[TESLIMEDEN] [nvarchar](50) NULL,
	[TESLIMALAN] [nvarchar](50) NULL,
	[CEKDURUMID] [smallint] NULL,
	[DURUMID] [smallint] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[CEKALTCARIID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[ILKFISID] [int] NULL,
	[SONFISID] [int] NULL,
	[CEKHESAPID] [int] NULL,
	[SONHESAPID] [int] NULL,
	[SONALTCARIID] [int] NULL,
	[SONCEKHESAPID] [int] NULL,
	[SONCEKALTCARIID] [int] NULL,
	[SONCEKDURUMID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[CEKNOID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CONFIG]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CONFIG](
	[CONFIGID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROGNAME] [nvarchar](50) NULL,
	[SECTIONSTR] [nvarchar](200) NULL,
	[KEYNAME] [nvarchar](200) NULL,
	[VALUESTR] [nvarchar](200) NULL,
	[TYPES] [int] NULL,
	[ALTERNATIVES] [nvarchar](255) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
 CONSTRAINT [PK_CONFIG] PRIMARY KEY CLUSTERED 
(
	[CONFIGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_CONFIG] UNIQUE NONCLUSTERED 
(
	[CONFIGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[CONFIG59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CONFIG59](
	[CONFIGID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROGNAME] [nvarchar](50) NULL,
	[SECTIONSTR] [nvarchar](200) NULL,
	[KEYNAME] [nvarchar](200) NULL,
	[VALUESTR] [nvarchar](200) NULL,
	[TYPES] [int] NULL,
	[ALTERNATIVES] [nvarchar](255) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DENEMETABLO]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DENEMETABLO](
	[DENEMEID] [int] IDENTITY(1,1) NOT NULL,
	[AD] [nvarchar](50) NULL,
	[SOYAD] [nvarchar](50) NULL,
 CONSTRAINT [PK_DENEMETABLO] PRIMARY KEY CLUSTERED 
(
	[DENEMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPO59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPO59](
	[DEPOID] [int] NOT NULL,
	[DEPOADI] [nvarchar](40) NOT NULL,
	[ANADEPO] [bit] NULL,
	[DEPOMUH] [int] NULL,
	[SKODU] [nvarchar](10) NULL,
	[KODU] [nvarchar](5) NOT NULL,
	[MUHKODU] [nvarchar](25) NULL,
	[MUHKODUSARF] [nvarchar](25) NULL,
	[MASMERID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[MASMERID2] [int] NULL,
	[MIKTARKONTROL] [bit] NULL,
	[SIL] [smallint] NULL,
	[SUBEFIYATKULLAN] [bit] NULL,
	[MERKEZDEPOID] [int] NULL,
	[NSATISHESAPID] [int] NULL,
	[KKSATISHESAPID] [int] NULL,
	[ACIKHESAPID] [int] NULL,
	[ACIKSUBEID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[OLDDEPOID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOFIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOFIS59](
	[DEPOFISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[TARIH] [datetime] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[USERID] [int] NULL,
	[ISLEM] [nvarchar](10) NULL,
	[ENO] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[GDEPOID] [int] NULL,
	[CDEPOID] [int] NULL,
	[TADET] [float] NULL,
	[TTUTAR] [float] NULL,
	[GSKODU] [nvarchar](10) NULL,
	[CSKODU] [nvarchar](10) NULL,
	[URUNFISID] [int] NULL,
	[URETILDI] [bit] NULL,
	[LOGOAKTAR] [int] NULL,
	[LOGODANGELDI] [bit] NULL,
	[ISLEMDETAY] [nvarchar](15) NULL,
	[SDEPART] [nvarchar](15) NULL,
	[ONAY] [bit] NULL,
	[MUHFISID] [int] NULL,
	[DURUM] [int] NULL,
	[CSUBEID] [int] NULL,
	[EK2] [nvarchar](30) NULL,
	[EK1] [nvarchar](30) NULL,
	[MUHFC] [int] NULL,
	[SBOLUMID] [int] NULL,
	[BOLUM] [nvarchar](10) NULL,
	[BARKODBASILDI] [bit] NULL,
	[BMALIYET] [float] NULL,
	[MUHASEBELESTIRME] [bit] NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[EK2GOREV] [nvarchar](50) NULL,
	[EK2YETKI] [nvarchar](50) NULL,
	[GSUBEID] [int] NULL,
	[GERCEKTARIH] [datetime] NULL,
	[SIL] [smallint] NULL,
	[DURUMID] [smallint] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[PROJEID] [int] NULL,
	[MODULID] [int] NULL,
	[DEPOFISUUID] [uniqueidentifier] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOFISISL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOFISISL59](
	[DEPOFISISLID] [int] NOT NULL,
	[DEPOFISID] [int] NULL,
	[STOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[MARKAID] [int] NULL,
	[ISLREFID] [int] NULL,
	[FBFIYAT] [float] NULL,
	[URETSEVIYE] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[SKTARIHI] [datetime] NULL,
	[RGDEPOID] [int] NULL,
	[RCDEPOID] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[OTOTUKETISL] [bit] NULL,
	[TEMPITSID] [int] NULL,
	[ETSCARIID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[BMALIYET] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOW]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOW](
	[DEPOID] [int] NOT NULL,
	[DEPOADI] [nvarchar](40) NULL,
	[ANADEPO] [bit] NULL,
	[DEPOMUH] [int] NULL,
	[SKODU] [nvarchar](10) NULL,
	[KODU] [nvarchar](5) NULL,
	[MUHKODU] [nvarchar](25) NULL,
	[MUHKODUSARF] [nvarchar](25) NULL,
	[MASMERID] [int] NULL,
	[SUBEID] [int] NULL,
	[MASMERID2] [int] NULL,
	[MIKTARKONTROL] [bit] NULL,
	[ADI] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[SUBEFIYATKULLAN] [bit] NULL,
	[MERKEZDEPOID] [int] NULL,
	[NSATISHESAPID] [int] NULL,
	[KKSATISHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPOX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPOX](
	[DEPOID] [int] NOT NULL,
	[DEPOADI] [nvarchar](40) NULL,
	[ANADEPO] [bit] NULL,
	[DEPOMUH] [int] NULL,
	[SKODU] [nvarchar](10) NULL,
	[KODU] [nvarchar](5) NULL,
	[MUHKODU] [nvarchar](25) NULL,
	[MUHKODUSARF] [nvarchar](25) NULL,
	[MASMERID] [int] NULL,
	[SUBEID] [int] NULL,
	[MASMERID2] [int] NULL,
	[MIKTARKONTROL] [bit] NULL,
	[ADI] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[SUBEFIYATKULLAN] [bit] NULL,
	[MERKEZDEPOID] [int] NULL,
	[NSATISHESAPID] [int] NULL,
	[KKSATISHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DEPYAZICI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DEPYAZICI](
	[DEPYAZICIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPID] [int] NULL,
	[YAZICITIPID] [int] NULL,
	[TURU] [smallint] NULL,
	[YAZICIADI] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_DEPYAZICI] PRIMARY KEY CLUSTERED 
(
	[DEPYAZICIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DINAMIKRAPOR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DINAMIKRAPOR](
	[DINAMIKRAPORID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[RAPORADI] [nvarchar](50) NULL,
	[EKRANID] [int] NULL,
	[ANAEKRANID] [int] NULL,
	[OZELRAPOR] [bit] NULL,
	[RAPORFIRMAID] [int] NULL,
	[RAPORSQL] [nvarchar](max) NULL,
	[TURID] [smallint] NULL,
	[TARIHALANI] [nvarchar](20) NULL,
	[TARIHALANIA] [nvarchar](20) NULL,
	[TARIHALANIETIKET] [nvarchar](30) NULL,
	[TARIHAKTIF] [bit] NULL,
	[PARAMSQL1] [nvarchar](250) NULL,
	[PARAMSQL2] [nvarchar](250) NULL,
	[PARAMSQL3] [nvarchar](250) NULL,
	[PARAMSQL4] [nvarchar](250) NULL,
	[PARAMSQL5] [nvarchar](250) NULL,
	[PALAN1] [nvarchar](20) NULL,
	[PALAN1A] [nvarchar](20) NULL,
	[PALAN1ETIKET] [nvarchar](30) NULL,
	[PALAN2] [nvarchar](20) NULL,
	[PALAN2A] [nvarchar](20) NULL,
	[PALAN2ETIKET] [nvarchar](30) NULL,
	[PALAN3] [nvarchar](20) NULL,
	[PALAN3A] [nvarchar](20) NULL,
	[PALAN3ETIKET] [nvarchar](30) NULL,
	[PALAN4] [nvarchar](20) NULL,
	[PALAN4A] [nvarchar](20) NULL,
	[PALAN4ETIKET] [nvarchar](30) NULL,
	[PALAN5] [nvarchar](20) NULL,
	[PALAN5A] [nvarchar](20) NULL,
	[PALAN5ETIKET] [nvarchar](30) NULL,
	[PALAN1AKTIF] [bit] NULL,
	[PALAN2AKTIF] [bit] NULL,
	[PALAN3AKTIF] [bit] NULL,
	[PALAN4AKTIF] [bit] NULL,
	[PALAN5AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USREID] [int] NULL,
	[SIL] [smallint] NULL,
	[RAPORSQL2] [nvarchar](max) NULL,
	[DEL_USERID] [int] NULL,
 CONSTRAINT [PK_DINAMIKRAPOR] PRIMARY KEY CLUSTERED 
(
	[DINAMIKRAPORID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DINAMIKRAPOR_19052022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DINAMIKRAPOR_19052022](
	[DINAMIKRAPORID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[RAPORADI] [nvarchar](50) NULL,
	[EKRANID] [int] NULL,
	[ANAEKRANID] [int] NULL,
	[OZELRAPOR] [bit] NULL,
	[RAPORFIRMAID] [int] NULL,
	[RAPORSQL] [nvarchar](max) NULL,
	[TURID] [smallint] NULL,
	[TARIHALANI] [nvarchar](20) NULL,
	[TARIHALANIA] [nvarchar](20) NULL,
	[TARIHALANIETIKET] [nvarchar](30) NULL,
	[TARIHAKTIF] [bit] NULL,
	[PARAMSQL1] [nvarchar](250) NULL,
	[PARAMSQL2] [nvarchar](250) NULL,
	[PARAMSQL3] [nvarchar](250) NULL,
	[PARAMSQL4] [nvarchar](250) NULL,
	[PARAMSQL5] [nvarchar](250) NULL,
	[PALAN1] [nvarchar](20) NULL,
	[PALAN1A] [nvarchar](20) NULL,
	[PALAN1ETIKET] [nvarchar](30) NULL,
	[PALAN2] [nvarchar](20) NULL,
	[PALAN2A] [nvarchar](20) NULL,
	[PALAN2ETIKET] [nvarchar](30) NULL,
	[PALAN3] [nvarchar](20) NULL,
	[PALAN3A] [nvarchar](20) NULL,
	[PALAN3ETIKET] [nvarchar](30) NULL,
	[PALAN4] [nvarchar](20) NULL,
	[PALAN4A] [nvarchar](20) NULL,
	[PALAN4ETIKET] [nvarchar](30) NULL,
	[PALAN5] [nvarchar](20) NULL,
	[PALAN5A] [nvarchar](20) NULL,
	[PALAN5ETIKET] [nvarchar](30) NULL,
	[PALAN1AKTIF] [bit] NULL,
	[PALAN2AKTIF] [bit] NULL,
	[PALAN3AKTIF] [bit] NULL,
	[PALAN4AKTIF] [bit] NULL,
	[PALAN5AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USREID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DINAMIKRAPOR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DINAMIKRAPOR59](
	[DINAMIKRAPORID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[RAPORADI] [nvarchar](50) NULL,
	[EKRANID] [int] NULL,
	[ANAEKRANID] [int] NULL,
	[OZELRAPOR] [bit] NULL,
	[RAPORFIRMAID] [int] NULL,
	[RAPORSQL] [nvarchar](max) NULL,
	[TURID] [smallint] NULL,
	[TARIHALANI] [nvarchar](20) NULL,
	[TARIHALANIA] [nvarchar](20) NULL,
	[TARIHALANIETIKET] [nvarchar](30) NULL,
	[TARIHAKTIF] [bit] NULL,
	[PARAMSQL1] [nvarchar](250) NULL,
	[PARAMSQL2] [nvarchar](250) NULL,
	[PARAMSQL3] [nvarchar](250) NULL,
	[PARAMSQL4] [nvarchar](250) NULL,
	[PARAMSQL5] [nvarchar](250) NULL,
	[PALAN1] [nvarchar](20) NULL,
	[PALAN1A] [nvarchar](20) NULL,
	[PALAN1ETIKET] [nvarchar](30) NULL,
	[PALAN2] [nvarchar](20) NULL,
	[PALAN2A] [nvarchar](20) NULL,
	[PALAN2ETIKET] [nvarchar](30) NULL,
	[PALAN3] [nvarchar](20) NULL,
	[PALAN3A] [nvarchar](20) NULL,
	[PALAN3ETIKET] [nvarchar](30) NULL,
	[PALAN4] [nvarchar](20) NULL,
	[PALAN4A] [nvarchar](20) NULL,
	[PALAN4ETIKET] [nvarchar](30) NULL,
	[PALAN5] [nvarchar](20) NULL,
	[PALAN5A] [nvarchar](20) NULL,
	[PALAN5ETIKET] [nvarchar](30) NULL,
	[PALAN1AKTIF] [bit] NULL,
	[PALAN2AKTIF] [bit] NULL,
	[PALAN3AKTIF] [bit] NULL,
	[PALAN4AKTIF] [bit] NULL,
	[PALAN5AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USREID] [int] NULL,
	[SIL] [smallint] NULL,
	[DEL_USERID] [int] NULL,
	[RAPORSQL2] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DOVIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DOVIZ](
	[DOVIZID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](5) NOT NULL,
	[ADI] [nvarchar](25) NULL,
	[TCMBKODU] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[SIRANO] [tinyint] NULL,
	[KASAHESAPID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[KKHESAPID] [int] NULL,
 CONSTRAINT [PK_DOVIZ] PRIMARY KEY CLUSTERED 
(
	[DOVIZID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_DOVIZ] UNIQUE NONCLUSTERED 
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[KODU] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DOVIZ59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DOVIZ59](
	[DOVIZID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](5) NOT NULL,
	[ADI] [nvarchar](25) NULL,
	[TCMBKODU] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[SIRANO] [tinyint] NULL,
	[KASAHESAPID] [int] NULL,
	[KKHESAPID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DOVIZISL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DOVIZISL59](
	[DOVIZISLID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[TARIH] [datetime] NULL,
	[KODU] [nvarchar](5) NULL,
	[DOVIZALIS] [float] NULL,
	[DOVIZSATIS] [float] NULL,
	[MBDOVIZALIS] [float] NULL,
	[MBDOVIZSATIS] [float] NULL,
	[EFEKTIFALIS] [float] NULL,
	[EFEKTIFSATIS] [float] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[DREAMSTOK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DREAMSTOK](
	[STOKKODU] [nvarchar](255) NULL,
	[STOKADI] [nvarchar](255) NULL,
	[DEPOKODU] [nvarchar](255) NULL,
	[DEPOADI] [nvarchar](255) NULL,
	[ANAGRUPADI] [nvarchar](255) NULL,
	[BIRIM] [nvarchar](255) NULL,
	[DEVIR] [float] NULL,
	[GIREN] [float] NULL,
	[CIKAN] [float] NULL,
	[KALAN] [float] NULL,
	[URETICI] [nvarchar](255) NULL,
	[URETICIADI] [nvarchar](255) NULL,
	[TURU] [nvarchar](255) NULL,
	[ALISFIYATI] [float] NULL,
	[SFIYAT1] [float] NULL,
	[SFYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[ANAGRUP] [nvarchar](255) NULL,
	[MALIYETI] [float] NULL,
	[KALANSTOK] [float] NULL,
	[ALTGRUP] [nvarchar](255) NULL,
	[ALTGRUPADI] [nvarchar](255) NULL,
	[OZELKOD1] [nvarchar](255) NULL,
	[OZELKOD2] [nvarchar](255) NULL,
	[OZELKOD3] [nvarchar](255) NULL,
	[OZELKOD4] [nvarchar](255) NULL,
	[DEVIR1] [float] NULL,
	[GIREN1] [float] NULL,
	[CIKAN1] [float] NULL,
	[BARKOD] [nvarchar](255) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_BIRIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_BIRIM](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[KAYNAK] [nvarchar](50) NULL,
	[HEDEF] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EFATURA_BIRIM] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_EFATURA_BIRIM] UNIQUE NONCLUSTERED 
(
	[KAYNAK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_BIRIM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_BIRIM59](
	[ID] [int] NOT NULL,
	[KAYNAK] [nvarchar](50) NULL,
	[HEDEF] [nvarchar](50) NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_DOVIZ]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_DOVIZ](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[KAYNAK] [nvarchar](5) NULL,
	[HEDEF] [nvarchar](5) NULL,
 CONSTRAINT [PK_EFATURA_DOVIZ] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_EFATURA_DOVIZ] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_DOVIZ59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_DOVIZ59](
	[ID] [int] NOT NULL,
	[KAYNAK] [nvarchar](5) NULL,
	[HEDEF] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_FIRMA_17012022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_FIRMA_17012022](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VDNO] [nvarchar](50) NULL,
	[KODU] [nvarchar](250) NULL,
	[UNVANI] [nvarchar](500) NULL,
	[TIPI] [nvarchar](10) NULL,
	[KAYITTARIHI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[FIRMATIPI] [smallint] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_FIRMA_tmp_04_07_2022_14_45_59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_FIRMA_tmp_04_07_2022_14_45_59](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VDNO] [nvarchar](50) NULL,
	[KODU] [nvarchar](250) NULL,
	[UNVANI] [nvarchar](500) NULL,
	[TIPI] [nvarchar](10) NULL,
	[KAYITTARIHI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[FIRMATIPI] [smallint] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_FIRMA_tmp_04_07_2022_14_47_29]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_FIRMA_tmp_04_07_2022_14_47_29](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VDNO] [nvarchar](50) NULL,
	[KODU] [nvarchar](250) NULL,
	[UNVANI] [nvarchar](500) NULL,
	[TIPI] [nvarchar](10) NULL,
	[KAYITTARIHI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[FIRMATIPI] [smallint] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_FIRMA_tmp_08_07_2022_14_31_00]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_FIRMA_tmp_08_07_2022_14_31_00](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VDNO] [nvarchar](50) NULL,
	[KODU] [nvarchar](250) NULL,
	[UNVANI] [nvarchar](500) NULL,
	[TIPI] [nvarchar](10) NULL,
	[KAYITTARIHI] [datetime] NULL,
	[SIL] [smallint] NULL,
	[FIRMATIPI] [smallint] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_LOG]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_LOG](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[EFATNO] [nvarchar](50) NULL,
	[UUID] [nvarchar](50) NULL,
	[DURUM] [nvarchar](25) NULL,
	[TARIH] [datetime] NOT NULL,
	[ISLEM] [nvarchar](25) NULL,
	[HATAMESAJI] [nvarchar](255) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[XML] [ntext] NULL,
	[ONIZLE] [ntext] NULL,
 CONSTRAINT [PK_EFATURA_LOG] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY],
 CONSTRAINT [IX_EFATURA_LOG] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EFATURA_POSTAKUTUSU]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EFATURA_POSTAKUTUSU](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[VKN] [nvarchar](15) NULL,
	[POSTA_KUTUSU] [nvarchar](500) NULL,
	[VARSAYILAN] [bit] NULL,
 CONSTRAINT [PK_EFATURA_POSTAKUTUSU] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_EFATURA_POSTAKUTUSU] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EGITIM0306]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EGITIM0306](
	[EGITIMADI] [nvarchar](255) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EGITIMLERX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EGITIMLERX](
	[FIRMAID] [float] NULL,
	[İÇDIŞI] [nvarchar](255) NULL,
	[EGITIMADI] [nvarchar](255) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKOZELLIK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKOZELLIK](
	[EKOZELLIKID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GRUP] [nvarchar](50) NULL,
	[OZELLIK] [nvarchar](50) NULL,
	[FIYAT] [float] NULL,
	[IKRAM] [bit] NULL,
	[MANUEL] [bit] NULL,
	[SURE] [smallint] NULL,
	[RECETEID] [int] NULL,
	[TUMURUNLER] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EKOZELLIK] PRIMARY KEY CLUSTERED 
(
	[EKOZELLIKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKRANLAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKRANLAR](
	[EKRANID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANSIRA] [smallint] NULL,
	[EKRANMI] [smallint] NULL,
	[FORMADI] [nvarchar](30) NULL,
	[EKRANADI] [nvarchar](50) NULL,
	[RESIMINDEX] [smallint] NULL,
	[RESIMINDEX32] [smallint] NULL,
	[TREERESIMINDEX] [smallint] NULL,
	[SECINDEX] [smallint] NULL,
	[ANAMODULMU] [bit] NULL,
	[BAGLIMODULID] [int] NULL,
	[TABICINDE] [bit] NULL,
	[AKTIF] [bit] NULL,
	[YENIISLEM] [bit] NULL,
	[FISTURID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EKRANLAR_1] PRIMARY KEY CLUSTERED 
(
	[EKRANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKRANLAR_19052022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKRANLAR_19052022](
	[EKRANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANSIRA] [smallint] NULL,
	[EKRANMI] [smallint] NULL,
	[FORMADI] [nvarchar](30) NULL,
	[EKRANADI] [nvarchar](50) NULL,
	[RESIMINDEX] [smallint] NULL,
	[RESIMINDEX32] [smallint] NULL,
	[TREERESIMINDEX] [smallint] NULL,
	[SECINDEX] [smallint] NULL,
	[ANAMODULMU] [bit] NULL,
	[BAGLIMODULID] [int] NULL,
	[TABICINDE] [bit] NULL,
	[AKTIF] [bit] NULL,
	[YENIISLEM] [bit] NULL,
	[FISTURID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKRANLAR_27042022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKRANLAR_27042022](
	[EKRANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANSIRA] [smallint] NULL,
	[EKRANMI] [smallint] NULL,
	[FORMADI] [nvarchar](30) NULL,
	[EKRANADI] [nvarchar](50) NULL,
	[RESIMINDEX] [smallint] NULL,
	[RESIMINDEX32] [smallint] NULL,
	[TREERESIMINDEX] [smallint] NULL,
	[SECINDEX] [smallint] NULL,
	[ANAMODULMU] [bit] NULL,
	[BAGLIMODULID] [int] NULL,
	[TABICINDE] [bit] NULL,
	[AKTIF] [bit] NULL,
	[YENIISLEM] [bit] NULL,
	[FISTURID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKRANLAR_28012021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKRANLAR_28012021](
	[EKRANID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANSIRA] [smallint] NULL,
	[EKRANMI] [smallint] NULL,
	[FORMADI] [nvarchar](20) NULL,
	[EKRANADI] [nvarchar](50) NULL,
	[RESIMINDEX] [smallint] NULL,
	[RESIMINDEX32] [smallint] NULL,
	[TREERESIMINDEX] [smallint] NULL,
	[SECINDEX] [smallint] NULL,
	[ANAMODULMU] [bit] NULL,
	[BAGLIMODULID] [int] NULL,
	[TABICINDE] [bit] NULL,
	[AKTIF] [bit] NULL,
	[YENIISLEM] [bit] NULL,
	[FISTURID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EKRANLAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EKRANLAR59](
	[EKRANID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANSIRA] [smallint] NULL,
	[EKRANMI] [smallint] NULL,
	[FORMADI] [nvarchar](30) NULL,
	[EKRANADI] [nvarchar](50) NULL,
	[RESIMINDEX] [smallint] NULL,
	[RESIMINDEX32] [smallint] NULL,
	[TREERESIMINDEX] [smallint] NULL,
	[SECINDEX] [smallint] NULL,
	[ANAMODULMU] [bit] NULL,
	[BAGLIMODULID] [int] NULL,
	[TABICINDE] [bit] NULL,
	[AKTIF] [bit] NULL,
	[YENIISLEM] [bit] NULL,
	[FISTURID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKDAIRE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKDAIRE](
	[EMLAKDAIREID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[SATICIHESAPID] [int] NULL,
	[SATICIALTCARIID] [int] NULL,
	[LISTEFIYATI] [float] NULL,
	[REELFIYATI] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DAIREACIKLAMA] [nvarchar](150) NULL,
 CONSTRAINT [PK_EMLAKDAIRE] PRIMARY KEY CLUSTERED 
(
	[EMLAKDAIREID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKDAIRE59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKDAIRE59](
	[EMLAKDAIREID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[SATICIHESAPID] [int] NULL,
	[SATICIALTCARIID] [int] NULL,
	[LISTEFIYATI] [float] NULL,
	[REELFIYATI] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DAIREACIKLAMA] [nvarchar](150) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKDOSYA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKDOSYA](
	[EMLAKDOSYAID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[DOSYAADI] [nvarchar](50) NULL,
	[TURU] [nvarchar](10) NULL,
	[DOSYA] [varbinary](max) NULL,
	[AKTARILDI] [bit] NULL,
	[AKTARIMZAMANI] [datetime] NULL,
 CONSTRAINT [PK_EMLAKDOSYA] PRIMARY KEY CLUSTERED 
(
	[EMLAKDOSYAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKDOSYA59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKDOSYA59](
	[EMLAKDOSYAID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[DOSYAADI] [nvarchar](50) NULL,
	[TURU] [nvarchar](10) NULL,
	[DOSYA] [varbinary](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKGORUSMELER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKGORUSMELER](
	[EMLAKGORUSMELERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[ARAYANMUSTERIID] [int] NULL,
	[ARAYANMUSTERI] [nvarchar](30) NULL,
	[TELEFON] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[ULKE] [nvarchar](50) NULL,
	[SEHIR] [nvarchar](30) NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[DAIRE] [nvarchar](30) NULL,
	[ILGILIPERSONELID] [int] NULL,
	[ILGILIPERSONEL] [nvarchar](50) NULL,
	[ILGILIEMLAKCIID] [int] NULL,
	[ILGILIEMLKACI] [nvarchar](50) NULL,
	[TRANSFERVARMI] [bit] NULL,
	[KONAKLAMAVARMI] [bit] NULL,
	[VIPMUSTERI] [bit] NULL,
	[LISTEFIYATI] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[INDIRIMYUZDE] [float] NULL,
	[NETTOPLAM] [float] NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[MUSTERINOTU] [nvarchar](150) NULL,
	[EMLAKCINOTU] [nvarchar](150) NULL,
	[GENELNOT] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EMLAKGORUSMELER] PRIMARY KEY CLUSTERED 
(
	[EMLAKGORUSMELERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKGORUSMELER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKGORUSMELER59](
	[EMLAKGORUSMELERID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[ARAYANMUSTERIID] [int] NULL,
	[ARAYANMUSTERI] [nvarchar](30) NULL,
	[TELEFON] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[ULKE] [nvarchar](50) NULL,
	[SEHIR] [nvarchar](30) NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[DAIRE] [nvarchar](30) NULL,
	[ILGILIPERSONELID] [int] NULL,
	[ILGILIPERSONEL] [nvarchar](50) NULL,
	[ILGILIEMLAKCIID] [int] NULL,
	[ILGILIEMLKACI] [nvarchar](50) NULL,
	[TRANSFERVARMI] [bit] NULL,
	[KONAKLAMAVARMI] [bit] NULL,
	[VIPMUSTERI] [bit] NULL,
	[LISTEFIYATI] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[INDIRIMYUZDE] [float] NULL,
	[NETTOPLAM] [float] NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[MUSTERINOTU] [nvarchar](150) NULL,
	[EMLAKCINOTU] [nvarchar](150) NULL,
	[GENELNOT] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKINDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKINDEK](
	[EMLAKINDEKID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TUR] [smallint] NULL,
	[INDEKID] [int] NULL,
	[ENDEKADI] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[TUTAR] [float] NULL,
	[YUZDE] [float] NULL,
 CONSTRAINT [PK_EMLAKINDEK] PRIMARY KEY CLUSTERED 
(
	[EMLAKINDEKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKINDEK59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKINDEK59](
	[EMLAKINDEKID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TUR] [smallint] NULL,
	[INDEKID] [int] NULL,
	[ENDEKADI] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[TUTAR] [float] NULL,
	[YUZDE] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRADOSYA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRADOSYA](
	[EMLAKKIRADOSYAID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKKIRALAMAID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[DOSYAADI] [nvarchar](50) NULL,
	[TURU] [nvarchar](10) NULL,
	[DOSYA] [varbinary](max) NULL,
 CONSTRAINT [PK_EMLAKKIRADOSYA] PRIMARY KEY CLUSTERED 
(
	[EMLAKKIRADOSYAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRADOSYA59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRADOSYA59](
	[EMLAKKIRADOSYAID] [int] NOT NULL,
	[EMLAKKIRALAMAID] [int] NULL,
	[EKLEMEZAMANI] [datetime] NULL,
	[DOSYAADI] [nvarchar](50) NULL,
	[TURU] [nvarchar](10) NULL,
	[DOSYA] [varbinary](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRALAMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRALAMA](
	[EMLAKKIRALAMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[TAPUDAIRESI] [nvarchar](30) NULL,
	[MAHALLE] [nvarchar](50) NULL,
	[CADDESOKAK] [nvarchar](50) NULL,
	[DAIRENO] [nvarchar](30) NULL,
	[KIRALANAN] [nvarchar](20) NULL,
	[KVID] [int] NULL,
	[KVADSOYAD] [nvarchar](50) NULL,
	[KVTCNO] [nvarchar](11) NULL,
	[KVADRES] [nvarchar](250) NULL,
	[KVTELEFON] [nvarchar](25) NULL,
	[KIRACIID] [int] NULL,
	[KIRACIADSOYAD] [nvarchar](50) NULL,
	[KIRACITCNO] [nvarchar](11) NULL,
	[KIRACIADRES] [nvarchar](250) NULL,
	[KIRABASLANGIC] [smalldatetime] NULL,
	[KIRACITELEFON] [nvarchar](25) NULL,
	[SUREAY] [int] NULL,
	[KIRABITIS] [smalldatetime] NULL,
	[AYLIKKIRABEDELI] [float] NULL,
	[YILLIKKIRABEDELI] [float] NULL,
	[KIRADOVIZ] [nvarchar](5) NULL,
	[KAPORA] [float] NULL,
	[EMLAKKOMISYON] [float] NULL,
	[ODEMESEKLI] [nvarchar](10) NULL,
	[KULLANIMAMACI] [nvarchar](20) NULL,
	[DURUMU] [nvarchar](50) NULL,
	[DEMIRBASLAR] [nvarchar](500) NULL,
	[SOZLESMEDURUMU] [nvarchar](20) NULL,
	[ACIKLAMALAR] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EMLAKKIRALAMA] PRIMARY KEY CLUSTERED 
(
	[EMLAKKIRALAMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRALAMA59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRALAMA59](
	[EMLAKKIRALAMAID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[TAPUDAIRESI] [nvarchar](30) NULL,
	[MAHALLE] [nvarchar](50) NULL,
	[CADDESOKAK] [nvarchar](50) NULL,
	[DAIRENO] [nvarchar](30) NULL,
	[KIRALANAN] [nvarchar](20) NULL,
	[KVID] [int] NULL,
	[KVADSOYAD] [nvarchar](50) NULL,
	[KVTCNO] [nvarchar](11) NULL,
	[KVADRES] [nvarchar](250) NULL,
	[KVTELEFON] [nvarchar](25) NULL,
	[KIRACIID] [int] NULL,
	[KIRACIADSOYAD] [nvarchar](50) NULL,
	[KIRACITCNO] [nvarchar](11) NULL,
	[KIRACIADRES] [nvarchar](250) NULL,
	[KIRABASLANGIC] [smalldatetime] NULL,
	[KIRACITELEFON] [nvarchar](25) NULL,
	[SUREAY] [int] NULL,
	[KIRABITIS] [smalldatetime] NULL,
	[AYLIKKIRABEDELI] [float] NULL,
	[YILLIKKIRABEDELI] [float] NULL,
	[KIRADOVIZ] [nvarchar](5) NULL,
	[KAPORA] [float] NULL,
	[EMLAKKOMISYON] [float] NULL,
	[ODEMESEKLI] [nvarchar](10) NULL,
	[KULLANIMAMACI] [nvarchar](20) NULL,
	[DURUMU] [nvarchar](50) NULL,
	[DEMIRBASLAR] [nvarchar](500) NULL,
	[SOZLESMEDURUMU] [nvarchar](20) NULL,
	[ACIKLAMALAR] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRATAKSIT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRATAKSIT](
	[EMLAKKIRATAKSITID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKKIRALAMAID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[ODEMETURU] [nvarchar](30) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[TUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ODENDI] [bit] NULL,
	[ODENENTUTAR] [float] NULL,
	[ONCEHATIRLAT] [int] NULL,
	[SMSGITTI] [bit] NULL,
 CONSTRAINT [PK_EMLAKKIRATAKSIT] PRIMARY KEY CLUSTERED 
(
	[EMLAKKIRATAKSITID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKKIRATAKSIT59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKKIRATAKSIT59](
	[EMLAKKIRATAKSITID] [int] NOT NULL,
	[EMLAKKIRALAMAID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[ODEMETURU] [nvarchar](30) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[TUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ODENDI] [bit] NULL,
	[ODENENTUTAR] [float] NULL,
	[ONCEHATIRLAT] [int] NULL,
	[SMSGITTI] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSATIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATIS59](
	[EMLAKSATISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TAPUTARIHI] [smalldatetime] NULL,
	[SOZLESMENO] [nvarchar](20) NULL,
	[KENDIMULKUMUZ] [bit] NULL,
	[MULKSATICIHESAPID] [int] NULL,
	[MULKSATICIALTCARIID] [int] NULL,
	[SATICIADSOYAD] [nvarchar](80) NULL,
	[SATICIADRES] [nvarchar](200) NULL,
	[SATICITEL] [nvarchar](25) NULL,
	[SATICIEMAIL] [nvarchar](40) NULL,
	[ALICIHESAPID] [int] NULL,
	[ALICIALTCARIID] [int] NULL,
	[ALICIADSOYAD] [nvarchar](80) NULL,
	[ALICIADRES] [nvarchar](200) NULL,
	[ALICITEL] [nvarchar](25) NULL,
	[ALICIEMAIL] [nvarchar](40) NULL,
	[ALICIDOGUMTARIHI] [smalldatetime] NULL,
	[ALICIVATNO] [nvarchar](20) NULL,
	[ALICIANNEADI] [nvarchar](20) NULL,
	[ALICIBABAADI] [nvarchar](20) NULL,
	[ISLEMGRUPID1] [int] NULL,
	[PROJEID] [int] NULL,
	[DAIREID] [int] NULL,
	[DAIREID2] [int] NULL,
	[DAIREID3] [int] NULL,
	[PROJEMAH] [nvarchar](20) NULL,
	[PROJEADANO] [nvarchar](10) NULL,
	[PROJEPARSEL] [nvarchar](10) NULL,
	[BAGIMSIZBOLUM] [nvarchar](20) NULL,
	[KAT] [nvarchar](10) NULL,
	[GMACIKADRES] [nvarchar](200) NULL,
	[SATISTEMSILCIID] [int] NULL,
	[SATISTEMSILCI] [nvarchar](50) NULL,
	[SIRKETYETKILISI] [nvarchar](30) NULL,
	[LISTEFIYATI] [float] NULL,
	[REELFIYAT] [float] NULL,
	[SATISNOTLARI] [nvarchar](150) NULL,
	[EMLAKFIRMAHESAPID] [int] NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TAKSITSAYISI] [int] NULL,
	[ILKTAKSITVADE] [smalldatetime] NULL,
	[ILKTAKSITTUTAR] [float] NULL,
	[TAKSITACIKLAMA] [nvarchar](250) NULL,
	[SONTAKSITVADE] [smalldatetime] NULL,
	[ARACIFIRMASAHIS] [nvarchar](30) NULL,
	[BEYAZESYA] [nvarchar](20) NULL,
	[EKSTRATALEP] [nvarchar](50) NULL,
	[TRANSFER] [nvarchar](50) NULL,
	[BILETFIYATI] [float] NULL,
	[TAPUISKANES] [nvarchar](50) NULL,
	[MUHASEBELESTI] [smallint] NULL,
	[MUHFISID] [int] NULL,
	[TAAHTUTARI] [float] NULL,
	[TAAHDOVIZ] [nvarchar](5) NULL,
	[MASRAFKIMIN] [nvarchar](10) NULL,
	[BASKATASVARMI] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[IPTALTARIH] [smalldatetime] NULL,
	[IPTALACIKLAMA] [nvarchar](50) NULL,
	[IPTALFISID] [int] NULL,
	[ACENTAHESAPID] [int] NULL,
	[KOMDAHIL] [bit] NULL,
	[DAIRELER] [nvarchar](150) NULL,
	[INDIRIM] [float] NULL,
	[SOZLESMETURU] [nvarchar](30) NULL,
	[REHBERHESAPID] [int] NULL,
	[REHBERALTCARIID] [int] NULL,
	[REHBER2HESAPID] [int] NULL,
	[REHBER2ALTCARIID] [int] NULL,
	[ACENTAALTCARIID] [int] NULL,
	[ALICIULKE] [nvarchar](30) NULL,
	[VEKALET] [nvarchar](5) NULL,
	[VEKALETNOT] [nvarchar](50) NULL,
	[SATISTEMSILCIHESAPID] [int] NULL,
	[SATISTEMSILCIALTCARIID] [int] NULL,
	[SATISKAPATANID] [int] NULL,
	[IMZAYETKILIID] [int] NULL,
	[TAPUTARIH] [smalldatetime] NULL,
	[TAPUDAKIAD] [nvarchar](50) NULL,
	[ELEKTRIKABONESI] [nvarchar](30) NULL,
	[SUABONESI] [nvarchar](30) NULL,
	[SIGORTAPOLICESI] [nvarchar](30) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSATISKOM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATISKOM](
	[EMLAKSATISKOMID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[KOMISYONCUID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL,
 CONSTRAINT [PK_EMLAKSATISKOM] PRIMARY KEY CLUSTERED 
(
	[EMLAKSATISKOMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSATISKOM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATISKOM59](
	[EMLAKSATISKOMID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[KOMISYONCUID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[KOMISYONORAN] [float] NULL,
	[KOMISYONTUTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSATISNOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATISNOT](
	[EMLAKSATISNOTID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TIP] [smallint] NULL,
	[TURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[TARIH] [smalldatetime] NULL,
	[TUTAR] [float] NULL,
	[ACIKLAMA2] [nvarchar](50) NULL,
	[ISLEMYETKILIID] [int] NULL,
	[ISLEMYETKILI] [nvarchar](30) NULL,
	[KONTROL] [bit] NULL,
 CONSTRAINT [PK_EMLAKSATISNOT] PRIMARY KEY CLUSTERED 
(
	[EMLAKSATISNOTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSATISNOT59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSATISNOT59](
	[EMLAKSATISNOTID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TIP] [smallint] NULL,
	[TURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[TARIH] [smalldatetime] NULL,
	[TUTAR] [float] NULL,
	[ACIKLAMA2] [nvarchar](50) NULL,
	[ISLEMYETKILIID] [int] NULL,
	[ISLEMYETKILI] [nvarchar](30) NULL,
	[KONTROL] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSTDNOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSTDNOT](
	[EMLAKSTDNOTID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[NOTTURID] [int] NULL,
	[NOTTURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EMLAKSTDNOT] PRIMARY KEY CLUSTERED 
(
	[EMLAKSTDNOTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKSTDNOT59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKSTDNOT59](
	[EMLAKSTDNOTID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[NOTTURID] [int] NULL,
	[NOTTURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTAKSIT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTAKSIT](
	[EMLAKTAKSITID] [int] IDENTITY(1,1) NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TUR] [nvarchar](10) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[TUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODENDI] [bit] NULL,
 CONSTRAINT [PK_EMLAKTAKSIT] PRIMARY KEY CLUSTERED 
(
	[EMLAKTAKSITID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTAKSIT59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTAKSIT59](
	[EMLAKTAKSITID] [int] NOT NULL,
	[EMLAKSATISID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[TUR] [nvarchar](10) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[TUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODENDI] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTIP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTIP](
	[EMLAKTIPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EMLAKTURU] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[AIDAT] [float] NULL,
	[ADOVIZ] [nvarchar](5) NULL,
 CONSTRAINT [PK_DAIREOZELLIK] PRIMARY KEY CLUSTERED 
(
	[EMLAKTIPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTIP59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTIP59](
	[EMLAKTIPID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EMLAKTURU] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[AIDAT] [float] NULL,
	[ADOVIZ] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTRANSFER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTRANSFER](
	[EMLAKTRANSFERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[TUR] [nvarchar](20) NULL,
	[KALKISYERI] [nvarchar](50) NULL,
	[VARISYERI] [nvarchar](50) NULL,
	[ARACTIPI] [nvarchar](20) NULL,
	[UCUSKODU] [nvarchar](20) NULL,
	[FIRMA] [nchar](20) NULL,
	[MISAFIRADSOYAD] [nvarchar](50) NULL,
	[MILLIYET] [nvarchar](20) NULL,
	[KISI] [int] NULL,
	[FIYAT] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SOFOR] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_EMLAKTRANSFER] PRIMARY KEY CLUSTERED 
(
	[EMLAKTRANSFERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[EMLAKTRANSFER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMLAKTRANSFER59](
	[EMLAKTRANSFERID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[TUR] [nvarchar](20) NULL,
	[KALKISYERI] [nvarchar](50) NULL,
	[VARISYERI] [nvarchar](50) NULL,
	[ARACTIPI] [nvarchar](20) NULL,
	[UCUSKODU] [nvarchar](20) NULL,
	[FIRMA] [nchar](20) NULL,
	[MISAFIRADSOYAD] [nvarchar](50) NULL,
	[MILLIYET] [nvarchar](20) NULL,
	[KISI] [int] NULL,
	[FIYAT] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SOFOR] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATAKTARIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATAKTARIM](
	[FATAKTARIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FISTURID] [int] NULL,
	[FISHESAPID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[FATURANO] [nvarchar](20) NULL,
	[FATID] [int] NULL,
	[GRUPID] [int] NULL,
	[STOKID] [int] NULL,
	[BARKOD] [nvarchar](10) NULL,
	[STOKADI] [nvarchar](50) NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[RENK] [nvarchar](20) NULL,
	[BEDEN] [nvarchar](20) NULL,
	[FBIRIM] [nvarchar](10) NULL,
	[FMIKTAR] [float] NULL,
	[FBFIYAT] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[KDVDAHIL] [nvarchar](10) NULL,
	[KDVORAN] [float] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[AKTARIMUUID] [uniqueidentifier] NULL,
	[CARIUNVAN] [nvarchar](150) NULL,
 CONSTRAINT [PK_FATAKTARIM] PRIMARY KEY CLUSTERED 
(
	[FATAKTARIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATAKTARIM_YEDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATAKTARIM_YEDEK](
	[FATAKTARIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FISTURID] [int] NULL,
	[FISHESAPID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[FATURANO] [nvarchar](20) NULL,
	[FATID] [int] NULL,
	[GRUPID] [int] NULL,
	[STOKID] [int] NULL,
	[BARKOD] [nvarchar](10) NULL,
	[STOKADI] [nvarchar](50) NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[RENK] [nvarchar](20) NULL,
	[BEDEN] [nvarchar](20) NULL,
	[FBIRIM] [nvarchar](10) NULL,
	[FMIKTAR] [float] NULL,
	[FBFIYAT] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[KDVDAHIL] [nvarchar](10) NULL,
	[KDVORAN] [float] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[AKTARIMUUID] [uniqueidentifier] NULL,
	[CARIUNVAN] [nvarchar](150) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATIRSALIYE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATIRSALIYE](
	[FATIRSALIYEID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[IRSALIYESERI] [nvarchar](5) NULL,
	[IRSALIYENO] [nvarchar](20) NULL,
	[IRSALIYETARIH] [smalldatetime] NULL,
 CONSTRAINT [PK_FATIRSALIYE] PRIMARY KEY CLUSTERED 
(
	[FATIRSALIYEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATISL_ROYAL_YEDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATISL_ROYAL_YEDEK](
	[FATISLID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NOT NULL,
	[BARKOD] [nvarchar](30) NULL,
	[IRSISLID] [int] NULL,
	[HESAPID] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[SATISTID] [int] NULL,
	[ADET] [float] NOT NULL,
	[BFIYAT] [float] NOT NULL,
	[SKTARIHI] [datetime] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[SATIRIND3] [float] NULL,
	[SATIRIND4] [float] NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FADET] [float] NOT NULL,
	[FBFIYAT] [float] NOT NULL,
	[VADE] [datetime] NULL,
	[KDV] [float] NULL,
	[IRSCOUNTER] [int] NULL,
	[IRSCOUNTERILK] [int] NULL,
	[SGRUPLA] [int] NULL,
	[SATIRINDT] [float] NULL,
	[DEPT] [nvarchar](5) NULL,
	[GELIRGRUP] [nvarchar](5) NULL,
	[FBTOPLAM] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[TEVORAN] [nvarchar](5) NULL,
	[KODU] [nvarchar](20) NULL,
	[FFARKI] [int] NULL,
	[RGDEPOID] [int] NULL,
	[SILINDI] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[DFBFIYAT] [float] NULL,
	[DBFIYAT] [float] NULL,
	[ISLREFID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[IRSADET] [float] NULL,
	[KDVTURU] [nvarchar](5) NULL,
	[MUHFC] [float] NULL,
	[SRMMRKID] [int] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[SATIRNO] [int] NULL,
	[KDVLIFIYAT] [float] NULL,
	[YAZILDI] [int] NULL,
	[DEMID] [int] NULL,
	[SIPYAZILDI] [int] NULL,
	[YAZICINO] [int] NULL,
	[BMALIYET] [float] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[BABSHARIC] [int] NULL,
	[TEMPITSID] [int] NULL,
	[SSIRA] [int] NULL,
	[KDV2] [float] NULL,
	[KNO] [int] NULL,
	[SERILOTID] [int] NULL,
	[GTARIHI] [smalldatetime] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[TEVKANUNKODU] [nvarchar](20) NULL,
	[TEVKANUNACIKLAMA] [nvarchar](200) NULL,
	[URETICIKODU] [nvarchar](10) NULL,
	[ALICIKODU] [nvarchar](10) NULL,
	[SATICIKODU] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[SIL] [smallint] NULL,
	[KDVDAHIL] [nvarchar](5) NULL,
	[FATFIRMAID] [int] NULL,
	[OLDFATID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FKARSIHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATISL_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATISL_TEMP](
	[FATISLID] [int] NOT NULL,
	[FATID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[IRSISLID] [int] NULL,
	[HESAPID] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[SATISTID] [int] NULL,
	[ADET] [float] NULL,
	[BFIYAT] [float] NULL,
	[SKTARIHI] [smalldatetime] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FADET] [float] NULL,
	[FBFIYAT] [float] NULL,
	[VADE] [smalldatetime] NULL,
	[KDV] [float] NULL,
	[IRSCOUNTER] [int] NULL,
	[IRSCOUNTERILK] [int] NULL,
	[SGRUPLA] [int] NULL,
	[SATIRINDT] [float] NULL,
	[DEPT] [nvarchar](5) NULL,
	[GELIRGRUP] [nvarchar](5) NULL,
	[FBTOPLAM] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[TEVORAN] [nvarchar](5) NULL,
	[KODU] [nvarchar](20) NULL,
	[FFARKI] [int] NULL,
	[RGDEPOID] [int] NULL,
	[SILINDI] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[DFBFIYAT] [float] NULL,
	[DBFIYAT] [float] NULL,
	[ISLREFID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[IRSADET] [float] NULL,
	[KDVTURU] [nvarchar](5) NULL,
	[MUHFC] [float] NULL,
	[SRMMRKID] [int] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[SATIRNO] [int] NULL,
	[KDVLIFIYAT] [float] NULL,
	[YAZILDI] [int] NULL,
	[DEMID] [int] NULL,
	[SIPYAZILDI] [int] NULL,
	[YAZICINO] [int] NULL,
	[BMALIYET] [float] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[BABSHARIC] [int] NULL,
	[TEMPITSID] [int] NULL,
	[SSIRA] [int] NULL,
	[KDV2] [float] NULL,
	[KNO] [int] NULL,
	[SERILOTID] [int] NULL,
	[GTARIHI] [smalldatetime] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[SATIRIND3] [float] NULL,
	[SATIRIND4] [float] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[TEVKANUNKODU] [nvarchar](20) NULL,
	[TEVKANUNACIKLAMA] [nvarchar](200) NULL,
	[URETICIKODU] [nvarchar](10) NULL,
	[ALICIKODU] [nvarchar](10) NULL,
	[SATICIKODU] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[FATID_V6] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATISL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATISL59](
	[FATISLID] [int] NOT NULL,
	[FATID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NOT NULL,
	[BARKOD] [nvarchar](30) NULL,
	[IRSISLID] [int] NULL,
	[HESAPID] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[SATISTID] [int] NULL,
	[ADET] [float] NOT NULL,
	[BFIYAT] [float] NOT NULL,
	[SKTARIHI] [datetime] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[SATIRIND3] [float] NULL,
	[SATIRIND4] [float] NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FADET] [float] NOT NULL,
	[FBFIYAT] [float] NOT NULL,
	[VADE] [datetime] NULL,
	[KDV] [float] NULL,
	[IRSCOUNTER] [int] NULL,
	[IRSCOUNTERILK] [int] NULL,
	[SGRUPLA] [int] NULL,
	[SATIRINDT] [float] NULL,
	[DEPT] [nvarchar](5) NULL,
	[GELIRGRUP] [nvarchar](5) NULL,
	[FBTOPLAM] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[TEVORAN] [nvarchar](5) NULL,
	[KODU] [nvarchar](20) NULL,
	[FFARKI] [int] NULL,
	[RGDEPOID] [int] NULL,
	[SILINDI] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[DFBFIYAT] [float] NULL,
	[DBFIYAT] [float] NULL,
	[ISLREFID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[IRSADET] [float] NULL,
	[KDVTURU] [nvarchar](5) NULL,
	[MUHFC] [float] NULL,
	[SRMMRKID] [int] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[SATIRNO] [int] NULL,
	[KDVLIFIYAT] [float] NULL,
	[YAZILDI] [int] NULL,
	[DEMID] [int] NULL,
	[SIPYAZILDI] [int] NULL,
	[YAZICINO] [int] NULL,
	[BMALIYET] [float] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[BABSHARIC] [int] NULL,
	[TEMPITSID] [int] NULL,
	[SSIRA] [int] NULL,
	[KDV2] [float] NULL,
	[KNO] [int] NULL,
	[SERILOTID] [int] NULL,
	[GTARIHI] [smalldatetime] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[TEVKANUNKODU] [nvarchar](20) NULL,
	[TEVKANUNACIKLAMA] [nvarchar](200) NULL,
	[URETICIKODU] [nvarchar](10) NULL,
	[ALICIKODU] [nvarchar](10) NULL,
	[SATICIKODU] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[SIL] [smallint] NULL,
	[KDVDAHIL] [nvarchar](5) NULL,
	[FATFIRMAID] [int] NULL,
	[OLDFATID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[FKARSIHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATISLX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATISLX](
	[FATISLID] [int] NOT NULL,
	[FATID] [int] NULL,
	[ANASTOKID] [int] NULL,
	[STOKID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[IRSISLID] [int] NULL,
	[HESAPID] [int] NULL,
	[SATINALMAISLID] [int] NULL,
	[SATISTID] [int] NULL,
	[ADET] [float] NULL,
	[BFIYAT] [float] NULL,
	[SKTARIHI] [datetime] NULL,
	[SATIRIND] [float] NULL,
	[SATIRIND2] [float] NULL,
	[SATIRIND3] [float] NULL,
	[SATIRIND4] [float] NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FADET] [float] NULL,
	[FBFIYAT] [float] NULL,
	[VADE] [datetime] NULL,
	[KDV] [float] NULL,
	[IRSCOUNTER] [int] NULL,
	[IRSCOUNTERILK] [int] NULL,
	[SGRUPLA] [int] NULL,
	[SATIRINDT] [float] NULL,
	[DEPT] [nvarchar](5) NULL,
	[GELIRGRUP] [nvarchar](5) NULL,
	[FBTOPLAM] [float] NULL,
	[ARATOPLAM] [float] NULL,
	[TEVORAN] [nvarchar](5) NULL,
	[KODU] [nvarchar](20) NULL,
	[FFARKI] [int] NULL,
	[RGDEPOID] [int] NULL,
	[SILINDI] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[DFBFIYAT] [float] NULL,
	[DBFIYAT] [float] NULL,
	[ISLREFID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZKURU] [float] NULL,
	[IRSADET] [float] NULL,
	[KDVTURU] [nvarchar](5) NULL,
	[MUHFC] [float] NULL,
	[SRMMRKID] [int] NULL,
	[DOVIZKODU] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[SATIRNO] [int] NULL,
	[KDVLIFIYAT] [float] NULL,
	[YAZILDI] [int] NULL,
	[DEMID] [int] NULL,
	[SIPYAZILDI] [int] NULL,
	[YAZICINO] [int] NULL,
	[BMALIYET] [float] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[BABSHARIC] [int] NULL,
	[TEMPITSID] [int] NULL,
	[SSIRA] [int] NULL,
	[KDV2] [float] NULL,
	[KNO] [int] NULL,
	[SERILOTID] [int] NULL,
	[GTARIHI] [smalldatetime] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[TEVKANUNKODU] [nvarchar](20) NULL,
	[TEVKANUNACIKLAMA] [nvarchar](200) NULL,
	[URETICIKODU] [nvarchar](10) NULL,
	[ALICIKODU] [nvarchar](10) NULL,
	[SATICIKODU] [nvarchar](10) NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURA_RBD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURA_RBD](
	[FATID] [int] NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [smalldatetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [smalldatetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[DEL_DATE] [smalldatetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [smalldatetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [smalldatetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [smalldatetime] NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [smalldatetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [smalldatetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[EFATTURU] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [smalldatetime] NULL,
	[IRSALIYENO] [nvarchar](500) NULL,
	[IRSALIYETARIHI] [smalldatetime] NULL,
	[EFATURAACIKLAMA] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[EFATURA_KABULREDNOTU] [nvarchar](255) NULL,
	[EFATNO] [nvarchar](16) NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[EFATURAZARF] [uniqueidentifier] NULL,
	[UUID] [uniqueidentifier] NOT NULL,
	[EFATURA_ENTREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPTARIHI] [smalldatetime] NULL,
	[EFATURA_CEVAPACK] [nvarchar](150) NULL,
	[EFATURAACIKLAMA2] [nvarchar](250) NULL,
	[EFATURA_CEVAP_UUID] [uniqueidentifier] NULL,
	[EFATURA_CEVAPNO] [nvarchar](50) NULL,
	[EFATURAINDYOK] [bit] NULL,
	[EFATURA_LOG] [nvarchar](255) NULL,
	[EFATURA_SONGONTAR] [smalldatetime] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[ONLINE] [bit] NULL,
	[EDEVLETDURUM] [int] NULL,
	[EDEVLET_ILETIMYONTEMI] [nvarchar](20) NULL,
	[ONLINE_WEBADRES] [nvarchar](50) NULL,
	[ONLINE_ODEMESEKLI] [nvarchar](20) NULL,
	[ONLINE_ODEME_TARIHI] [smalldatetime] NULL,
	[ONLINE_GONDERIM_TARIHI] [smalldatetime] NULL,
	[ONLINE_GONDERIM_TASIYANTURU] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANKIMLIKNO] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANADI] [nvarchar](20) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[EFATURADURUM] [int] NULL,
	[EI_SATICIVKNO] [nvarchar](11) NULL,
	[EI_SATICIUNVAN] [nvarchar](250) NULL,
	[EI_ALICIVKNO] [nvarchar](11) NULL,
	[EI_ALICIUNVAN] [nvarchar](250) NULL,
	[EI_ISLEMBASLATANVKNO] [nvarchar](11) NULL,
	[EI_ISLEMBASLATANUNVAN] [nvarchar](250) NULL,
	[EI_TASIYICIVKNO] [nvarchar](11) NULL,
	[EI_ARACPLAKA] [nvarchar](20) NULL,
	[EI_DORSEPLAKA] [nvarchar](30) NULL,
	[EI_ARACSOFORADISOYADI] [nvarchar](100) NULL,
	[EI_ARACSOFORID] [nvarchar](20) NULL,
	[EI_TESLIMATTANIM] [nvarchar](50) NULL,
	[EI_TESLIMATADRES] [nvarchar](250) NULL,
	[EI_TESLIMATILCE] [nvarchar](50) NULL,
	[EI_TESLIMATIL] [nvarchar](50) NULL,
	[EI_TESLIMATULKE] [nvarchar](50) NULL,
	[EI_TASIYICIUNVAN] [nvarchar](250) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURA_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURA_TEMP](
	[FATID] [int] NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [smalldatetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [smalldatetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[DEL_DATE] [smalldatetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [smalldatetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [smalldatetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [smalldatetime] NOT NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [smalldatetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [smalldatetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[EFATTURU] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [smalldatetime] NULL,
	[IRSALIYENO] [nvarchar](500) NULL,
	[IRSALIYETARIHI] [smalldatetime] NULL,
	[EFATURAACIKLAMA] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[EFATURA_KABULREDNOTU] [nvarchar](255) NULL,
	[EFATNO] [nvarchar](16) NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[EFATURADURUM] [int] NULL,
	[EFATURAZARF] [uniqueidentifier] NULL,
	[UUID] [uniqueidentifier] NOT NULL,
	[EFATURA_ENTREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPTARIHI] [smalldatetime] NULL,
	[EFATURA_CEVAPACK] [nvarchar](150) NULL,
	[EFATURAACIKLAMA2] [nvarchar](250) NULL,
	[EFATURA_CEVAP_UUID] [uniqueidentifier] NULL,
	[EFATURA_CEVAPNO] [nvarchar](50) NULL,
	[EFATURAINDYOK] [bit] NULL,
	[EFATURA_LOG] [nvarchar](255) NULL,
	[EFATURA_SONGONTAR] [smalldatetime] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[ONLINE] [bit] NULL,
	[EDEVLETDURUM] [int] NULL,
	[EDEVLET_ILETIMYONTEMI] [nvarchar](20) NULL,
	[ONLINE_WEBADRES] [nvarchar](50) NULL,
	[ONLINE_ODEMESEKLI] [nvarchar](20) NULL,
	[ONLINE_ODEME_TARIHI] [smalldatetime] NULL,
	[ONLINE_GONDERIM_TARIHI] [smalldatetime] NULL,
	[ONLINE_GONDERIM_TASIYANTURU] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANKIMLIKNO] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANADI] [nvarchar](20) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[EI_SATICIVKNO] [nvarchar](11) NULL,
	[EI_SATICIUNVAN] [nvarchar](250) NULL,
	[EI_ALICIVKNO] [nvarchar](11) NULL,
	[EI_ALICIUNVAN] [nvarchar](250) NULL,
	[EI_ISLEMBASLATANVKNO] [nvarchar](11) NULL,
	[EI_ISLEMBASLATANUNVAN] [nvarchar](250) NULL,
	[EI_TASIYICIVKNO] [nvarchar](11) NULL,
	[EI_ARACPLAKA] [nvarchar](20) NULL,
	[EI_DORSEPLAKA] [nvarchar](30) NULL,
	[EI_ARACSOFORADISOYADI] [nvarchar](100) NULL,
	[EI_ARACSOFORID] [nvarchar](20) NULL,
	[EI_TESLIMATTANIM] [nvarchar](50) NULL,
	[EI_TESLIMATADRES] [nvarchar](250) NULL,
	[EI_TESLIMATILCE] [nvarchar](50) NULL,
	[EI_TESLIMATIL] [nvarchar](50) NULL,
	[EI_TESLIMATULKE] [nvarchar](50) NULL,
	[EI_TASIYICIUNVAN] [nvarchar](250) NULL,
	[FATID_V6] [int] NULL,
	[FIRMAID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURA_YEDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURA_YEDEK](
	[FATID] [int] IDENTITY(1,1) NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [datetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [datetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [datetime] NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [datetime] NULL,
	[IRSALIYENO] [nvarchar](50) NULL,
	[IRSALIYETARIHI] [datetime] NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[TINDEK] [float] NULL,
	[NTOPLAM] [float] NULL,
	[DNTOPLAM] [float] NULL,
	[FISTURADI] [nvarchar](30) NULL,
	[MODULID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURA59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURA59](
	[FATID] [int] NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [datetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [datetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [datetime] NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [datetime] NULL,
	[IRSALIYENO] [nvarchar](50) NULL,
	[IRSALIYETARIHI] [datetime] NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[TINDEK] [float] NULL,
	[NTOPLAM] [float] NULL,
	[DNTOPLAM] [float] NULL,
	[FISTURADI] [nvarchar](30) NULL,
	[MODULID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[OLDFATID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURADETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURADETAY59](
	[FATURADETAYID] [int] NOT NULL,
	[FATID] [int] NULL,
	[EFATNO] [nvarchar](16) NULL,
	[EFATURAACIKLAMA] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[EFATURA_KABULREDNOTU] [nvarchar](250) NULL,
	[EFATURA_ENTREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPTARIHI] [datetime] NULL,
	[EFATURA_CEVAPACK] [nvarchar](150) NULL,
	[EFATURAACIKLAMA2] [nvarchar](250) NULL,
	[EFATURA_CEVAP_UUID] [uniqueidentifier] NULL,
	[EFATURA_CEVAPNO] [nvarchar](50) NULL,
	[EFATURAINDYOK] [bit] NULL,
	[EFATURA_LOG] [nvarchar](250) NULL,
	[EFATURA_SONGONTAR] [datetime] NULL,
	[EFATTURU] [int] NULL,
	[EFATURADURUM] [int] NULL,
	[EDEVLETDURUM] [int] NULL,
	[EFATURAZARF] [uniqueidentifier] NULL,
	[UUID] [uniqueidentifier] NOT NULL,
	[EDEVLET_ILETIMYONTEMI] [nvarchar](20) NULL,
	[ONLINE] [bit] NULL,
	[ONLINE_WEBADRES] [nvarchar](50) NULL,
	[ONLINE_ODEMESEKLI] [nvarchar](20) NULL,
	[ONLINE_ODEME_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TASIYANTURU] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANKIMLIKNO] [nvarchar](15) NULL,
	[ONLINE_GONDERIM_TASIYANADI] [nvarchar](20) NULL,
	[EI_SATICIVKNO] [nvarchar](11) NULL,
	[EI_SATICIUNVAN] [nvarchar](150) NULL,
	[EI_ALICIVKNO] [nvarchar](20) NULL,
	[EI_ALICIUNVAN] [nvarchar](150) NULL,
	[EI_ISLEMBASLATANVKNO] [nvarchar](11) NULL,
	[EI_ISLEMBASLATANUNVAN] [nvarchar](150) NULL,
	[EI_TASIYICIVKNO] [nvarchar](11) NULL,
	[EI_TASIYICIUNVAN] [nvarchar](150) NULL,
	[EI_ARACPLAKA] [nvarchar](15) NULL,
	[EI_DORSEPLAKA] [nvarchar](20) NULL,
	[EI_ARACSOFORADISOYADI] [nvarchar](20) NULL,
	[EI_ARACSOFORID] [nvarchar](20) NULL,
	[EI_TESLIMATTANIM] [nvarchar](50) NULL,
	[EI_TESLIMATADRES] [nvarchar](250) NULL,
	[EI_TESLIMATILCE] [nvarchar](30) NULL,
	[EI_TESLIMATIL] [nvarchar](30) NULL,
	[EI_TESLIMATULKE] [nvarchar](50) NULL,
	[EFATURA_IBAN] [nvarchar](26) NULL,
	[EI_TASIYICIPOSTAKUTUSU] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURAEK59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAEK59](
	[FATURAEKID] [int] NOT NULL,
	[FATID] [int] NULL,
	[STOKID] [int] NULL,
	[GBEYANNO] [nvarchar](50) NULL,
	[GBEYANTARIHI] [smalldatetime] NULL,
	[GMAKBUZNO] [nvarchar](20) NULL,
	[GMAKBUZTARIHI] [smalldatetime] NULL,
	[GIRISGUMRUK] [nvarchar](150) NULL,
	[ALISYAPILANFIRMA] [nvarchar](150) NULL,
	[ALISFNO] [nvarchar](20) NULL,
	[ALISFTARIHI] [smalldatetime] NULL,
	[MODELYILI] [smallint] NULL,
	[SASINO] [nvarchar](30) NULL,
	[MOTORNO] [nvarchar](30) NULL,
	[RENK] [nvarchar](20) NULL,
	[SILINDIRHACMI] [nvarchar](20) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURAIRSALIYE59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAIRSALIYE59](
	[FATIRSID] [int] NULL,
	[FATID] [int] NULL,
	[IRSALIYENO] [nvarchar](50) NULL,
	[IRSALIYETARIHI] [datetime] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURAVERGI59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAVERGI59](
	[FATURAVERGIID] [int] NOT NULL,
	[FATID] [int] NULL,
	[VERGIID] [int] NULL,
	[HESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ORAN] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FATURAX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FATURAX](
	[FATID] [int] NOT NULL,
	[FATNO] [nvarchar](20) NULL,
	[TARIH] [datetime] NULL,
	[FISDURUMID] [int] NULL,
	[FISTURID] [int] NULL,
	[TUR] [int] NULL,
	[SUBEID] [int] NULL,
	[BAYIID] [int] NULL,
	[SATISTID] [int] NULL,
	[DEPOID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[PROJEID] [int] NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ACIKLAMA2] [nvarchar](500) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](200) NULL,
	[ADRES3] [nvarchar](50) NULL,
	[VD] [nvarchar](100) NULL,
	[VDNO] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](5) NULL,
	[UNVANI] [nvarchar](200) NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[OZELKOD2] [nvarchar](20) NULL,
	[OZELKOD3] [nvarchar](20) NULL,
	[VADE] [datetime] NULL,
	[SIND] [float] NULL,
	[EKORAN3] [float] NULL,
	[EKORAN2] [float] NULL,
	[EKORAN1] [float] NULL,
	[INDORAN3] [float] NULL,
	[INDORAN1] [float] NULL,
	[INDORAN2] [float] NULL,
	[IND1] [float] NULL,
	[IND2] [float] NULL,
	[IND3] [float] NULL,
	[EK1] [float] NULL,
	[EK2] [float] NULL,
	[EK3] [float] NULL,
	[GTOPLAM] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[DTOPLAM] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[IRSALIYE] [bit] NULL,
	[YAZONAY] [bit] NULL,
	[MUHFC] [int] NULL,
	[DEPOFISID] [int] NULL,
	[MODUL] [int] NULL,
	[FATSERI] [nvarchar](5) NULL,
	[MFATID] [int] NULL,
	[AKTARILDI] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[IPTALACIKLAMA] [nvarchar](100) NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[ODENENTUTAR] [float] NULL,
	[VERGITOPLAM] [float] NULL,
	[FISIVAR] [bit] NULL,
	[BABSHARIC] [bit] NULL,
	[ALTCARIID] [int] NULL,
	[FATKDVDETAYLI] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[ODENMEYEN3] [float] NULL,
	[DKAPANAN] [float] NULL,
	[CARIID2] [int] NULL,
	[INDHESAPID] [int] NULL,
	[HESAPID] [int] NULL,
	[FATCOUNTER] [int] NULL,
	[KTARIH] [datetime] NULL,
	[TADET] [int] NULL,
	[KURUMTIPI] [int] NULL,
	[SAAT] [datetime] NULL,
	[FATTUR] [nvarchar](15) NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[FIPTALACIKLAMA] [nvarchar](200) NULL,
	[FIPTALKULLANICI] [nvarchar](20) NULL,
	[FIPTALTARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[FIPTAL] [int] NULL,
	[ODEMEALTCARIID] [int] NULL,
	[MASADURUMID] [int] NULL,
	[MASANO] [nvarchar](50) NULL,
	[ODEMEHESAPID2] [int] NULL,
	[ODENENTUTAR2] [float] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[EFATTURU] [int] NULL,
	[ODEMEALTCARIID2] [int] NULL,
	[VERGIMASMERATA] [bit] NULL,
	[WEB] [nvarchar](100) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[TEVKIFATTOPLAM] [float] NULL,
	[SIPARISNO] [nvarchar](100) NULL,
	[SIPARISTARIHI] [datetime] NULL,
	[IRSALIYENO] [nvarchar](500) NULL,
	[IRSALIYETARIHI] [datetime] NULL,
	[EFATURAACIKLAMA] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[EFATURA_KABULREDNOTU] [nvarchar](255) NULL,
	[EFATNO] [nvarchar](16) NULL,
	[FATURAGELDI] [int] NULL,
	[FARKFATURASI] [bit] NULL,
	[CLTUTAR] [float] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[BABSTUTAR] [float] NULL,
	[GOREVLI1] [nvarchar](50) NULL,
	[GOREV1] [nvarchar](50) NULL,
	[YETKI1] [nvarchar](50) NULL,
	[GOREVLI2] [nvarchar](50) NULL,
	[GOREV2] [nvarchar](50) NULL,
	[YETKI2] [nvarchar](50) NULL,
	[EFATURAZARF] [uniqueidentifier] NULL,
	[UUID] [uniqueidentifier] NOT NULL,
	[EFATURA_ENTREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPREFNO] [nvarchar](100) NULL,
	[EFATURA_CEVAPTARIHI] [datetime] NULL,
	[EFATURA_CEVAPACK] [nvarchar](150) NULL,
	[EFATURAACIKLAMA2] [nvarchar](250) NULL,
	[EFATURA_CEVAP_UUID] [uniqueidentifier] NULL,
	[EFATURA_CEVAPNO] [nvarchar](50) NULL,
	[EFATURAINDYOK] [bit] NULL,
	[EFATURA_LOG] [nvarchar](255) NULL,
	[EFATURA_SONGONTAR] [datetime] NULL,
	[KDVACIKLAMA] [nvarchar](100) NULL,
	[EVRAKSIRANO] [nvarchar](15) NULL,
	[FATSERINO] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[KDVSIZLIKKODU] [nvarchar](20) NULL,
	[ONLINE] [bit] NULL,
	[EDEVLETDURUM] [int] NULL,
	[EDEVLET_ILETIMYONTEMI] [nvarchar](20) NULL,
	[ONLINE_WEBADRES] [nvarchar](50) NULL,
	[ONLINE_ODEMESEKLI] [nvarchar](20) NULL,
	[ONLINE_ODEME_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TARIHI] [datetime] NULL,
	[ONLINE_GONDERIM_TASIYANTURU] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANKIMLIKNO] [nvarchar](20) NULL,
	[ONLINE_GONDERIM_TASIYANADI] [nvarchar](20) NULL,
	[EFATURADURUM] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FAVORIEKRAN]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FAVORIEKRAN](
	[FAVORIEKRANID] [int] IDENTITY(1,1) NOT NULL,
	[EKRANID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
 CONSTRAINT [PK_FAVORIEKRAN] PRIMARY KEY CLUSTERED 
(
	[FAVORIEKRANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMABARKOD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMABARKOD](
	[FIRMABARKODID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BARKOD] [bigint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[TUR] [nvarchar](15) NULL,
	[KONTROLNO] [smallint] NULL,
 CONSTRAINT [PK_FIRMABARKOD] PRIMARY KEY CLUSTERED 
(
	[FIRMABARKODID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMABARKOD59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMABARKOD59](
	[FIRMABARKODID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BARKOD] [bigint] NULL,
	[KONTROLNO] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[TUR] [nvarchar](15) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMAISLEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMAISLEM](
	[FIRMAISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[FISTURID] [int] NULL,
	[BELGENO] [nvarchar](30) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[TUTAR] [float] NULL,
	[DTUTAR] [float] NULL,
	[BORC] [float] NULL,
	[ALACAK] [float] NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_FIRMAISLEM] PRIMARY KEY CLUSTERED 
(
	[FIRMAISLEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMALAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMALAR](
	[FIRMAID] [int] NOT NULL,
	[FIRMAKODU] [nvarchar](20) NULL,
	[UNVANI] [nvarchar](250) NULL,
	[ADRES1] [nvarchar](250) NULL,
	[ADRES2] [nvarchar](150) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[ULKE] [nvarchar](30) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](11) NULL,
	[FIRMAYETKILI] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[ISTEL] [nvarchar](20) NULL,
	[UYELIKTARIHI] [smalldatetime] NULL,
	[UYELIKBITIS] [smalldatetime] NULL,
	[UYARIMESAJI] [nvarchar](250) NULL,
	[BAYIID] [int] NULL,
	[BAYIMI] [bit] NULL,
	[GUNCELMI] [bit] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[UYELIKACIKLAMA] [nvarchar](250) NULL,
	[DEMOMODU] [bit] NULL,
	[DEMOBITISTARIH] [smalldatetime] NULL,
	[GERCEKSATIS] [bit] NULL,
	[KVKKONAY] [bit] NULL,
	[BILGISAYARMAC] [nvarchar](30) NULL,
	[DISIP] [nvarchar](20) NULL,
	[DBNAME] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[YETKILIGOREV] [nvarchar](30) NULL,
	[FIRMAUUID] [uniqueidentifier] NULL,
	[DBTURU] [bit] NULL,
	[YERELSQLSTR] [nvarchar](250) NULL,
	[UZAKSQLSTR] [nvarchar](250) NULL,
	[YERELSQL] [nvarchar](40) NULL,
	[YERELSQLUSER] [nvarchar](20) NULL,
	[YERELSQLPASS] [nvarchar](30) NULL,
	[YERELSQLDB] [nvarchar](50) NULL,
	[UZAKSQL] [nvarchar](40) NULL,
	[MOBILSQLIP] [nvarchar](40) NULL,
	[MODUL_MUH] [bit] NULL,
	[MODUL_POS] [bit] NULL,
	[MODUL_MAR] [bit] NULL,
	[MODUL_ELK] [bit] NULL,
	[MODUL_UYG] [bit] NULL,
	[MODUL_GEN] [bit] NULL,
	[IYZICOURL] [nvarchar](100) NULL,
	[IYZICOAPI] [nvarchar](100) NULL,
	[IYZICOKEY] [nvarchar](100) NULL,
	[DIGERAPI] [nvarchar](100) NULL,
	[DIGERKEY] [nvarchar](100) NULL,
	[GRUPFIRMAID] [int] NULL,
	[GRUPFIRMAMI] [bit] NULL,
 CONSTRAINT [PK_FIRMALAR] PRIMARY KEY CLUSTERED 
(
	[FIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_FIRMALAR] UNIQUE NONCLUSTERED 
(
	[FIRMAKODU] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMALAR_19052022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMALAR_19052022](
	[FIRMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAKODU] [nvarchar](20) NULL,
	[UNVANI] [nvarchar](250) NULL,
	[ADRES1] [nvarchar](250) NULL,
	[ADRES2] [nvarchar](150) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[ULKE] [nvarchar](30) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](11) NULL,
	[FIRMAYETKILI] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[ISTEL] [nvarchar](20) NULL,
	[UYELIKTARIHI] [smalldatetime] NULL,
	[UYELIKBITIS] [smalldatetime] NULL,
	[UYARIMESAJI] [nvarchar](250) NULL,
	[BAYIID] [int] NULL,
	[BAYIMI] [bit] NULL,
	[GUNCELMI] [bit] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[UYELIKACIKLAMA] [nvarchar](250) NULL,
	[DEMOMODU] [bit] NULL,
	[DEMOBITISTARIH] [smalldatetime] NULL,
	[GERCEKSATIS] [bit] NULL,
	[KVKKONAY] [bit] NULL,
	[BILGISAYARMAC] [nvarchar](30) NULL,
	[DISIP] [nvarchar](20) NULL,
	[DBNAME] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[YETKILIGOREV] [nvarchar](30) NULL,
	[FIRMAUUID] [uniqueidentifier] NULL,
	[DBTURU] [bit] NULL,
	[YERELSQLSTR] [nvarchar](250) NULL,
	[UZAKSQLSTR] [nvarchar](250) NULL,
	[YERELSQL] [nvarchar](40) NULL,
	[YERELSQLUSER] [nvarchar](20) NULL,
	[YERELSQLPASS] [nvarchar](30) NULL,
	[YERELSQLDB] [nvarchar](50) NULL,
	[UZAKSQL] [nvarchar](40) NULL,
	[MOBILSQLIP] [nvarchar](40) NULL,
	[MODUL_MUH] [bit] NULL,
	[MODUL_POS] [bit] NULL,
	[MODUL_MAR] [bit] NULL,
	[MODUL_ELK] [bit] NULL,
	[MODUL_UYG] [bit] NULL,
	[MODUL_GEN] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMALAR_27042022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMALAR_27042022](
	[FIRMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAKODU] [nvarchar](20) NULL,
	[UNVANI] [nvarchar](250) NULL,
	[ADRES1] [nvarchar](250) NULL,
	[ADRES2] [nvarchar](150) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[ULKE] [nvarchar](30) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](11) NULL,
	[FIRMAYETKILI] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[ISTEL] [nvarchar](20) NULL,
	[UYELIKTARIHI] [smalldatetime] NULL,
	[UYELIKBITIS] [smalldatetime] NULL,
	[UYARIMESAJI] [nvarchar](250) NULL,
	[BAYIID] [int] NULL,
	[BAYIMI] [bit] NULL,
	[GUNCELMI] [bit] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[UYELIKACIKLAMA] [nvarchar](250) NULL,
	[DEMOMODU] [bit] NULL,
	[DEMOBITISTARIH] [smalldatetime] NULL,
	[GERCEKSATIS] [bit] NULL,
	[KVKKONAY] [bit] NULL,
	[BILGISAYARMAC] [nvarchar](30) NULL,
	[DISIP] [nvarchar](20) NULL,
	[DBNAME] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[YETKILIGOREV] [nvarchar](30) NULL,
	[FIRMAUUID] [uniqueidentifier] NULL,
	[DBTURU] [bit] NULL,
	[YERELSQLSTR] [nvarchar](250) NULL,
	[UZAKSQLSTR] [nvarchar](250) NULL,
	[YERELSQL] [nvarchar](40) NULL,
	[YERELSQLUSER] [nvarchar](20) NULL,
	[YERELSQLPASS] [nvarchar](30) NULL,
	[YERELSQLDB] [nvarchar](50) NULL,
	[UZAKSQL] [nvarchar](40) NULL,
	[MOBILSQLIP] [nvarchar](40) NULL,
	[MODUL_MUH] [bit] NULL,
	[MODUL_POS] [bit] NULL,
	[MODUL_MAR] [bit] NULL,
	[MODUL_ELK] [bit] NULL,
	[MODUL_UYG] [bit] NULL,
	[MODUL_GEN] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMALAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMALAR59](
	[FIRMAID] [int] NOT NULL,
	[FIRMAKODU] [nvarchar](20) NULL,
	[UNVANI] [nvarchar](250) NULL,
	[ADRES1] [nvarchar](250) NULL,
	[ADRES2] [nvarchar](150) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[ULKE] [nvarchar](30) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](11) NULL,
	[FIRMAYETKILI] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[ISTEL] [nvarchar](20) NULL,
	[UYELIKTARIHI] [smalldatetime] NULL,
	[UYELIKBITIS] [smalldatetime] NULL,
	[UYARIMESAJI] [nvarchar](250) NULL,
	[BAYIID] [int] NULL,
	[BAYIMI] [bit] NULL,
	[GUNCELMI] [bit] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[UYELIKACIKLAMA] [nvarchar](250) NULL,
	[DEMOMODU] [bit] NULL,
	[DEMOBITISTARIH] [smalldatetime] NULL,
	[GERCEKSATIS] [bit] NULL,
	[KVKKONAY] [bit] NULL,
	[BILGISAYARMAC] [nvarchar](30) NULL,
	[DISIP] [nvarchar](20) NULL,
	[DBNAME] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[YETKILIGOREV] [nvarchar](30) NULL,
	[FIRMAUUID] [uniqueidentifier] NULL,
	[DBTURU] [bit] NULL,
	[YERELSQLSTR] [nvarchar](250) NULL,
	[UZAKSQLSTR] [nvarchar](250) NULL,
	[YERELSQL] [nvarchar](40) NULL,
	[YERELSQLUSER] [nvarchar](20) NULL,
	[YERELSQLPASS] [nvarchar](30) NULL,
	[YERELSQLDB] [nvarchar](50) NULL,
	[UZAKSQL] [nvarchar](40) NULL,
	[MOBILSQLIP] [nvarchar](40) NULL,
	[MODUL_MUH] [bit] NULL,
	[MODUL_POS] [bit] NULL,
	[MODUL_MAR] [bit] NULL,
	[MODUL_ELK] [bit] NULL,
	[MODUL_UYG] [bit] NULL,
	[MODUL_GEN] [bit] NULL,
	[GRUPFIRMAID] [int] NULL,
	[GRUPFIRMAMI] [bit] NULL,
	[IYZICOAPI] [nvarchar](100) NULL,
	[IYZICOKEY] [nvarchar](100) NULL,
	[DIGERAPI] [nvarchar](100) NULL,
	[DIGERKEY] [nvarchar](100) NULL,
	[IYZICOURL] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMAMODUL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMAMODUL](
	[FIRMAMODULID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[EKRANID] [int] NULL,
	[IMAGEINDEX] [int] NULL,
	[AKTIF] [bit] NULL,
 CONSTRAINT [PK_FIRMAMODUL] PRIMARY KEY CLUSTERED 
(
	[FIRMAMODULID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMAMODUL_27042022]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMAMODUL_27042022](
	[FIRMAMODULID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[EKRANID] [int] NULL,
	[IMAGEINDEX] [int] NULL,
	[AKTIF] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FIRMAMODUL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FIRMAMODUL59](
	[FIRMAMODULID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[EKRANID] [int] NULL,
	[IMAGEINDEX] [int] NULL,
	[AKTIF] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[FTPBILGI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FTPBILGI](
	[FTPBILGIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[SUNUCU] [nvarchar](50) NULL,
	[KULLANICI] [nvarchar](50) NULL,
	[SIFRE] [nvarchar](50) NULL,
	[PORT] [nvarchar](5) NULL,
	[FTPKLASOR] [nvarchar](250) NULL,
	[INDIRMEKLASOR] [nvarchar](250) NULL,
	[TUMSISTEMICIN] [bit] NULL,
	[YUKLEMETURU] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_FTPBILGI] PRIMARY KEY CLUSTERED 
(
	[FTPBILGIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GARSON59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GARSON59](
	[GARSONID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[GKODU] [nvarchar](15) NOT NULL,
	[GADI] [nvarchar](25) NULL,
	[GSIFRE] [nvarchar](50) NULL,
	[DEPKODU] [nvarchar](200) NULL,
	[GYETKI] [nvarchar](50) NULL,
	[GGRUPID] [int] NULL,
	[GARSONRESIM] [image] NULL,
	[SIFRESOR] [bit] NULL,
	[GARSONPRIM] [float] NULL,
	[SIL] [smallint] NULL,
	[GHESAPID] [int] NULL,
	[TELEFON] [nvarchar](30) NULL,
	[ADRES] [nvarchar](150) NULL,
	[PAKETCI] [bit] NULL,
	[YAZARKASASIRA] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEPKODUX] [nvarchar](20) NULL,
	[YINDIRIM] [bit] NULL,
	[YADISYONYAZ] [bit] NULL,
	[YHESAPAL] [bit] NULL,
	[YODEMESIL] [bit] NULL,
	[YODEMEDUZELT] [bit] NULL,
	[YGUNSONU] [bit] NULL,
	[YRAPORLAR] [bit] NULL,
	[YMASAAKTAR] [bit] NULL,
	[YYEMEKSEPETI] [bit] NULL,
	[YYEMEKSEPETIRED] [bit] NULL,
	[YYEMEKSEPETIKABUL] [bit] NULL,
	[YCALLERID] [bit] NULL,
	[YISLEMMENU] [bit] NULL,
	[YADISYONGOR] [bit] NULL,
	[YADISYONDUZELT] [bit] NULL,
	[YADISYONYAZDIR] [bit] NULL,
	[YRENKSECENEK] [bit] NULL,
	[YUYECARI] [bit] NULL,
	[YFIYATGUNCELLE] [bit] NULL,
	[YMIKTARGIRIS] [bit] NULL,
	[YSAYIM] [bit] NULL,
	[YGMP3] [bit] NULL,
	[YACIKSATIS] [bit] NULL,
	[YRESIMDEGISTIR] [bit] NULL,
	[YXRAPORU] [bit] NULL,
	[YZRAPORU] [bit] NULL,
	[YGUNGERIALMA] [bit] NULL,
	[YGUNKAPATMA] [bit] NULL,
	[YIADE] [bit] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GELIRGRUP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GELIRGRUP](
	[GGID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](5) NULL,
	[ADI] [nvarchar](50) NULL,
	[MUHHESAP1] [nvarchar](18) NULL,
	[MUHHESAP2] [nvarchar](18) NULL,
	[MUHHESAP3] [nvarchar](18) NULL,
	[MUHHESAP4] [nvarchar](18) NULL,
	[KDV] [int] NULL,
	[MUHHESAP5] [nvarchar](18) NULL,
	[DEPARTMAN] [nvarchar](50) NULL,
	[KDVMUHHESAP] [int] NULL,
	[IADEKDVMUHHESAP] [int] NULL,
	[KDV2] [float] NULL,
	[BARKOD] [nvarchar](20) NULL,
	[MERKEZGGKODU] [nvarchar](5) NULL,
	[EKKDV] [int] NULL,
	[EKKDV2] [int] NULL,
	[SIL] [smallint] NULL,
	[OKCKDVID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [IX_GELIRGRUP] UNIQUE NONCLUSTERED 
(
	[GGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GENELNOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GENELNOT](
	[GENELNOTID] [int] IDENTITY(1,1) NOT NULL,
	[TABLO] [nvarchar](30) NULL,
	[TABLOID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[KONU] [nvarchar](50) NULL,
	[BELGENO] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERI] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_GENELNOT] PRIMARY KEY CLUSTERED 
(
	[GENELNOTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GETIRYEMEK_Siparis]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GETIRYEMEK_Siparis](
	[recid] [int] IDENTITY(1,1) NOT NULL,
	[firmaId] [int] NOT NULL,
	[subeId] [int] NOT NULL,
	[id] [nvarchar](50) NOT NULL,
	[status] [int] NULL,
	[isScheduled] [bit] NULL,
	[confirmationId] [nvarchar](50) NULL,
	[clientNote] [nvarchar](200) NULL,
	[totalprice] [float] NULL,
	[totalDiscountedPrice] [float] NULL,
	[checkoutDate] [datetime] NULL,
	[scheduledDate] [datetime] NULL,
	[verifyDate] [datetime] NULL,
	[scheduleVerifiedDate] [datetime] NULL,
	[prepareDate] [datetime] NULL,
	[handoverDate] [datetime] NULL,
	[reachDate] [datetime] NULL,
	[deliverDate] [datetime] NULL,
	[deliveryType] [int] NULL,
	[isEcoFriendly] [bit] NULL,
	[doNotKnock] [bit] NULL,
	[paymentMethod] [int] NULL,
	[paymentMethodText] [nvarchar](50) NULL,
	[cancelNote] [nvarchar](200) NULL,
	[cancelReason] [nvarchar](200) NULL,
 CONSTRAINT [PK_GETIRYEMEK_Siparis_1] PRIMARY KEY CLUSTERED 
(
	[recid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GETIRYEMEK_Siparis_Kurye]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GETIRYEMEK_Siparis_Kurye](
	[recid] [int] IDENTITY(1,1) NOT NULL,
	[siprecid] [int] NULL,
	[sipid] [nvarchar](50) NOT NULL,
	[id] [nvarchar](50) NOT NULL,
	[status] [int] NULL,
	[name] [nvarchar](50) NULL,
 CONSTRAINT [PK_GETIRYEMEK_Siparis_Kurye] PRIMARY KEY CLUSTERED 
(
	[recid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GETIRYEMEK_Siparis_Musteri]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GETIRYEMEK_Siparis_Musteri](
	[recid] [int] NOT NULL,
	[siprecid] [int] IDENTITY(1,1) NOT NULL,
	[sipid] [nvarchar](50) NOT NULL,
	[id] [nvarchar](50) NOT NULL,
	[name] [nvarchar](100) NULL,
	[clientPhoneNumber] [nvarchar](50) NULL,
	[clientUnmaskedPhoneNumber] [nvarchar](50) NULL,
	[contactPhoneNumber] [nvarchar](50) NULL,
	[adress] [nvarchar](100) NULL,
	[aptNo] [nvarchar](50) NULL,
	[floor] [nvarchar](50) NULL,
	[doorno] [nvarchar](50) NULL,
	[city] [nvarchar](50) NULL,
	[district] [nvarchar](50) NULL,
	[description] [nvarchar](50) NULL,
 CONSTRAINT [PK_GETIRYEMEK_Siparis_Musteri] PRIMARY KEY CLUSTERED 
(
	[recid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GETIRYEMEK_Siparis_Urun]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GETIRYEMEK_Siparis_Urun](
	[recid] [int] IDENTITY(1,1) NOT NULL,
	[siprecid] [int] NULL,
	[sipid] [nvarchar](50) NOT NULL,
	[id] [nvarchar](50) NOT NULL,
	[count] [float] NULL,
	[product] [nvarchar](100) NULL,
	[chainProduct] [nvarchar](100) NULL,
	[name] [nvarchar](100) NULL,
	[price] [float] NULL,
	[optionPrice] [float] NULL,
	[priceWithoption] [float] NULL,
	[totalPrice] [float] NULL,
	[totalOptionPrice] [float] NULL,
	[totalPriceWithOption] [float] NULL,
	[note] [nvarchar](250) NULL,
 CONSTRAINT [PK_GETIRYEMEK_Siparis_Urun] PRIMARY KEY CLUSTERED 
(
	[recid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GETIRYEMEK_UrunEslem]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GETIRYEMEK_UrunEslem](
	[firmaId] [int] NOT NULL,
	[gtry_productid] [nvarchar](50) NOT NULL,
	[gtry_urunadi] [nvarchar](150) NULL,
	[novaid] [nvarchar](50) NULL,
 CONSTRAINT [PK_GETIRYEMEK_UrunEslem] PRIMARY KEY CLUSTERED 
(
	[firmaId] ASC,
	[gtry_productid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GUNSONU]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GUNSONU](
	[GUNSONUID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[SAAT] [datetime] NULL,
	[USERID] [int] NULL,
	[GARSONID] [int] NULL,
	[RAPOR] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
 CONSTRAINT [PK_GUNSONU] PRIMARY KEY CLUSTERED 
(
	[GUNSONUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HESAP_ELITE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HESAP_ELITE](
	[HESAPID] [float] NULL,
	[KODU] [nvarchar](255) NULL,
	[ACIKLAMA] [nvarchar](255) NULL,
	[HESAPTIPID] [float] NULL,
	[VD] [nvarchar](255) NULL,
	[VDNO] [nvarchar](255) NULL,
	[ADRES] [nvarchar](255) NULL,
	[ADRES2] [nvarchar](255) NULL,
	[YETKILI] [nvarchar](255) NULL,
	[YETKILI1] [nvarchar](255) NULL,
	[FAKS] [nvarchar](255) NULL,
	[FAKS2] [nvarchar](255) NULL,
	[GSM] [nvarchar](255) NULL,
	[GOREVI] [nvarchar](255) NULL,
	[BANKASUBE] [nvarchar](255) NULL,
	[BANKAKODU] [nvarchar](255) NULL,
	[BANKAHESAP] [nvarchar](255) NULL,
	[BANKAIBAN] [nvarchar](255) NULL,
	[BANKAFIRMA] [nvarchar](255) NULL,
	[DOVIZ] [nvarchar](255) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSFIRMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSFIRMA](
	[HSFIRMAID] [int] IDENTITY(1,1) NOT NULL,
	[UNVANI] [nvarchar](150) NULL,
	[ADRES] [nvarchar](150) NULL,
	[YETKILI] [nvarchar](150) NULL,
	[TEL] [nvarchar](20) NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](20) NULL,
	[DISIP] [nvarchar](20) NULL,
	[AKTIF] [bit] NULL,
	[QKOD] [nvarchar](250) NULL,
	[ANABAYI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_HSFIRMA] PRIMARY KEY CLUSTERED 
(
	[HSFIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSPAKET]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSPAKET](
	[HSPAKETID] [int] IDENTITY(1,1) NOT NULL,
	[HSPAKETFISID] [int] NULL,
	[YUKLEMETARIH] [smalldatetime] NULL,
	[GUNSAYISI] [int] NULL,
	[CSVKODU] [nvarchar](20) NULL,
	[QRKOD] [nvarchar](250) NULL,
	[SATILDI] [bit] NULL,
 CONSTRAINT [PK_HSPAKET] PRIMARY KEY CLUSTERED 
(
	[HSPAKETID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSPAKETFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSPAKETFIS](
	[HSPAKETFISID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GUN] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_HSPAKETFIS] PRIMARY KEY CLUSTERED 
(
	[HSPAKETFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSPAKETFIYAT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSPAKETFIYAT](
	[HSPAKETFIYATID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ILKTARIH] [smalldatetime] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[GUNSAYISI] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[FIYATI] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_HSPAKETFIYAT] PRIMARY KEY CLUSTERED 
(
	[HSPAKETFIYATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSPAKETSATIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSPAKETSATIS](
	[HSPAKETSATISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[ODANO] [nvarchar](10) NULL,
	[MISAFIR] [nvarchar](30) NULL,
	[SATISUSERID] [int] NULL,
	[CSVKODU] [nvarchar](20) NULL,
	[QRKOD] [nvarchar](250) NULL,
	[GUNSAYISI] [int] NULL,
	[FIYAT] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[BELGENO] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[SATILDI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_HSPAKETSATIS] PRIMARY KEY CLUSTERED 
(
	[HSPAKETSATISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[HSUSER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HSUSER](
	[HSUSERID] [int] IDENTITY(1,1) NOT NULL,
	[HSFIRMAID] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[SIFRESI] [nvarchar](20) NULL,
	[AKTIF] [bit] NULL,
	[FIRMAYETKISI] [bit] NULL,
	[PAKETTANIM] [bit] NULL,
	[PAKETYUKLEME] [bit] NULL,
	[PAKETSATIS] [bit] NULL,
	[KULLANICIEKLEME] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_HSUSER] PRIMARY KEY CLUSTERED 
(
	[HSUSERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKMESAIMAIL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKMESAIMAIL](
	[IKMESAIMAILID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[YENIKAYIT_MAIL] [nvarchar](150) NULL,
	[YENIKAYIT_YAZI] [nvarchar](250) NULL,
	[ONAY_MAIL] [nvarchar](150) NULL,
	[ONAY_YAZI] [nvarchar](250) NULL,
	[OPRONAY_MAIL] [nvarchar](150) NULL,
	[OPRONAY_YAZI] [nvarchar](250) NULL,
	[DUZELTME_MAIL] [nvarchar](150) NULL,
	[DUZELTME_YAZI] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKMESAIMAIL] PRIMARY KEY CLUSTERED 
(
	[IKMESAIMAILID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKPERSONEL_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKPERSONEL_TEMP](
	[IKPERSONEL_TEMPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FIRMA] [int] NULL,
	[PSICILID] [int] NULL,
	[AD] [nvarchar](20) NULL,
	[SOYAD] [nvarchar](20) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[UNVANID] [int] NULL,
	[DEPARTMANID] [int] NULL,
	[DEPKODU] [nvarchar](10) NULL,
	[CALISIYOR] [int] NULL,
	[GOREVI] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[MAXMESAI] [float] NULL,
	[TCKIMLIKNO] [nvarchar](11) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[OZELKOD3] [nvarchar](50) NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_IKPERSONEL_TEMP] PRIMARY KEY CLUSTERED 
(
	[IKPERSONEL_TEMPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IKVARDIYADETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IKVARDIYADETAY](
	[IKVARDIYADETAYID] [int] IDENTITY(1,1) NOT NULL,
	[IKVARDIYAID] [int] NULL,
	[PSICILID] [int] NULL,
	[IKVARDIYATANIMID] [int] NULL,
	[GUN1] [int] NULL,
	[GUN2] [int] NULL,
	[GUN3] [int] NULL,
	[GUN4] [int] NULL,
	[GUN5] [int] NULL,
	[GUN6] [int] NULL,
	[GUN7] [int] NULL,
	[CALISMAGUN] [float] NULL,
	[DIGERGUN] [float] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[ISEGIRIS] [smalldatetime] NULL,
 CONSTRAINT [PK_IKVARDIYADETAY] PRIMARY KEY CLUSTERED 
(
	[IKVARDIYADETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [UX_IKVARDIYADETAY] UNIQUE NONCLUSTERED 
(
	[IKVARDIYAID] ASC,
	[PSICILID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[IndexMaintenanceLog]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IndexMaintenanceLog](
	[LogID] [int] IDENTITY(1,1) NOT NULL,
	[LogDate] [datetime] NOT NULL,
	[SchemaName] [sysname] NULL,
	[TableName] [sysname] NULL,
	[IndexName] [sysname] NULL,
	[FragmentationPercent] [decimal](8, 2) NULL,
	[PageCount] [bigint] NULL,
	[OperationType] [varchar](40) NULL,
	[Status] [varchar](20) NULL,
	[ErrorMessage] [nvarchar](max) NULL,
	[SqlCommand] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED 
(
	[LogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KDVTANIM_ARS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KDVTANIM_ARS](
	[KDVTANIMID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ORAN] [float] NULL,
	[ALKOLLU] [int] NULL,
	[ALISHESAPID] [int] NULL,
	[ALISIADEHESAPID] [int] NULL,
	[SATISHESAPID] [int] NULL,
	[SATISIADEHESAPID] [int] NULL,
	[TEVKALISHESAPID] [int] NULL,
	[TEVKSATISHESAPID] [int] NULL,
	[TEVKALISIADEHESAPID] [int] NULL,
	[TEVKSATISIADEHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[GELIRENTKONTROLHESABIID] [int] NULL,
	[GELIRENTKONTROLIADEHESAPID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KREDITUR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KREDITUR](
	[KREDITURID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KREDITURU] [nvarchar](50) NULL,
	[KKDFORANI] [float] NULL,
	[BSMVORANI] [float] NULL,
	[KKDFHESAPID] [int] NULL,
	[BSMVHESAPID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_KREDITUR] PRIMARY KEY CLUSTERED 
(
	[KREDITURID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KYKTANIM_NOK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KYKTANIM_NOK](
	[KYKTANIMID] [int] NOT NULL,
	[ACIKLAMA] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[BASLANGIC] [sql_variant] NULL,
	[BITIS] [sql_variant] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MASALAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MASALAR](
	[MASAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[MASANO] [nvarchar](50) NOT NULL,
	[KISIS] [int] NULL,
	[STATU] [int] NULL,
	[XPOS] [int] NULL,
	[YPOS] [int] NULL,
	[MASAGRUP] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[DEPART] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DEPID] [int] NULL,
 CONSTRAINT [PK_MASALAR] PRIMARY KEY CLUSTERED 
(
	[MASAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MASALAR] UNIQUE NONCLUSTERED 
(
	[MASAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MASALAR_ALI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MASALAR_ALI](
	[MASAID] [int] NOT NULL,
	[DEPART] [nvarchar](50) NOT NULL,
	[MASANO] [nvarchar](50) NOT NULL,
	[KISIS] [int] NULL,
	[STATU] [int] NULL,
	[XPOS] [int] NULL,
	[YPOS] [int] NULL,
	[MASAGRUP] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MASALAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MASALAR59](
	[MASAID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[MASANO] [nvarchar](50) NOT NULL,
	[KISIS] [int] NULL,
	[STATU] [int] NULL,
	[XPOS] [int] NULL,
	[YPOS] [int] NULL,
	[MASAGRUP] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[DEPART] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DEPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKAEKSTRE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKAEKSTRE](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[HESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TARIHBAS] [smalldatetime] NULL,
	[TARIHSON] [smalldatetime] NULL,
	[MASRAF] [float] NULL,
	[ALTCARIID] [int] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[BANKAID] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[OLDID] [int] NULL,
 CONSTRAINT [PK_MUH_BANKAEKSTRE] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_BANKAEKSTRE] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKAEKSTRE_DETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKAEKSTRE_DETAY](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[BANKAEKSTREID] [int] NULL,
	[TARIH] [datetime] NULL,
	[SUBEID] [int] NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](50) NULL,
	[TUTAR] [decimal](18, 2) NULL,
	[ANAHTAR] [nvarchar](100) NULL,
	[KARSIHESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[FISID] [int] NULL,
	[KUR] [float] NULL,
	[AKTARMA] [bit] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[CEKID] [int] NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[FISACIKLAMA] [nvarchar](100) NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
 CONSTRAINT [PK_MUH_BANKAEKSTRE_DETAY] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY],
 CONSTRAINT [IX_MUH_BANKAEKSTRE_DETAY] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKAEKSTRE_DETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKAEKSTRE_DETAY59](
	[ID] [int] NOT NULL,
	[BANKAEKSTREID] [int] NULL,
	[TARIH] [datetime] NULL,
	[SUBEID] [int] NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](50) NULL,
	[TUTAR] [decimal](18, 2) NULL,
	[ANAHTAR] [nvarchar](100) NULL,
	[KARSIHESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[FISID] [int] NULL,
	[KUR] [float] NULL,
	[AKTARMA] [bit] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[CEKID] [int] NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[FISACIKLAMA] [nvarchar](100) NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[SDOVIZ] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKAEKSTRE59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKAEKSTRE59](
	[ID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[HESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TARIHBAS] [smalldatetime] NULL,
	[TARIHSON] [smalldatetime] NULL,
	[MASRAF] [float] NULL,
	[ALTCARIID] [int] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[BANKAID] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[OLDID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKATANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKATANIM](
	[BANKAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BANKAKODU] [nvarchar](5) NULL,
	[BANKAADI] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[BANKAUNVAN] [nvarchar](100) NULL,
 CONSTRAINT [PK_MUH_BANKATANIM] PRIMARY KEY CLUSTERED 
(
	[BANKAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_BANKATANIM] UNIQUE NONCLUSTERED 
(
	[BANKAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_BANKATANIM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_BANKATANIM59](
	[BANKAID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[BANKAKODU] [nvarchar](5) NULL,
	[BANKAADI] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[BANKAUNVAN] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_CEK_LTD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_CEK_LTD](
	[CEKID] [int] NOT NULL,
	[CEKTURID] [int] NULL,
	[VADE] [smalldatetime] NULL,
	[BANKA] [nvarchar](50) NULL,
	[SUBE] [nvarchar](50) NULL,
	[HESAPNO] [nvarchar](50) NULL,
	[CEKNO] [nvarchar](50) NULL,
	[ILKSAHIBI] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](50) NULL,
	[NOTLAR] [nvarchar](250) NULL,
	[DTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SILINDI] [int] NULL,
	[SONISLEMID] [int] NULL,
	[TAKIPETME] [bit] NULL,
	[TENANTID] [int] NOT NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_ENTDATA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_ENTDATA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[FISACIKLAMA] [nvarchar](250) NULL,
	[HESAPKODU] [nvarchar](50) NULL,
	[ALTCARIKODU] [nvarchar](20) NULL,
	[SATIRACIKLAMA] [nvarchar](250) NULL,
	[BORC] [float] NULL,
	[ALACAK] [float] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[KUR] [float] NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[BABSTUTAR] [float] NULL,
	[MASMERKODU] [nvarchar](20) NULL,
	[BELGENO] [nvarchar](30) NULL,
 CONSTRAINT [PK_MUH_ENTDATA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_ENTDATA] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_ENTTANIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_ENTTANIM](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ADI] [nvarchar](50) NULL,
	[CTSQL] [ntext] NULL,
	[ENTKAYNAK] [nvarchar](50) NULL,
	[VERITABANI] [int] NULL,
	[UPDATESQL] [ntext] NULL,
	[GERILALSQL] [ntext] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_MUH_ENTTANIM] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_ENTTANIM] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_FIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_FIS59](
	[FISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FISTURID] [int] NULL,
	[FISDURUMID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[TARIH] [datetime] NULL,
	[VADE] [datetime] NULL,
	[FISNO] [nvarchar](30) NULL,
	[YEVNO] [nvarchar](30) NULL,
	[FISTURU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](30) NULL,
	[BELGEACIKLAMA] [nvarchar](250) NULL,
	[DETAYLIENTEGRE] [bit] NULL,
	[FISHESAPID] [int] NULL,
	[FISHESAPID2] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TOPLAM] [decimal](18, 2) NULL,
	[KAPANAN] [float] NULL,
	[DTOPLAM] [float] NULL,
	[OZELKOD1] [nvarchar](40) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[YETKIID] [int] NULL,
	[ENTKAYNAK] [nvarchar](30) NULL,
	[ENTKAYNAKID] [int] NULL,
	[MERKEZIFC] [int] NULL,
	[BABSTYPEID] [int] NULL,
	[OZELKOD4] [nvarchar](30) NULL,
	[PASIF] [bit] NULL,
	[YEVMNO] [int] NULL,
	[YEVMTARIH] [datetime] NULL,
	[YEVMACIKLAMA] [nvarchar](250) NULL,
	[BABSTUTAR] [decimal](18, 2) NULL,
	[ODENMEYEN] [float] NULL,
	[TFISID] [int] NULL,
	[TFISNO] [nvarchar](30) NULL,
	[TFISTARIH] [datetime] NULL,
	[TFISACIKLAMA] [nvarchar](250) NULL,
	[ALTCARIID] [int] NULL,
	[MERKEZFISID] [int] NULL,
	[AKTARIMSTATUID] [int] NULL,
	[RFISNO] [nvarchar](50) NULL,
	[YAZDIRMASAYISI] [int] NULL,
	[ESKIFISDURUMID] [int] NULL,
	[EXPORTEDILDI] [bit] NULL,
	[EXPORTDEGISTI] [bit] NULL,
	[BELGETURU] [int] NULL,
	[ODEMEYONTEMI] [nvarchar](300) NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[SIL] [smallint] NULL,
	[FISTANIMID] [int] NULL,
	[KARSIHESAPID] [int] NULL,
	[TMIKTAR] [float] NULL,
	[TBIRIM] [nvarchar](10) NULL,
	[TBIRIMFIYAT] [float] NULL,
	[MODULID] [int] NULL,
	[MODULEKRANID] [int] NULL,
	[FISDEPOID] [int] NULL,
	[OZELKODID] [int] NULL,
	[OPSTARIHI] [datetime] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_GRUP59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_GRUP59](
	[GRUPID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GRUPKODU] [nvarchar](30) NULL,
	[GRUPADI] [nvarchar](100) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TIPID] [int] NULL,
	[ANAGRUBU] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[SERI] [nvarchar](5) NULL,
	[SIRANO] [int] NULL,
	[PRIMORAN] [float] NULL,
	[PRIMDVZ] [nvarchar](10) NULL,
	[MAHALLE] [nvarchar](30) NULL,
	[ADA] [nvarchar](10) NULL,
	[PARSEL] [nvarchar](10) NULL,
	[ADRES] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[OKCSIFRE] [nvarchar](10) NULL,
	[GRUPSUBEID] [int] NULL,
	[GRUPDEPOID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[ANAGRUPID] [int] NULL,
	[SATICIHESAPID] [int] NULL,
	[KOMGELIRHESAPID] [int] NULL,
	[KOMGIDERHESAPID] [int] NULL,
	[STOKHESAPID] [int] NULL,
	[OLDGRUPID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[KAT] [nvarchar](10) NULL,
	[CEPHE] [nvarchar](20) NULL,
	[DURUM] [nvarchar](20) NULL,
	[GRUPADIENG] [nvarchar](30) NULL,
	[GRUPADIDEU] [nvarchar](30) NULL,
	[GRUPADIRUS] [nvarchar](30) NULL,
	[GRUPADIARP] [nvarchar](30) NULL,
	[MUSTERIHESAPID] [int] NULL,
	[SOZLESMEID] [int] NULL,
	[MALIYETI] [float] NULL,
	[SATISBEDELI] [float] NULL,
	[DOVIZI] [nvarchar](5) NULL,
	[M2] [float] NULL,
	[EMLAKTURID] [int] NULL,
	[GIRISTARIHI] [smalldatetime] NULL,
	[CIKISTARIHI] [smalldatetime] NULL,
	[TAPUTARIHI] [smalldatetime] NULL,
	[ELEKTRIKABONE] [nvarchar](20) NULL,
	[SUABONE] [nvarchar](20) NULL,
	[SIGORTAPOLICE] [nvarchar](50) NULL,
	[TAPUADI] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAP_BOS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAP_BOS](
	[HESAPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NOT NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](50) NULL,
	[VDNO] [nvarchar](40) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [datetime] NULL,
	[ISTENAYRILIS] [datetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[VADEUYAR] [bit] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[OLDHESAPID] [int] NULL,
	[KAMU] [bit] NULL,
	[ALTCARIKULLANIR] [bit] NULL,
	[RDOVIZ] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAP_TEMP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAP_TEMP](
	[HESAPID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](40) NULL,
	[VDNO] [nvarchar](30) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[VADEUYAR] [bit] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL,
	[HESAPID_V6] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAP59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAP59](
	[HESAPID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NOT NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](50) NULL,
	[VDNO] [nvarchar](40) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [datetime] NULL,
	[ISTENAYRILIS] [datetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[VADEUYAR] [bit] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[OLDHESAPID] [int] NULL,
	[KAMU] [bit] NULL,
	[ALTCARIKULLANIR] [bit] NULL,
	[SOZLESMESIVAR] [bit] NULL,
	[ISLEMGRUPID1ZORUNLU] [bit] NULL,
	[OZELKODIDZORUNLU] [bit] NULL,
	[PROJEZORUNLU] [bit] NULL,
	[RDOVIZ] [nvarchar](5) NULL,
	[ENG_HESAPADI] [nvarchar](100) NULL,
	[RUS_HESAPADI] [nvarchar](100) NULL,
	[DIG_HESAPADI] [nvarchar](100) NULL,
	[EFATURAPK] [nvarchar](150) NULL,
	[KURZARARHESAPID] [int] NULL,
	[KURKARHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPISL_ROYAL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPISL_ROYAL](
	[ISLEMID] [int] IDENTITY(1,1) NOT NULL,
	[FISID] [int] NULL,
	[HESAPID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[ACIKLAMA] [nvarchar](500) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TUTAR] [decimal](18, 2) NULL,
	[DTUTAR] [float] NULL,
	[BORC] [decimal](18, 2) NULL,
	[ALACAK] [decimal](18, 2) NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[BABSTUTAR] [float] NULL,
	[VADE] [datetime] NULL,
	[KAPANAN] [float] NULL,
	[ENTKAYNAK] [nvarchar](30) NULL,
	[ENTKAYITID] [int] NULL,
	[BUTCEID] [int] NULL,
	[SILINDI] [int] NULL,
	[CEKID] [int] NULL,
	[KDV] [float] NULL,
	[BELGENO] [nvarchar](30) NULL,
	[BELGEACIKLAMA] [nvarchar](500) NULL,
	[BELGETARIH] [datetime] NULL,
	[TEVKIFATKODU] [nvarchar](5) NULL,
	[TEVKIFATYUZDE] [float] NULL,
	[KISISAYI] [int] NULL,
	[RESMIKURUMKODU] [nvarchar](5) NULL,
	[TVKKDVPAY] [int] NULL,
	[TVKKDVPAYDA] [int] NULL,
	[KDVISTISNATUR] [nvarchar](5) NULL,
	[BANKAID] [int] NULL,
	[KAPANAN2] [float] NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[BANKAEKSTREDETAYID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[SSIRA] [int] NULL,
	[BELGETURU] [int] NULL,
	[ODEMEYONTEMI] [nvarchar](300) NULL,
	[GERCEKLESTIID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIMFIYAT] [float] NULL,
	[OZELKODID] [int] NULL,
	[CKARSIHESAPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPISL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPISL59](
	[ISLEMID] [int] NOT NULL,
	[FISID] [int] NULL,
	[HESAPID] [int] NULL,
	[FISUUID] [uniqueidentifier] NULL,
	[ACIKLAMA] [nvarchar](500) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[TUTAR] [decimal](18, 2) NULL,
	[DTUTAR] [float] NULL,
	[BORC] [decimal](18, 2) NULL,
	[ALACAK] [decimal](18, 2) NULL,
	[DBORC] [float] NULL,
	[DALACAK] [float] NULL,
	[MASMERID] [int] NULL,
	[PROJEID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[BABSTUTAR] [float] NULL,
	[VADE] [datetime] NULL,
	[KAPANAN] [float] NULL,
	[ENTKAYNAK] [nvarchar](30) NULL,
	[ENTKAYITID] [int] NULL,
	[BUTCEID] [int] NULL,
	[SILINDI] [int] NULL,
	[CEKID] [int] NULL,
	[KDV] [float] NULL,
	[BELGENO] [nvarchar](30) NULL,
	[BELGEACIKLAMA] [nvarchar](500) NULL,
	[BELGETARIH] [datetime] NULL,
	[TEVKIFATKODU] [nvarchar](5) NULL,
	[TEVKIFATYUZDE] [float] NULL,
	[KISISAYI] [int] NULL,
	[RESMIKURUMKODU] [nvarchar](5) NULL,
	[TVKKDVPAY] [int] NULL,
	[TVKKDVPAYDA] [int] NULL,
	[KDVISTISNATUR] [nvarchar](5) NULL,
	[BANKAID] [int] NULL,
	[KAPANAN2] [float] NULL,
	[ODENMEYEN] [float] NULL,
	[ODENMEYEN2] [float] NULL,
	[BANKAEKSTREDETAYID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[YEVSATIRSIRANO] [float] NULL,
	[SSIRA] [int] NULL,
	[BELGETURU] [int] NULL,
	[ODEMEYONTEMI] [nvarchar](300) NULL,
	[GERCEKLESTIID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIMFIYAT] [float] NULL,
	[OZELKODID] [int] NULL,
	[CKARSIHESAPID] [int] NULL,
	[GERCEKLESTI] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPW]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPW](
	[HESAPID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](40) NULL,
	[VDNO] [nvarchar](30) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL,
	[VADEUYAR] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPX]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPX](
	[HESAPID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HESAPTIPID] [int] NULL,
	[HESAPGRUPID1] [int] NULL,
	[HESAPGRUPID2] [int] NULL,
	[KODU] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[ACIKLAMA2] [nvarchar](100) NULL,
	[UCHESAP] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[MASMERID] [int] NULL,
	[YETKIID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SEVIYE] [int] NULL,
	[VADEGUN] [int] NULL,
	[MMZORUNLU] [int] NULL,
	[FAALIYETICI] [int] NULL,
	[RISKLIMITI] [float] NULL,
	[VD] [nvarchar](40) NULL,
	[VDNO] [nvarchar](30) NULL,
	[VADEORAN] [float] NULL,
	[DVADEORAN] [float] NULL,
	[TCKIMLIKNO] [nvarchar](15) NULL,
	[UNVANI] [nvarchar](100) NULL,
	[ADRES1] [nvarchar](200) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[SEHIR] [nvarchar](20) NULL,
	[PKODU] [nvarchar](20) NULL,
	[ULKE] [nvarchar](50) NULL,
	[ULKEKODU] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](100) NULL,
	[YETKILI2] [nvarchar](100) NULL,
	[TEL1] [nvarchar](30) NULL,
	[TEL2] [nvarchar](30) NULL,
	[FAX] [nvarchar](30) NULL,
	[FAX2] [nvarchar](30) NULL,
	[GSM] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[BOLUMU] [nvarchar](30) NULL,
	[MAAS] [float] NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[STDIND] [float] NULL,
	[KARTNO] [nvarchar](30) NULL,
	[WEBUSER] [nvarchar](20) NULL,
	[WEBPASS] [nvarchar](20) NULL,
	[FIRMAGRUPKODU] [nvarchar](50) NULL,
	[ODEMEGUNU] [int] NULL,
	[BANKASUBEKODU] [nvarchar](50) NULL,
	[BANKAKODU] [nvarchar](50) NULL,
	[BANKAHESAPNO] [nvarchar](50) NULL,
	[BANKAIBAN] [nvarchar](50) NULL,
	[KDVORAN] [int] NULL,
	[ODEMEHESAPID] [int] NULL,
	[ODEMEORAN] [float] NULL,
	[BANKAMUSTERINO] [nvarchar](20) NULL,
	[BATIPI] [int] NULL,
	[CALISMASEKLI] [int] NULL,
	[GRUPFIRMAHESAPID] [int] NULL,
	[NOTLAR] [nvarchar](100) NULL,
	[OZELKODZORUNLU] [bit] NULL,
	[MERKEZKODU] [nvarchar](50) NULL,
	[SKODU] [nvarchar](100) NULL,
	[EFATURAKULLANIR] [bit] NULL,
	[EK1] [nvarchar](50) NULL,
	[MALIYEKODU] [nvarchar](50) NULL,
	[KDVTANIMID] [int] NULL,
	[BORCTUTAR] [float] NULL,
	[ALACAKTUTAR] [float] NULL,
	[DBORCTUTAR] [float] NULL,
	[DALACAKTUTAR] [float] NULL,
	[KARTKODU] [nvarchar](50) NULL,
	[AKTIF] [bit] NULL,
	[ILCE] [nvarchar](50) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [smalldatetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [smalldatetime] NULL,
	[KALITEPUAN] [int] NULL,
	[CINDORAN] [float] NULL,
	[GSFIYAT] [int] NULL,
	[SIL] [smallint] NULL,
	[STDIND2] [float] NULL,
	[BANKAID] [smallint] NULL,
	[ANLASMAOKU] [smallint] NULL,
	[SORUNLU] [bit] NULL,
	[SORUNSEBEBI] [nvarchar](50) NULL,
	[FIYATTIPI] [tinyint] NULL,
	[SOZLESMENO] [nvarchar](10) NULL,
	[SOZLESMEBASLANGIC] [smalldatetime] NULL,
	[SOZLESMEBITIS] [smalldatetime] NULL,
	[SOZLESMEYETKILISI] [nvarchar](20) NULL,
	[AY] [tinyint] NULL,
	[AYLIKUCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](5) NULL,
	[TOPLAMUCRET] [float] NULL,
	[KDVLIMI] [bit] NULL,
	[SOZLESMENOTU] [nvarchar](150) NULL,
	[TAPDK] [nvarchar](50) NULL,
	[STDISLEMGRUBU1] [int] NULL,
	[KAYITDURUM] [smallint] NULL,
	[VADEUYAR] [bit] NULL,
	[STDISLEMGRUBU2] [int] NULL,
	[OGRENCISINIF] [nvarchar](40) NULL,
	[OGRENCIBABADI] [nvarchar](40) NULL,
	[OGRENCIANNEADI] [nvarchar](40) NULL,
	[OGRENCIBABATEL] [nvarchar](25) NULL,
	[OGRENCIANNETEL] [nvarchar](25) NULL,
	[SORUMLUOGRETMEN] [nvarchar](40) NULL,
	[OGRENCIVELITC] [nvarchar](20) NULL,
	[OGRENCISERVIS] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_HESAPYANSITMA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_HESAPYANSITMA](
	[HESAPYANSITMAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[HESAPID1] [int] NULL,
	[HESAPID2] [int] NULL,
	[YANSITMAHESAPID1] [int] NULL,
	[YANSITMAHESAPID2] [int] NULL,
	[YANSITMAHESAPID3] [int] NULL,
	[YUZDE] [float] NULL,
	[MASMERID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[PROJEID] [int] NULL,
 CONSTRAINT [PK_MUH_HESAPYANSITMA] PRIMARY KEY CLUSTERED 
(
	[HESAPYANSITMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_HESAPYANSITMA] UNIQUE NONCLUSTERED 
(
	[HESAPYANSITMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUH_YETKIKOD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUH_YETKIKOD](
	[YETKIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[YETKIKODU] [nvarchar](30) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
 CONSTRAINT [PK_MUH_YETKIKOD] PRIMARY KEY CLUSTERED 
(
	[YETKIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUH_YETKIKOD] UNIQUE NONCLUSTERED 
(
	[YETKIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MUHDONEM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MUHDONEM](
	[DONEMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[KODU] [nvarchar](20) NULL,
	[DONEMBASI] [datetime] NULL,
	[DONEMSONU] [datetime] NULL,
	[KAPANDI] [int] NULL,
	[EDEFTER] [bit] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_MUHDONEM] PRIMARY KEY CLUSTERED 
(
	[DONEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_MUHDONEM] UNIQUE NONCLUSTERED 
(
	[DONEMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVA_DBBAKIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVA_DBBAKIM](
	[BAKIMID] [int] IDENTITY(1,1) NOT NULL,
	[SURUM] [nvarchar](20) NOT NULL,
	[TARIH] [datetime] NOT NULL,
	[USERID] [int] NULL,
	[BASARILI] [int] NOT NULL,
	[HATALI] [int] NOT NULL,
 CONSTRAINT [PK_NOVA_DBBAKIM] PRIMARY KEY CLUSTERED 
(
	[BAKIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVA_RAPORSABLON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVA_RAPORSABLON](
	[SABLONID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[ADI] [nvarchar](100) NOT NULL,
	[TURU] [varchar](10) NOT NULL,
	[VERIKAYNAK] [nvarchar](50) NOT NULL,
	[SABLONJSON] [nvarchar](max) NOT NULL,
	[VARSAYILAN] [bit] NOT NULL,
	[SIL] [int] NOT NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[UPD_DATE] [datetime] NULL,
	[UPD_USERID] [int] NULL,
 CONSTRAINT [PK_NOVA_RAPORSABLON] PRIMARY KEY CLUSTERED 
(
	[SABLONID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVA_UYGULAMA_SERVISI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVA_UYGULAMA_SERVISI](
	[US_ID] [int] IDENTITY(1,1) NOT NULL,
	[US_ADI] [nvarchar](50) NULL,
	[US_TIPID] [tinyint] NULL,
	[US_ZAMANSN] [int] NULL,
	[US_BITISRUNSQL] [nvarchar](250) NULL,
	[US_AKTIF] [bit] NULL,
	[US_METHODNAME] [nvarchar](50) NULL,
 CONSTRAINT [PK_NOVA_UYGULAMA_SERVISI] PRIMARY KEY CLUSTERED 
(
	[US_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVA_UYGULAMA_SERVISI_MAIL_SENDER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVA_UYGULAMA_SERVISI_MAIL_SENDER](
	[MS_ID] [int] IDENTITY(1,1) NOT NULL,
	[US_ID] [int] NOT NULL,
	[MS_ADI] [nvarchar](50) NULL,
	[MS_DOSYAADI] [nvarchar](50) NULL,
	[MS_SQL] [nvarchar](250) NULL,
	[MS_TIPID] [int] NULL,
	[MS_AKTIF] [bit] NULL,
 CONSTRAINT [PK_NOVA_UYGULAMA_SERVISI_MAIL_SENDER] PRIMARY KEY CLUSTERED 
(
	[MS_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAERISIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAERISIM](
	[NOVAERISIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[DURUMID] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](20) NULL,
	[IPADRESI] [nvarchar](20) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_NOVAERISIM] PRIMARY KEY CLUSTERED 
(
	[NOVAERISIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAERISIM_07052021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAERISIM_07052021](
	[NOVAERISIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[DURUMID] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](20) NULL,
	[IPADRESI] [nvarchar](20) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAERISIM_08042021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAERISIM_08042021](
	[NOVAERISIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[DURUMID] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](20) NULL,
	[IPADRESI] [nvarchar](20) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAERISIM_25072021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAERISIM_25072021](
	[NOVAERISIMID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[DURUMID] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](20) NULL,
	[IPADRESI] [nvarchar](20) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAEXE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAEXE](
	[NOVAEXEID] [int] IDENTITY(1,1) NOT NULL,
	[DOSYA] [text] NULL,
	[VERSIYONNO] [nvarchar](30) NULL,
 CONSTRAINT [PK_NOVAEXE] PRIMARY KEY CLUSTERED 
(
	[NOVAEXEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAGUNCELLEME]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAGUNCELLEME](
	[NOVAGUNCELLEMEID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [smalldatetime] NULL,
	[VERSIYONNO] [nvarchar](50) NULL,
	[MODUL] [nvarchar](50) NULL,
	[EKRAN] [nvarchar](50) NULL,
	[KONU] [nvarchar](100) NULL,
	[EKLENTILER] [nvarchar](3500) NULL,
	[URL] [nvarchar](500) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_NOVAGUNCELLEME] PRIMARY KEY CLUSTERED 
(
	[NOVAGUNCELLEMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAHATA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAHATA](
	[NOVAHATAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[EKRAN] [nvarchar](20) NULL,
	[NESNEADI] [nvarchar](20) NULL,
	[HATAMESAJI] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_NOVAHATA] PRIMARY KEY CLUSTERED 
(
	[NOVAHATAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVALOG]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVALOG](
	[NOVALOGID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[KAYNAK] [nvarchar](30) NULL,
	[KULLANICIID] [int] NULL,
	[ISLEM] [nvarchar](20) NULL,
	[ISLEMID] [int] NULL,
	[ACIKLAMA] [nvarchar](300) NULL,
	[SIL] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](30) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[IPADRES] [nvarchar](20) NULL,
 CONSTRAINT [PK_NOVALOG] PRIMARY KEY CLUSTERED 
(
	[NOVALOGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVALOG_YEDEK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVALOG_YEDEK](
	[NOVALOGID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[KAYNAK] [nvarchar](30) NULL,
	[KULLANICIID] [int] NULL,
	[ISLEM] [nvarchar](20) NULL,
	[ISLEMID] [int] NULL,
	[ACIKLAMA] [nvarchar](300) NULL,
	[SIL] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](30) NULL,
	[MACADRES] [nvarchar](20) NULL,
	[IPADRES] [nvarchar](20) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVALOG_YEDEK_10122021]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVALOG_YEDEK_10122021](
	[NOVALOGID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[KAYNAK] [nvarchar](30) NULL,
	[KULLANICIID] [int] NULL,
	[ISLEM] [nvarchar](20) NULL,
	[ISLEMID] [int] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[SIL] [smallint] NULL,
	[BILGISAYARADI] [nvarchar](30) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAUPDATE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAUPDATE](
	[NOVAUPDATEID] [int] NOT NULL,
	[NESNEADI] [nvarchar](50) NULL,
	[SQLTEXT] [nvarchar](max) NULL,
 CONSTRAINT [PK_NOVAUPDATE] PRIMARY KEY CLUSTERED 
(
	[NOVAUPDATEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAUSER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAUSER59](
	[NOVAUSERID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](30) NULL,
	[SIFRESI] [nvarchar](40) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[DEPARTMANI] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[ADRES] [nvarchar](150) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[TIP] [bit] NULL,
	[YETKIGRUPID] [int] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[DEPOID] [int] NULL,
	[MASMERID] [int] NULL,
	[DEPKODU] [nvarchar](5) NULL,
	[SKODU] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[GARSONID] [int] NULL,
	[IZINLIIPAKTIF] [bit] NULL,
	[IZINLIIP] [nvarchar](150) NULL,
	[VERSIYONNO] [nvarchar](20) NULL,
	[DEPID] [int] NULL,
	[KAPALISATIS] [bit] NULL,
	[FIYAT123] [bit] NULL,
	[OZELFIYAT] [bit] NULL,
	[FIYATDEGISTIR] [bit] NULL,
	[RESIMDEGISTIR] [bit] NULL,
	[RESIMURUNSEC] [bit] NULL,
	[INDIRIMVER] [bit] NULL,
	[KASAGOREBILIR] [bit] NULL,
	[SATISIPTAL] [bit] NULL,
	[SATISDUZELT] [bit] NULL,
	[SERBESTDEPO] [bit] NULL,
	[TUTARSALINDIRIM] [bit] NULL,
	[MOBILYETKISEVIYE] [smallint] NULL,
	[GUNCELLENDI] [bit] NULL,
	[UPDATE_DATE] [datetime] NULL,
	[IKYETKI] [bit] NULL,
	[IKDEPARTMANID] [int] NULL,
	[ONAYTIPI] [smallint] NULL,
	[TAMYETKI] [bit] NULL,
	[OZELRAPOR] [bit] NULL,
	[TUMPERSONEL] [bit] NULL,
	[KARTNO] [nvarchar](35) NULL,
	[ONAYSEVIYE] [smallint] NULL,
	[SATIRSIL] [bit] NULL,
	[ISLEMMENU] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAUSERD]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAUSERD](
	[NOVAUSERDID] [int] IDENTITY(1,1) NOT NULL,
	[NOVAUSERID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANID] [int] NULL,
	[EKRANAC] [bit] NULL,
	[YENI] [bit] NULL,
	[DUZELT] [bit] NULL,
	[KAYDET] [bit] NULL,
	[SIL] [bit] NULL,
	[YAZDIR] [bit] NULL,
	[RAPOR] [bit] NULL,
	[LISTEGIRIS] [bit] NULL,
 CONSTRAINT [PK_NOVAUSERD] PRIMARY KEY CLUSTERED 
(
	[NOVAUSERDID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAUSERD59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAUSERD59](
	[NOVAUSERDID] [int] NOT NULL,
	[NOVAUSERID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[EKRANID] [int] NULL,
	[EKRANAC] [bit] NULL,
	[YENI] [bit] NULL,
	[DUZELT] [bit] NULL,
	[KAYDET] [bit] NULL,
	[SIL] [bit] NULL,
	[YAZDIR] [bit] NULL,
	[RAPOR] [bit] NULL,
	[LISTEGIRIS] [bit] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAVERSIYON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAVERSIYON](
	[VERSIYONID] [int] IDENTITY(1,1) NOT NULL,
	[VERSIYONNO] [nvarchar](50) NULL,
	[YAYINNO] [nvarchar](50) NULL,
 CONSTRAINT [PK_NOVAVERSIYON] PRIMARY KEY CLUSTERED 
(
	[VERSIYONID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[NOVAYENILIK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NOVAYENILIK](
	[NOVAYENILIKID] [int] IDENTITY(1,1) NOT NULL,
	[VERSIYONNO] [nvarchar](50) NULL,
	[YAYINNO] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
 CONSTRAINT [PK_NOVAYENILIK] PRIMARY KEY CLUSTERED 
(
	[NOVAYENILIKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERADAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERADAY](
	[PERADAYID] [int] IDENTITY(1,1) NOT NULL,
	[BASVURUTARIHI] [smalldatetime] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ADSOYAD] [nvarchar](30) NULL,
	[TCKNO] [nvarchar](11) NULL,
	[CEPTEL] [nvarchar](15) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[ADRES] [nvarchar](150) NULL,
	[REFERANS1] [nvarchar](30) NULL,
	[REFERANS1GOREV] [nvarchar](30) NULL,
	[REFERANS1TEL] [nvarchar](15) NULL,
	[REFERANS2] [nvarchar](30) NULL,
	[REFERANS2GOREV] [nvarchar](30) NULL,
	[REFERANS2TEL] [nvarchar](15) NULL,
	[REFERANS3] [nvarchar](30) NULL,
	[REFERANS3GOREV] [nvarchar](30) NULL,
	[REFERANS3TEL] [nvarchar](15) NULL,
	[BASVURUSEKLI] [nvarchar](20) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[SONISYERI] [nvarchar](50) NULL,
	[SONMAAS] [float] NULL,
	[EHLIYET] [nvarchar](10) NULL,
	[KANGRUBU] [nvarchar](10) NULL,
	[OGRENIMDURUMU] [nvarchar](20) NULL,
	[YABANCIDIL] [nvarchar](20) NULL,
	[SIGARA] [bit] NULL,
	[ALKOL] [bit] NULL,
	[EVLI] [bit] NULL,
	[ADLISICIL] [bit] NULL,
	[OLUMLU] [bit] NULL,
	[SEBEPID] [int] NULL,
	[ADLISICILSEBEBI] [nvarchar](50) NULL,
	[NOTLAR] [nvarchar](250) NULL,
	[RESIM] [image] NULL,
	[ELKSUBEID] [int] NULL,
	[ELKSICILID] [int] NULL,
	[ELKDEPKODU] [nvarchar](10) NULL,
	[ELKUNVANID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_PERADAY] PRIMARY KEY CLUSTERED 
(
	[PERADAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERADAYDOSYA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERADAYDOSYA](
	[PERADAYDOSYAID] [int] IDENTITY(1,1) NOT NULL,
	[PERADAYID] [int] NULL,
	[ADI] [nvarchar](50) NULL,
	[TURU] [nvarchar](10) NULL,
	[DOSYA] [text] NULL,
 CONSTRAINT [PK_PERADAYDOSYA] PRIMARY KEY CLUSTERED 
(
	[PERADAYDOSYAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERBUTCEKUR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERBUTCEKUR](
	[PERBUTCEKURID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[BUTCEKUR] [float] NULL,
	[GERCEKKUR] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_PERBUTCEKUR] PRIMARY KEY CLUSTERED 
(
	[PERBUTCEKURID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERELEKTRADEP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERELEKTRADEP](
	[PERELEKTRADEPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPKODU] [nvarchar](20) NULL,
	[DEPADI] [nvarchar](50) NULL,
 CONSTRAINT [PK_PERELEKTRADEP] PRIMARY KEY CLUSTERED 
(
	[PERELEKTRADEPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERELEKTRAUNV]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERELEKTRAUNV](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[UNVANID] [int] NULL,
	[UNVANKODU] [nvarchar](10) NULL,
	[UNVANADI] [nvarchar](50) NULL,
	[DEPKODU] [nvarchar](10) NULL,
 CONSTRAINT [PK_PERELEKTRAUNV] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERSEBEP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERSEBEP](
	[PERSEBEPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[TURU] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_PERSEBEP] PRIMARY KEY CLUSTERED 
(
	[PERSEBEPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERSONEL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERSONEL](
	[ID] [tinyint] IDENTITY(1,1) NOT NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[NET] [decimal](15, 4) NULL,
	[BRUT] [decimal](15, 4) NULL,
	[GV_MATRAH] [decimal](15, 4) NULL,
	[KUMULATIF_GV_MATRAHI] [decimal](15, 4) NULL,
	[FIRMAID] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERSSKPARAMETRE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERSSKPARAMETRE](
	[PERSSKPARAMETREID] [int] IDENTITY(1,1) NOT NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BORDROTURID] [smallint] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[YIL] [int] NULL,
	[ILKAY] [int] NULL,
	[SONAY] [int] NULL,
	[ASGARIUCRET_NET] [float] NULL,
	[ASGARIUCRET_BRUT] [float] NULL,
	[SSK_ISCI_PRIMI] [float] NULL,
	[ISSIZLIK_ISCI_PRIMI] [float] NULL,
	[DAMGA_VERGISI] [float] NULL,
	[SSK_ISVEREN_PRIMI] [float] NULL,
	[ISSIZLIK_ISVEREN_PRIMI] [float] NULL,
	[SSK_TAVAN] [float] NULL,
	[SSK_TABAN] [float] NULL,
	[GV1_ORAN] [float] NULL,
	[GV1_MATRAH] [float] NULL,
	[GV2_ORAN] [float] NULL,
	[GV2_MATRAH] [float] NULL,
	[GV3_ORAN] [float] NULL,
	[GV3_MATRAH] [float] NULL,
	[GV4_ORAN] [float] NULL,
	[GV4_MATRAH] [float] NULL,
	[GV5_ORAN] [float] NULL,
	[GV5_MATRAH] [float] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_PERSSKPARAMETRE] PRIMARY KEY CLUSTERED 
(
	[PERSSKPARAMETREID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PERUNVANSUBE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PERUNVANSUBE](
	[PERUNVANSUBEID] [int] IDENTITY(1,1) NOT NULL,
	[PERDEPARTMANID] [int] NULL,
	[PERUNVANID] [int] NULL,
	[SUBEID] [int] NULL,
	[MERKEZSUBEID] [int] NULL,
	[NETMAAS] [float] NULL,
 CONSTRAINT [PK_PERUNVANSUBE] PRIMARY KEY CLUSTERED 
(
	[PERUNVANSUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PING]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PING](
	[PINGID] [smallint] NOT NULL,
 CONSTRAINT [PK_PING] PRIMARY KEY CLUSTERED 
(
	[PINGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POSINDIRIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POSINDIRIM](
	[POSINDIRIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[INDIRIMADI] [nvarchar](150) NULL,
	[BASLANGIC] [datetime] NULL,
	[BITIS] [datetime] NULL,
	[ILKSAAT] [datetime] NULL,
	[SONSAAT] [datetime] NULL,
	[INDORAN] [float] NULL,
	[INDTUTAR] [float] NULL,
	[MIKTAR] [float] NULL,
	[BEDAVA] [float] NULL,
	[INDSIRA] [smallint] NULL,
	[MANUEL] [bit] NULL,
	[AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_POSINDIRIM] PRIMARY KEY CLUSTERED 
(
	[POSINDIRIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POSINDIRIMDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POSINDIRIMDETAY](
	[POSINDIRIMDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[POSINDIRIMID] [int] NULL,
	[STOKID] [int] NULL,
	[INDORAN] [float] NULL,
	[INDTUTAR] [float] NULL,
	[MIKTARI] [float] NULL,
	[BEDAVASI] [float] NULL,
 CONSTRAINT [PK_POSINDIRIMDETAY] PRIMARY KEY CLUSTERED 
(
	[POSINDIRIMDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POSKONTROL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POSKONTROL](
	[POSKONTROLID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[TERMINAL] [nvarchar](20) NULL,
	[POSDURUM] [tinyint] NULL,
 CONSTRAINT [PK_POSKONTROL] PRIMARY KEY CLUSTERED 
(
	[POSKONTROLID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POSLOG]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POSLOG](
	[POSLOGID] [int] IDENTITY(1,1) NOT NULL,
	[FISCOUNTER] [int] NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[YETKILIID] [int] NULL,
	[USERID] [int] NULL,
	[ISLEM] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[TUTAR] [float] NULL,
 CONSTRAINT [PK_POSLOG] PRIMARY KEY CLUSTERED 
(
	[POSLOGID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POSYAZICITIP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POSYAZICITIP](
	[POSYAZICITIPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[HEDEFYERI] [nvarchar](30) NULL,
	[YAZICIADI] [nvarchar](100) NULL,
	[TURU] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_POSYAZICITIP] PRIMARY KEY CLUSTERED 
(
	[POSYAZICITIPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PROJEBLOK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PROJEBLOK](
	[PROJEBLOKID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[BLOKADI] [nvarchar](20) NULL,
	[DAIRESAYISI] [int] NULL,
	[KATSAYISI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_PROJEBLOK] PRIMARY KEY CLUSTERED 
(
	[PROJEBLOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PROJEBLOK59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PROJEBLOK59](
	[PROJEBLOKID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[BLOKADI] [nvarchar](20) NULL,
	[DAIRESAYISI] [int] NULL,
	[KATSAYISI] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PROJEEMLAKTIP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PROJEEMLAKTIP](
	[PROJEEMLAKTIPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[EMLAKTIPID] [int] NULL,
	[AIDAT] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[ISLEMGRUPID] [int] NULL,
 CONSTRAINT [PK_PROJEEMLAKTIP] PRIMARY KEY CLUSTERED 
(
	[PROJEEMLAKTIPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_FIRMAID_PROJE_TIP_SIL] UNIQUE NONCLUSTERED 
(
	[FIRMAID] ASC,
	[PROJEID] ASC,
	[EMLAKTIPID] ASC,
	[SIL] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PTARIH]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PTARIH](
	[PTARIHID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
 CONSTRAINT [PK_PTARIH] PRIMARY KEY CLUSTERED 
(
	[PTARIHID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RAPORLAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RAPORLAR](
	[RAPORLARID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BOLUM] [nvarchar](50) NULL,
	[RAPORADI] [nvarchar](100) NULL,
	[XML] [nvarchar](max) NULL,
	[DURUM] [tinyint] NULL,
	[OLUSTURMA] [datetime] NULL,
	[SILME] [datetime] NULL,
	[XML2] [text] NULL,
 CONSTRAINT [PK_RAPORLAR] PRIMARY KEY CLUSTERED 
(
	[RAPORLARID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RAPORLAR_EK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RAPORLAR_EK](
	[RaporlarId] [int] NOT NULL,
	[Bolum] [nvarchar](20) NULL,
	[RaporAdi] [nvarchar](100) NULL,
	[XML] [nvarchar](max) NULL,
	[Durum] [tinyint] NULL,
	[Olusturma] [smalldatetime] NULL,
	[Silme] [smalldatetime] NULL,
	[XML2] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RAPORLAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RAPORLAR59](
	[RAPORLARID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BOLUM] [nvarchar](50) NULL,
	[RAPORADI] [nvarchar](100) NULL,
	[XML] [nvarchar](max) NULL,
	[DURUM] [tinyint] NULL,
	[OLUSTURMA] [datetime] NULL,
	[SILME] [datetime] NULL,
	[XML2] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RECETE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RECETE](
	[RECETEID] [int] IDENTITY(1,1) NOT NULL,
	[URUNID] [int] NULL,
	[STOKID] [int] NULL,
	[ORAN] [float] NULL,
	[FIRE] [float] NULL,
	[AKTARID] [int] NULL,
	[XBIRIM] [nvarchar](10) NULL,
	[STOKKODU] [nvarchar](10) NULL,
	[SARFDEPOID] [int] NULL,
	[BMALIYET] [float] NULL,
	[SONBMALIYET] [float] NULL,
	[CIHAZID] [int] NULL,
	[SUBEID] [int] NULL,
	[RECETEKATSAYISI] [float] NULL,
	[GRUBU] [nvarchar](15) NULL,
	[RAPORKATSAYISI] [float] NULL,
	[BIRIM] [nvarchar](15) NULL,
 CONSTRAINT [PK_RECETE] PRIMARY KEY CLUSTERED 
(
	[RECETEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_RECETE] UNIQUE NONCLUSTERED 
(
	[RECETEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RECETE_NOK]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RECETE_NOK](
	[RECETEID] [int] NOT NULL,
	[URUNID] [int] NULL,
	[STOKID] [int] NULL,
	[ORAN] [float] NULL,
	[FIRE] [float] NULL,
	[AKTARID] [int] NULL,
	[XBIRIM] [nvarchar](10) NULL,
	[STOKKODU] [nvarchar](10) NULL,
	[SARFDEPOID] [int] NULL,
	[BMALIYET] [float] NULL,
	[SONBMALIYET] [float] NULL,
	[CIHAZID] [int] NULL,
	[SUBEID] [int] NULL,
	[RECETEKATSAYISI] [float] NULL,
	[GRUBU] [nvarchar](15) NULL,
	[RAPORKATSAYISI] [float] NULL,
	[BIRIM] [nvarchar](15) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RECETE59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RECETE59](
	[RECETEID] [int] NOT NULL,
	[URUNID] [int] NULL,
	[STOKID] [int] NULL,
	[ORAN] [float] NULL,
	[FIRE] [float] NULL,
	[AKTARID] [int] NULL,
	[XBIRIM] [nvarchar](10) NULL,
	[STOKKODU] [nvarchar](10) NULL,
	[SARFDEPOID] [int] NULL,
	[BMALIYET] [float] NULL,
	[SONBMALIYET] [float] NULL,
	[CIHAZID] [int] NULL,
	[SUBEID] [int] NULL,
	[RECETEKATSAYISI] [float] NULL,
	[GRUBU] [nvarchar](15) NULL,
	[RAPORKATSAYISI] [float] NULL,
	[BIRIM] [nvarchar](15) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RECETEDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RECETEDETAY](
	[RECETEDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[URETIMRECETEID] [int] NULL,
	[KODU] [nvarchar](20) NULL,
	[STOKID] [int] NULL,
	[BIRIM] [nvarchar](10) NULL,
	[MIKTAR] [float] NULL,
	[FIREY] [float] NULL,
	[FIRE] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[KUR] [float] NULL,
	[BIRIMMALIYET] [float] NULL,
	[RECETEMALIYET] [float] NULL,
	[FIREMALIYET] [float] NULL,
 CONSTRAINT [PK_RECETEDETAY] PRIMARY KEY CLUSTERED 
(
	[RECETEDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RENKBEDENGRUP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RENKBEDENGRUP](
	[RENKBEDENGRUPID] [int] IDENTITY(100,1) NOT NULL,
	[FIRMAID] [smallint] NOT NULL,
	[SUBEID] [smallint] NULL,
	[TURID] [smallint] NULL,
	[RENKBEDENGRUBU] [nvarchar](50) NULL,
	[STOKGRUBU] [nvarchar](10) NULL,
	[SIL] [nchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
 CONSTRAINT [PK_BEDENGRUP] PRIMARY KEY CLUSTERED 
(
	[RENKBEDENGRUPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RENKLER]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RENKLER](
	[RENKLERID] [int] IDENTITY(1000,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[RENKADI] [nvarchar](30) NULL,
	[RENKKODU] [nvarchar](20) NULL,
	[RENKACIKLAMA] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDRENKLERID] [int] NULL,
 CONSTRAINT [PK_RENKLER] PRIMARY KEY CLUSTERED 
(
	[RENKLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RENKLER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RENKLER59](
	[RENKLERID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[RENKADI] [nvarchar](30) NULL,
	[RENKKODU] [nvarchar](20) NULL,
	[RENKACIKLAMA] [nvarchar](50) NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDRENKLERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[REYON]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[REYON](
	[REYONID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[REYONNO] [nvarchar](10) NULL,
	[REYONADI] [nvarchar](50) NULL,
	[KAT] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_REYONID] PRIMARY KEY CLUSTERED 
(
	[REYONID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[REZSITE]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[REZSITE](
	[REZSITEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[REZTARIHI] [smalldatetime] NULL,
	[DAIRENO] [nvarchar](20) NULL,
	[DAIREID] [int] NULL,
	[HESAPID] [int] NULL,
	[REZNO] [nvarchar](10) NULL,
	[ADSOYAD] [nvarchar](50) NULL,
	[GELISTARIHI] [smalldatetime] NULL,
	[AYRILISTARIHI] [smalldatetime] NULL,
	[KISI] [float] NULL,
	[COCUK] [float] NULL,
	[GIRISNOTU] [nvarchar](50) NULL,
	[CIKISNOTU] [nvarchar](50) NULL,
	[TELEFON] [nvarchar](20) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[GUNLUKUCRET] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[TOPLAM] [float] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[AYRILDI] [bit] NULL,
	[KONAKLAMA] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_REZSITE] PRIMARY KEY CLUSTERED 
(
	[REZSITEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SATISBONUS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SATISBONUS](
	[SATISBONUSID] [int] IDENTITY(1,1) NOT NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[MASMERID] [int] NULL,
	[ILKTARIH] [smalldatetime] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[GRUPKODU] [nvarchar](10) NULL,
	[STOKID] [int] NULL,
	[ENAZSATIS] [float] NULL,
	[ENCOKSATIS] [float] NULL,
	[PUAN] [float] NULL,
	[INDIRIMORAN] [float] NULL,
	[AKTIF] [bit] NULL,
	[SADECEUYE] [bit] NULL,
	[SADECEKAMPANYA] [bit] NULL,
	[KAMPANYAKODU] [nvarchar](10) NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SATISBONUS] PRIMARY KEY CLUSTERED 
(
	[SATISBONUSID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SATISODEME59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SATISODEME59](
	[SATISODEMEID] [int] NOT NULL,
	[DEPOFISID] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYACLAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYACLAR](
	[SAYACLARID] [int] IDENTITY(1,1) NOT NULL,
	[TABLENAME] [nvarchar](50) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[SIRANO] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SAYACLAR] PRIMARY KEY CLUSTERED 
(
	[SAYACLARID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_SAYACLAR] UNIQUE NONCLUSTERED 
(
	[TABLENAME] ASC,
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYACLAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYACLAR59](
	[SAYACLARID] [int] NOT NULL,
	[TABLENAME] [nvarchar](50) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[SIRANO] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMDONEM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMDONEM59](
	[SAYIMDONEMID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[BASTARIH] [smalldatetime] NULL,
	[TARIH] [smalldatetime] NULL,
	[DEVIRT] [float] NULL,
	[ALIMT] [float] NULL,
	[MALIYETT] [float] NULL,
	[SAYIMT] [float] NULL,
	[DURUM] [int] NULL,
	[DUZELTILDI] [int] NULL,
	[SAYILDI] [int] NULL,
	[RAPORALINDI] [int] NULL,
	[KAPANDI] [int] NULL,
	[USERID] [int] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[KTARIHI] [datetime] NULL,
	[TRANSFERTOPLAM] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFIS](
	[SAYIMFISID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL,
	[DEVIR] [float] NULL,
	[DEVIRTUTAR] [float] NULL,
	[ALIM] [float] NULL,
	[ALIMTUTAR] [float] NULL,
 CONSTRAINT [PK_SayimFis] PRIMARY KEY CLUSTERED 
(
	[SAYIMFISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFIS_117]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFIS_117](
	[SAYIMFISID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFIS_55]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFIS_55](
	[SAYIMFISID] [int] IDENTITY(1,1) NOT NULL,
	[TARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFIS59](
	[SAYIMFISID] [int] NOT NULL,
	[TARIH] [datetime] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL,
	[DEVIR] [float] NULL,
	[DEVIRTUTAR] [float] NULL,
	[ALIM] [float] NULL,
	[ALIMTUTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFISARSIV59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFISARSIV59](
	[SAYIMFISID] [int] NOT NULL,
	[TARIH] [datetime] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DEPOFISID] [int] NULL,
	[USERID] [int] NULL,
	[BARKOD] [nvarchar](50) NULL,
	[STOKID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SAYIM] [float] NULL,
	[KALAN] [float] NULL,
	[FARK] [float] NULL,
	[SAYIMTUTAR] [float] NULL,
	[SAYIMBIRIMI] [nvarchar](10) NULL,
	[ORTFIYAT] [float] NULL,
	[FARKTUTARI] [float] NULL,
	[MUHFC] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[KISI] [float] NULL,
	[ODA] [float] NULL,
	[EUROKUR] [float] NULL,
	[USDKUR] [float] NULL,
	[GRUPID] [int] NULL,
	[FSAYIM] [float] NULL,
	[DEVIR] [float] NULL,
	[DEVIRTUTAR] [float] NULL,
	[ALIM] [float] NULL,
	[ALIMTUTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SAYIMFISARSIVW]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAYIMFISARSIVW](
	[SayimFisId] [int] NOT NULL,
	[Tarih] [smalldatetime] NULL,
	[MOBILSAYIMDONEMID] [int] NULL,
	[DepofisID] [int] NULL,
	[UserId] [int] NULL,
	[Barkod] [nvarchar](50) NULL,
	[StokId] [int] NULL,
	[SubeId] [int] NULL,
	[DepoId] [int] NULL,
	[Sayim] [float] NULL,
	[Kalan] [float] NULL,
	[Fark] [float] NULL,
	[SayimTutar] [float] NULL,
	[SayimBirimi] [nvarchar](10) NULL,
	[OrtFiyat] [float] NULL,
	[FarkTutari] [float] NULL,
	[MUHFC] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SBIRIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SBIRIM](
	[SBIRIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BIRIM] [nvarchar](20) NULL,
	[BIRIMACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SBIRIM] PRIMARY KEY CLUSTERED 
(
	[SBIRIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SBIRIM_AR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SBIRIM_AR](
	[BIRIMID] [int] NOT NULL,
	[BIRIM] [nvarchar](15) NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SBIRIM_ARS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SBIRIM_ARS](
	[BIRIMID] [int] NOT NULL,
	[BIRIM] [nvarchar](15) NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SBIRIM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SBIRIM59](
	[SBIRIMID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BIRIM] [nvarchar](20) NULL,
	[BIRIMACIKLAMA] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SBOLUM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SBOLUM](
	[SBOLUMID] [int] IDENTITY(1,1) NOT NULL,
	[KODU] [nvarchar](10) NULL,
	[BOLUMADI] [nvarchar](50) NULL,
 CONSTRAINT [PK_SBOLUM] PRIMARY KEY CLUSTERED 
(
	[SBOLUMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_SBOLUM] UNIQUE NONCLUSTERED 
(
	[SBOLUMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SERILOT]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERILOT](
	[SERILOTID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FATID] [int] NULL,
	[FTDETAYID] [int] NULL,
	[STOKID] [int] NULL,
	[SERINO] [nvarchar](30) NULL,
	[FMIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](20) NULL,
	[FBIRIMFIYAT] [float] NULL,
	[SATFATID] [int] NULL,
	[GARANTISURE] [int] NULL,
	[GARANTISONTARIH] [smalldatetime] NULL,
	[RENK] [nvarchar](20) NULL,
	[EBAT] [nvarchar](20) NULL,
	[SASENO] [nvarchar](30) NULL,
	[MOTORNO] [nvarchar](30) NULL,
	[SERIBARKOD] [nvarchar](20) NULL,
	[TUR] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SERILOT] PRIMARY KEY CLUSTERED 
(
	[SERILOTID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SERILOT59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERILOT59](
	[SERILOTID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[FATID] [int] NULL,
	[FTDETAYID] [int] NULL,
	[STOKID] [int] NULL,
	[SERINO] [nvarchar](30) NULL,
	[FMIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](20) NULL,
	[FBIRIMFIYAT] [float] NULL,
	[SATFATID] [int] NULL,
	[GARANTISURE] [int] NULL,
	[GARANTISONTARIH] [smalldatetime] NULL,
	[RENK] [nvarchar](20) NULL,
	[EBAT] [nvarchar](20) NULL,
	[SASENO] [nvarchar](30) NULL,
	[MOTORNO] [nvarchar](30) NULL,
	[SERIBARKOD] [nvarchar](20) NULL,
	[TUR] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SERVISGOREVLI]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERVISGOREVLI](
	[SERVISGOREVLIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ADSOYAD] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](30) NULL,
	[TELEFON] [nvarchar](30) NULL,
	[TELEFON2] [nvarchar](30) NULL,
	[ADRESI] [nvarchar](250) NULL,
	[ISEGIRIS] [smalldatetime] NULL,
	[ISTENAYRILIS] [smalldatetime] NULL,
	[MAAS] [float] NULL,
	[PRIMORAN] [float] NULL,
	[ACIKLAMALAR] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SERVISGOREVLI] PRIMARY KEY CLUSTERED 
(
	[SERVISGOREVLIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SERVISPARCA]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERVISPARCA](
	[SERVISPARCAID] [int] IDENTITY(1,1) NOT NULL,
	[SERVISFORMID] [int] NULL,
	[BARKOD] [nvarchar](20) NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[MIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[KDV] [float] NULL,
	[INDY] [float] NULL,
	[INDT] [float] NULL,
	[TOPLAM] [float] NULL,
	[KDVDAHIL] [bit] NULL,
	[FATREFID] [int] NULL,
 CONSTRAINT [PK_SERVISPARCA] PRIMARY KEY CLUSTERED 
(
	[SERVISPARCAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SERVISRESIM]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SERVISRESIM](
	[SERVISRESIMID] [int] IDENTITY(1,1) NOT NULL,
	[SERVISFORMID] [int] NULL,
	[BASLIK] [nvarchar](50) NULL,
	[RESIM1] [image] NULL,
	[RESIM2] [varbinary](max) NULL,
 CONSTRAINT [PK_SERVISRESIM] PRIMARY KEY CLUSTERED 
(
	[SERVISRESIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SGRUP59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SGRUP59](
	[SGRUPID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[GRUPKODU] [nvarchar](30) NULL,
	[GRUPADI] [nvarchar](150) NULL,
	[GRUPADIENG] [nvarchar](100) NULL,
	[ANAGRUPADI] [nvarchar](50) NULL,
	[ANAGRUPADIENG] [nvarchar](50) NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[GRUPTURU] [nvarchar](20) NULL,
	[ANAGRUPMU] [bit] NULL,
	[MUHALISHESAPID] [int] NULL,
	[MUHALISIADEHESAPID] [int] NULL,
	[MUHSATISHESAPID] [int] NULL,
	[MUHSATISIADEHESAPID] [int] NULL,
	[MUHSARFHESAPID] [int] NULL,
	[MUHVIRMANHESAPID] [int] NULL,
	[POSAKTIFMI] [bit] NULL,
	[MASRAF] [int] NULL,
	[VADEGUN] [int] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL,
	[ALKOLLU] [int] NULL,
	[MUHISKONTOHESAPID] [int] NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[SKODU] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[SGRUPPOSTURU] [smallint] NULL,
	[POSGRUBU] [nvarchar](10) NULL,
	[OZELKOD1] [nvarchar](10) NULL,
	[OLDSGRUPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SIPARIS]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SIPARIS](
	[SIPARISID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[YETKILI] [nvarchar](20) NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[ENO] [nvarchar](10) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TMIKTAR] [float] NULL,
	[TTUTAR] [float] NULL,
	[SIPARISTURU] [nvarchar](10) NULL,
	[MUHFC] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[FTKESILDI] [bit] NULL,
	[FATID] [int] NULL,
 CONSTRAINT [PK_Siparis] PRIMARY KEY CLUSTERED 
(
	[SIPARISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SIPARIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SIPARIS59](
	[SIPARISID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[YETKILI] [nvarchar](20) NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[ENO] [nvarchar](10) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[TMIKTAR] [float] NULL,
	[TTUTAR] [float] NULL,
	[SIPARISTURU] [nvarchar](10) NULL,
	[MUHFC] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[FTKESILDI] [bit] NULL,
	[FATID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SIPARISDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SIPARISDETAY](
	[SIPARISDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[SIPARISID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](10) NULL,
	[FBFIYAT] [float] NULL,
	[MIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[SONBAKIYE] [float] NULL,
	[FATID] [int] NULL,
	[TOPLAM] [float] NULL,
 CONSTRAINT [PK_SIPARISDETAY] PRIMARY KEY CLUSTERED 
(
	[SIPARISDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SIPARISDETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SIPARISDETAY59](
	[SIPARISDETAYID] [int] NOT NULL,
	[SIPARISID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](10) NULL,
	[FBFIYAT] [float] NULL,
	[MIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[SONBAKIYE] [float] NULL,
	[FATID] [int] NULL,
	[TOPLAM] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITECALISAN59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITECALISAN59](
	[CALISANID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ADI_SOYADI] [nvarchar](75) NULL,
	[TELEFON] [nvarchar](15) NULL,
	[GOREVI] [nvarchar](50) NULL,
	[RESIM] [nvarchar](50) NULL,
	[EMAIL] [nvarchar](100) NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEDONEM59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEDONEM59](
	[SITEDONEMID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROJEID] [int] NULL,
	[DONEMBASI] [smalldatetime] NULL,
	[DONEMSONU] [smalldatetime] NULL,
	[ACIKLAMALAR] [nvarchar](250) NULL,
	[KAPANDI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEDUYURULAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEDUYURULAR](
	[SITEDUYURULARID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[KONU] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](50) NULL,
	[DUYURUTURID] [int] NULL,
	[DUYURU] [nvarchar](800) NULL,
	[WEBAKTIF] [bit] NULL,
	[ONEMLI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SITEDUYURULAR] PRIMARY KEY CLUSTERED 
(
	[SITEDUYURULARID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEDUYURULAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEDUYURULAR59](
	[SITEDUYURULARID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [time](7) NULL,
	[KONU] [nvarchar](250) NULL,
	[BELGENO] [nvarchar](50) NULL,
	[DUYURUTURID] [int] NULL,
	[DUYURU] [nvarchar](800) NULL,
	[WEBAKTIF] [bit] NULL,
	[ONEMLI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEGALERI59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEGALERI59](
	[GID] [int] NOT NULL,
	[RESIMURL] [nvarchar](250) NULL,
	[AKTIF] [int] NULL,
	[SIL] [int] NULL,
	[K_RESIM_URL] [nvarchar](250) NULL,
	[FIRMAID] [nchar](10) NULL,
	[SUBEID] [nchar](10) NULL,
	[TUR] [int] NULL,
	[TIP] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEGENELKURUL]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEGENELKURUL](
	[SITEGENELKURULID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[KONU] [nvarchar](150) NULL,
	[YONETICI] [nvarchar](100) NULL,
	[DENETCI] [nvarchar](100) NULL,
	[ACIKLAMALAR] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SITEGENELKURUL] PRIMARY KEY CLUSTERED 
(
	[SITEGENELKURULID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEGENELKURUL59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEGENELKURUL59](
	[SITEGENELKURULID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[KURULTURUID] [int] NULL,
	[KONU] [nvarchar](150) NULL,
	[YONETICI] [nvarchar](100) NULL,
	[DENETCI] [nvarchar](100) NULL,
	[ACIKLAMALAR] [nvarchar](250) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKONUTUR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKONUTUR](
	[SITEKONUTURID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TURU] [smallint] NULL,
	[KONU] [nvarchar](50) NULL,
	[KONUENG] [nvarchar](50) NULL,
	[KONURUS] [nvarchar](50) NULL,
	[KONUDEU] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SITEKONUTUR] PRIMARY KEY CLUSTERED 
(
	[SITEKONUTURID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKONUTUR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKONUTUR59](
	[SITEKONUTURID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TURU] [smallint] NULL,
	[KONU] [nvarchar](50) NULL,
	[KONUENG] [nvarchar](50) NULL,
	[KONURUS] [nvarchar](50) NULL,
	[KONUDEU] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKULLANICIHESAP]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKULLANICIHESAP](
	[SITEKULLANICIHESAPID] [int] IDENTITY(1,1) NOT NULL,
	[SITEKULLANICILARID] [int] NULL,
	[MUHFIRMAID] [int] NULL,
	[MUHHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
 CONSTRAINT [PK_SITEKULLANICIHESAP] PRIMARY KEY CLUSTERED 
(
	[SITEKULLANICIHESAPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKULLANICIHESAP59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKULLANICIHESAP59](
	[SITEKULLANICIHESAPID] [int] NOT NULL,
	[SITEKULLANICILARID] [int] NULL,
	[MUHFIRMAID] [int] NULL,
	[MUHHESAPID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKULLANICILAR]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKULLANICILAR](
	[SITEKULLANICILARID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ADSOYAD] [nvarchar](100) NULL,
	[TELEFON] [nvarchar](20) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[SIFRE] [nvarchar](20) NULL,
	[ADRESI] [nvarchar](200) NULL,
	[SEHIR] [nvarchar](30) NULL,
	[ULKE] [nvarchar](30) NULL,
	[DIL] [nvarchar](5) NULL,
	[DOGUMTARIHI] [smalldatetime] NULL,
	[DEFAULTFIRMA] [int] NULL,
	[YETKITIPI] [int] NULL,
	[AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SITEKULLANICILAR] PRIMARY KEY CLUSTERED 
(
	[SITEKULLANICILARID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UX_SITEKULLANICILAR] UNIQUE NONCLUSTERED 
(
	[EMAIL] ASC,
	[SIL] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITEKULLANICILAR59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITEKULLANICILAR59](
	[SITEKULLANICILARID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ADSOYAD] [nvarchar](100) NULL,
	[TELEFON] [nvarchar](20) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[SIFRE] [nvarchar](20) NULL,
	[ADRESI] [nvarchar](200) NULL,
	[SEHIR] [nvarchar](30) NULL,
	[ULKE] [nvarchar](30) NULL,
	[DIL] [nvarchar](5) NULL,
	[DOGUMTARIHI] [smalldatetime] NULL,
	[DEFAULTFIRMA] [int] NULL,
	[YETKITIPI] [int] NULL,
	[AKTIF] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SITERESIMLER59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SITERESIMLER59](
	[RESIMID] [int] NOT NULL,
	[FIRMAID] [nvarchar](10) NULL,
	[RESIMURL] [nvarchar](250) NULL,
	[ADD_USER] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_USER] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_USER] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SOZLESME]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOZLESME](
	[SOZLESMEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[SOZLESMETARIHI] [smalldatetime] NULL,
	[BITISTARIHI] [smalldatetime] NULL,
	[ILKFTARIHI] [smalldatetime] NULL,
	[AY] [int] NULL,
	[AYLIKTUTAR] [float] NULL,
	[TOPLAMTUTAR] [float] NULL,
	[KDVDAHILMI] [bit] NULL,
	[YAZILIMBEDELI] [float] NULL,
	[DONANIMBEDELI] [float] NULL,
	[DIGERBEDEL] [float] NULL,
	[YAZILIMHESAPID] [int] NULL,
	[DONANIMHESAPID] [int] NULL,
	[DIGERHESAPID] [int] NULL,
	[YAZILIMSTOKID] [int] NULL,
	[DONANIMSTOKID] [int] NULL,
	[DIGERSTOKID] [int] NULL,
	[FISTURID] [int] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[KURTARIHI] [smallint] NULL,
	[KUR] [float] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SOZLESME] PRIMARY KEY CLUSTERED 
(
	[SOZLESMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SOZLESME59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOZLESME59](
	[SOZLESMEID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[HESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[SOZLESMETARIHI] [smalldatetime] NULL,
	[BITISTARIHI] [smalldatetime] NULL,
	[ILKFTARIHI] [smalldatetime] NULL,
	[AY] [int] NULL,
	[AYLIKTUTAR] [float] NULL,
	[TOPLAMTUTAR] [float] NULL,
	[KDVDAHILMI] [bit] NULL,
	[YAZILIMBEDELI] [float] NULL,
	[DONANIMBEDELI] [float] NULL,
	[DIGERBEDEL] [float] NULL,
	[YAZILIMHESAPID] [int] NULL,
	[DONANIMHESAPID] [int] NULL,
	[DIGERHESAPID] [int] NULL,
	[YAZILIMSTOKID] [int] NULL,
	[DONANIMSTOKID] [int] NULL,
	[DIGERSTOKID] [int] NULL,
	[FISTURID] [int] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[KURTARIHI] [smallint] NULL,
	[KUR] [float] NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SOZLESMEDETAY]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOZLESMEDETAY](
	[SOZLESMEDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[SOZLESMEID] [int] NULL,
	[FTARIH] [smalldatetime] NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[YAZILIMBEDELI] [float] NULL,
	[DONANIMBEDELI] [float] NULL,
	[DIGERBEDELI] [float] NULL,
	[FTACIKLAMA] [nvarchar](150) NULL,
	[FTKESILDI] [bit] NULL,
	[FATID] [int] NULL,
 CONSTRAINT [PK_SOZLESMEDETAY] PRIMARY KEY CLUSTERED 
(
	[SOZLESMEDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SOZLESMEDETAY59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOZLESMEDETAY59](
	[SOZLESMEDETAYID] [int] NOT NULL,
	[SOZLESMEID] [int] NULL,
	[FTARIH] [smalldatetime] NULL,
	[YIL] [int] NULL,
	[AY] [int] NULL,
	[YAZILIMBEDELI] [float] NULL,
	[DONANIMBEDELI] [float] NULL,
	[DIGERBEDELI] [float] NULL,
	[FTACIKLAMA] [nvarchar](150) NULL,
	[FTKESILDI] [bit] NULL,
	[FATID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAFIS59]    Script Date: 17.07.2026 15:19:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAFIS59](
	[SPAFISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[TARIH] [smalldatetime] NULL,
	[SAAT] [datetime] NULL,
	[SPAMEKANID] [int] NULL,
	[SPAGOREVLIID] [int] NULL,
	[OTELID] [int] NULL,
	[SERVISVAR] [bit] NULL,
	[ODANO] [nvarchar](20) NULL,
	[MISAFIRADI] [nvarchar](50) NULL,
	[ACIKLAMA] [nvarchar](150) NULL,
	[TEL] [nvarchar](20) NULL,
	[KISI] [smallint] NULL,
	[TUTAR] [float] NULL,
	[INDORAN] [float] NULL,
	[NETTUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[NAKIT] [float] NULL,
	[KKARTI] [float] NULL,
	[TICKET] [float] NULL,
	[ACIK] [float] NULL,
	[KAPANDI] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[CARIID] [int] NULL,
	[INDTUTAR] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAGOREVLI59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAGOREVLI59](
	[SPAGOREVLIID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[OTELID] [int] NULL,
	[GOREVLIADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](30) NULL,
	[TGUNU] [int] NULL,
	[AKTIF] [bit] NULL,
	[SIRA] [smallint] NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[PRIMORAN] [float] NULL,
	[PRIMTUTAR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[PRIMSURE] [float] NULL,
	[SUREYEGOREPRIM] [bit] NULL,
	[AJANDAGOSTER] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[SPAMEKANID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAMEKAN59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAMEKAN59](
	[SPAMEKANID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[MEKANADI] [nvarchar](30) NULL,
	[ASAATI] [datetime] NULL,
	[KSAATI] [datetime] NULL,
	[AKTIF] [bit] NULL,
	[KAPASITE] [int] NULL,
	[SORUMLUSU] [nvarchar](30) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAODEME](
	[SPAODEMEID] [int] IDENTITY(1,1) NOT NULL,
	[SPAFISID] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL,
 CONSTRAINT [PK_SPAODEME] PRIMARY KEY CLUSTERED 
(
	[SPAODEMEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SPAODEME59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SPAODEME59](
	[SPAODEMEID] [int] NOT NULL,
	[SPAFISID] [int] NULL,
	[ODEMETURID] [int] NULL,
	[ODEMETURU] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[KUR] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[ALINANPARA] [float] NULL,
	[PARAUSTU] [float] NULL,
	[KASIYER] [nvarchar](20) NULL,
	[CARIID] [int] NULL,
	[ZAMAN] [datetime] NULL,
	[ACIKLAMA] [nvarchar](30) NULL,
	[YETKILIID] [int] NULL,
	[ISLEMTIPI] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_23072021]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_23072021](
	[STOKID] [int] IDENTITY(1,1) NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](30) NULL,
	[EK2] [nvarchar](30) NULL,
	[EK3] [nvarchar](30) NULL,
	[EK4] [nvarchar](30) NULL,
	[EK5] [nvarchar](30) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[POSYAZICIID1] [int] NULL,
	[POSYAZICIID2] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](10) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](50) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](20) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](20) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[KGSATILIR] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](20) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[GRUPID] [int] NULL,
	[BIRIM5] [nvarchar](20) NULL,
	[BIRIM5ID] [int] NULL,
	[KATSAYI5] [float] NULL,
	[BARKOD5] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDSTOKID] [int] NULL,
	[PLUNO] [nvarchar](20) NULL,
	[INDVERILIR] [bit] NULL,
	[SURE] [smallint] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_24032022]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_24032022](
	[STOKID] [int] IDENTITY(1,1) NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](30) NULL,
	[EK2] [nvarchar](30) NULL,
	[EK3] [nvarchar](30) NULL,
	[EK4] [nvarchar](30) NULL,
	[EK5] [nvarchar](30) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[POSYAZICIID1] [int] NULL,
	[POSYAZICIID2] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](10) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[OZELKOD3] [nvarchar](50) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](50) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](20) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](20) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[KGSATILIR] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](20) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[GRUPID] [int] NULL,
	[BIRIM5] [nvarchar](20) NULL,
	[BIRIM5ID] [int] NULL,
	[KATSAYI5] [float] NULL,
	[BARKOD5] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDSTOKID] [int] NULL,
	[PLUNO] [nvarchar](20) NULL,
	[INDVERILIR] [bit] NULL,
	[SURE] [smallint] NULL,
	[AGIRLIK] [float] NULL,
	[KGFIYATI] [float] NULL,
	[MARKAID] [int] NULL,
	[URETICIID] [int] NULL,
	[REYONID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_LUCA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_LUCA](
	[GRUPKODU] [nvarchar](255) NULL,
	[BARKOD] [nvarchar](255) NULL,
	[KODU] [nvarchar](255) NULL,
	[ADI] [nvarchar](255) NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SDOVIZ1] [nvarchar](255) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[KAR] [float] NULL,
	[BIRIM] [nvarchar](255) NULL,
	[BIRIM1] [nvarchar](255) NULL,
	[KATSAYI2] [nvarchar](255) NULL,
	[TURU] [nvarchar](255) NULL,
	[GGR] [nvarchar](255) NULL,
	[FATURABIRIMI] [nvarchar](255) NULL,
	[GRUPADI] [nvarchar](255) NULL,
	[GIREN] [float] NULL,
	[CIKAN] [float] NULL,
	[KALAN] [float] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_RESIMLI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_RESIMLI](
	[STOKID] [int] IDENTITY(1,1) NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[POSYAZICIID1] [int] NULL,
	[POSYAZICIID2] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](255) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](1000) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](255) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](255) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[KGSATILIR] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](100) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[GRUPID] [int] NULL,
	[BIRIM5] [nvarchar](20) NULL,
	[BIRIM5ID] [int] NULL,
	[KATSAYI5] [float] NULL,
	[BARKOD5] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDSTOKID] [int] NULL,
	[PLUNO] [nvarchar](20) NULL,
	[INDVERILIR] [bit] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_TEMP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_TEMP](
	[STOKID] [int] NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [smalldatetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[HYERI] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](255) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [smalldatetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [smalldatetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](1000) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [smalldatetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [smalldatetime] NULL,
	[SDEPOLAR] [nvarchar](255) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](255) NULL,
	[SIPYAZICI] [nvarchar](15) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[HTURU] [nvarchar](20) NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [smalldatetime] NULL,
	[MADET] [float] NULL,
	[KODAD] [nvarchar](150) NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](100) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[STOKID_V6] [int] NULL,
	[FIRMAID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK_YEDEK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK_YEDEK](
	[STOKID] [int] NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[HYERI] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](255) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](1000) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](255) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](255) NULL,
	[SIPYAZICI] [nvarchar](15) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[HTURU] [nvarchar](20) NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[KODAD] [nvarchar](150) NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](100) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOK59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOK59](
	[STOKID] [int] NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [datetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](30) NULL,
	[EK2] [nvarchar](30) NULL,
	[EK3] [nvarchar](30) NULL,
	[EK4] [nvarchar](30) NULL,
	[EK5] [nvarchar](30) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[POSYAZICIID1] [int] NULL,
	[POSYAZICIID2] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](10) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[OZELKOD2] [nvarchar](50) NULL,
	[OZELKOD3] [nvarchar](50) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [datetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [datetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](50) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [datetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [datetime] NULL,
	[SDEPOLAR] [nvarchar](20) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](20) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[KGSATILIR] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [datetime] NULL,
	[MADET] [float] NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](20) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[FIRMAID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[EDIT_DATE] [datetime] NULL,
	[DEL_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_USERID] [int] NULL,
	[GRUPID] [int] NULL,
	[BIRIM5] [nvarchar](20) NULL,
	[BIRIM5ID] [int] NULL,
	[KATSAYI5] [float] NULL,
	[BARKOD5] [nvarchar](30) NULL,
	[SKODUX] [nvarchar](30) NULL,
	[OLDSTOKID] [int] NULL,
	[PLUNO] [nvarchar](20) NULL,
	[INDVERILIR] [bit] NULL,
	[SURE] [smallint] NULL,
	[AGIRLIK] [float] NULL,
	[KGFIYATI] [float] NULL,
	[MARKAID] [int] NULL,
	[URETICIID] [int] NULL,
	[REYONID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKBIRIMLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKBIRIMLER](
	[STOKBIRIMLERID] [int] IDENTITY(1,1) NOT NULL,
	[STOKID] [int] NULL,
	[BIRIM] [nvarchar](20) NULL,
	[BIRIMID] [int] NULL,
	[CB] [nvarchar](1) NULL,
	[KATSAYI] [float] NULL,
	[ANABIRIM] [nvarchar](20) NULL,
	[ANABIRIMID] [int] NULL,
 CONSTRAINT [PK_STOKBIRIMLER] PRIMARY KEY CLUSTERED 
(
	[STOKBIRIMLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUP_OKR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUP_OKR](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NOT NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUP_RBD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUP_RBD](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUP_RK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUP_RK](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NOT NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUP_TEMP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUP_TEMP](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUPW]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUPW](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NOT NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKGRUPX]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKGRUPX](
	[KODU] [nvarchar](20) NOT NULL,
	[ADI] [nvarchar](100) NOT NULL,
	[MUHKODU] [nvarchar](50) NULL,
	[OZELKOD1] [nvarchar](50) NULL,
	[SAKLA] [int] NULL,
	[MUHNHESAPID] [int] NULL,
	[MUHSHESAPID] [int] NULL,
	[MUHGHESAPID] [int] NULL,
	[TURU] [nvarchar](10) NULL,
	[ANAGRUPUZUNLUGU] [int] NULL,
	[ALTGRUPUZUNLUGU] [int] NULL,
	[ALT2GRUPUZUNLUGU] [int] NULL,
	[ALKOLLU] [int] NULL,
	[DSATIS] [int] NULL,
	[STOKGRUPID] [int] NOT NULL,
	[MUHAISKHESAPID] [int] NULL,
	[MUHSISKHESAPID] [int] NULL,
	[POSAKTIF] [int] NULL,
	[MASRAF] [int] NULL,
	[MUHAHESAPID] [int] NULL,
	[STOKUSTGRUPID] [int] NULL,
	[STOKALTGRUPID] [int] NULL,
	[STOKANAGRUPID] [int] NULL,
	[MIADZORUNLU] [int] NULL,
	[SUBEID] [int] NULL,
	[POSGURUBU] [nvarchar](50) NULL,
	[SGBARKOD] [nvarchar](50) NULL,
	[GRUPTURUID] [int] NULL,
	[SIL] [smallint] NULL,
	[GRUPPRIM] [float] NULL,
	[VADEGUN] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKINDIRIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKINDIRIM](
	[STOKINDIRIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[ILKTARIH] [datetime] NULL,
	[SONTARIH] [datetime] NULL,
	[INDIRIMADI] [nvarchar](50) NULL,
	[STDINDIRIM] [float] NULL,
	[MANUEL] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_STOKINDIRIM] PRIMARY KEY CLUSTERED 
(
	[STOKINDIRIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKINDIRIM59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKINDIRIM59](
	[STOKINDIRIMID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[ILKTARIH] [datetime] NULL,
	[SONTARIH] [datetime] NULL,
	[INDIRIMADI] [nvarchar](50) NULL,
	[STDINDIRIM] [float] NULL,
	[MANUEL] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKINDIRIMDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKINDIRIMDETAY](
	[STOKINDIRIMDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[STOKINDIRIMID] [int] NULL,
	[KODU] [nvarchar](20) NULL,
	[BARKOD] [nvarchar](20) NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BIRIM] [nvarchar](10) NULL,
	[LISTEFIYATI] [float] NULL,
	[INDORAN] [float] NULL,
	[NETFIYAT] [float] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_STOKINDIRIMDETAY] PRIMARY KEY CLUSTERED 
(
	[STOKINDIRIMDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKINDIRIMDETAY59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKINDIRIMDETAY59](
	[STOKINDIRIMDETAYID] [int] NOT NULL,
	[STOKINDIRIMID] [int] NULL,
	[KODU] [nvarchar](20) NULL,
	[BARKOD] [nvarchar](20) NULL,
	[STOKID] [int] NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[BIRIM] [nvarchar](10) NULL,
	[LISTEFIYATI] [float] NULL,
	[INDORAN] [float] NULL,
	[NETFIYAT] [float] NULL,
	[SIL] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKMARKA59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKMARKA59](
	[MARKAID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[CARIIID] [int] NULL,
	[MARKAADI] [nvarchar](50) NOT NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKPAKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKPAKET](
	[STOKPAKETID] [int] IDENTITY(1,1) NOT NULL,
	[STOKID] [int] NULL,
	[SECSTOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BIRIM] [nvarchar](10) NULL,
	[FIYAT] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SURE] [int] NULL,
	[FIYAT2] [float] NULL,
	[DOVIZ2] [nvarchar](5) NULL,
	[FIYAT3] [float] NULL,
	[DOVIZ3] [nvarchar](5) NULL,
	[FIYAT4] [float] NULL,
	[DOVIZ4] [nvarchar](5) NULL,
 CONSTRAINT [PK_STOKPAKET] PRIMARY KEY CLUSTERED 
(
	[STOKPAKETID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKPAKET59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKPAKET59](
	[STOKPAKETID] [int] NOT NULL,
	[STOKID] [int] NULL,
	[SECSTOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[BIRIM] [nvarchar](10) NULL,
	[FIYAT] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SURE] [int] NULL,
	[FIYAT2] [float] NULL,
	[DOVIZ2] [nvarchar](5) NULL,
	[FIYAT3] [float] NULL,
	[DOVIZ3] [nvarchar](5) NULL,
	[FIYAT4] [float] NULL,
	[DOVIZ4] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKRESIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKRESIM](
	[STOKRESIMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[STOKID] [int] NOT NULL,
	[RESIM] [varbinary](max) NULL,
	[UZANTI] [nvarchar](10) NULL,
	[GENISLIK] [int] NULL,
	[YUKSEKLIK] [int] NULL,
	[SIL] [smallint] NOT NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
 CONSTRAINT [PK_STOKRESIM] PRIMARY KEY CLUSTERED 
(
	[STOKRESIMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKRESIMLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKRESIMLER](
	[STOKRESIMLERID] [int] IDENTITY(1,1) NOT NULL,
	[STOKID] [int] NULL,
	[RESIM1] [image] NULL,
	[RESIM2] [varbinary](max) NULL,
 CONSTRAINT [PK_STOKRESIMLER] PRIMARY KEY CLUSTERED 
(
	[STOKRESIMLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKW]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKW](
	[STOKID] [int] NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [smalldatetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[HYERI] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](255) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [smalldatetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [smalldatetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](1000) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [smalldatetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [smalldatetime] NULL,
	[SDEPOLAR] [nvarchar](255) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](255) NULL,
	[SIPYAZICI] [nvarchar](15) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[HTURU] [nvarchar](20) NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [smalldatetime] NULL,
	[MADET] [float] NULL,
	[KODAD] [nvarchar](150) NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](100) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[STOKX]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[STOKX](
	[STOKID] [int] NOT NULL,
	[GRUP] [nvarchar](10) NULL,
	[BARKOD] [nvarchar](30) NULL,
	[KODU] [nvarchar](30) NOT NULL,
	[ADI] [nvarchar](100) NULL,
	[SSATICI] [int] NULL,
	[SALISFIYAT] [float] NULL,
	[SFATURANO] [nvarchar](20) NULL,
	[SFATTARIHI] [smalldatetime] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[AMIKTAR] [float] NULL,
	[OPTMIKTAR] [float] NULL,
	[ROMRU] [nvarchar](20) NULL,
	[RNO] [nvarchar](20) NULL,
	[EK1] [nvarchar](50) NULL,
	[EK2] [nvarchar](50) NULL,
	[EK3] [nvarchar](50) NULL,
	[EK4] [nvarchar](50) NULL,
	[EK5] [nvarchar](50) NULL,
	[ALISKDV] [float] NULL,
	[SATISKDV] [float] NULL,
	[ETIKETTIPI] [int] NULL,
	[BIRIM] [nvarchar](15) NULL,
	[BIRIM2] [nvarchar](15) NULL,
	[KATSAYI2] [float] NULL,
	[BIRIM3] [nvarchar](15) NULL,
	[KATSAYI3] [float] NULL,
	[BIRIM4] [nvarchar](15) NULL,
	[KATSAYI4] [float] NULL,
	[SAKLA] [int] NULL,
	[SKOMORAN] [float] NULL,
	[BKOMORAN] [float] NULL,
	[ALISIND] [float] NULL,
	[SATISIND] [float] NULL,
	[NAKLIYE] [float] NULL,
	[SKARY] [float] NULL,
	[BARKOD2] [nvarchar](20) NULL,
	[BARKOD3] [nvarchar](20) NULL,
	[BARKOD4] [nvarchar](20) NULL,
	[TURU] [nvarchar](10) NULL,
	[URETDEPOID] [int] NULL,
	[BEKLALISFIYAT] [float] NULL,
	[SFIYAT1KDV] [bit] NULL,
	[SFIYAT2KDV] [bit] NULL,
	[SFIYAT3KDV] [bit] NULL,
	[SFIYAT4KDV] [bit] NULL,
	[SFIYAT5KDV] [bit] NULL,
	[MALIYET] [float] NULL,
	[HYERI] [int] NULL,
	[AI] [bit] NULL,
	[INDGRUP] [int] NULL,
	[SDEPART] [nvarchar](255) NULL,
	[UAI] [bit] NULL,
	[GGRUP] [nvarchar](5) NULL,
	[ODENMEZ] [bit] NULL,
	[HLISTE] [bit] NULL,
	[GADET] [float] NULL,
	[HEDEFCOST] [float] NULL,
	[POSTURU] [nvarchar](1) NULL,
	[KDV] [int] NULL,
	[OPTIMAL] [float] NULL,
	[ASGARI] [float] NULL,
	[RAFNO] [nvarchar](15) NULL,
	[RAFOMRU] [nvarchar](20) NULL,
	[GARANTISURESI] [int] NULL,
	[OZELKOD1] [nvarchar](30) NULL,
	[OZELKOD2] [nvarchar](30) NULL,
	[OZELKOD3] [nvarchar](30) NULL,
	[EKKOD] [nvarchar](15) NULL,
	[SONALISF] [float] NULL,
	[SONSATICI] [nvarchar](30) NULL,
	[ALISTARIH] [smalldatetime] NULL,
	[SFIYAT] [float] NULL,
	[SONKULLANMA] [smalldatetime] NULL,
	[ABUFE] [bit] NULL,
	[KISISAYISI] [float] NULL,
	[RECETEBIRIMI] [nvarchar](15) NULL,
	[RECETEKATSAYISI] [float] NULL,
	[SAYIMDURUMU] [int] NULL,
	[UHHOUR] [bit] NULL,
	[EKBILGI] [nvarchar](1000) NULL,
	[COSTFACTOR] [float] NULL,
	[VARSAYILANBIRIM] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[ORTFIYAT] [float] NULL,
	[SONKT] [smalldatetime] NULL,
	[SUBEID] [int] NULL,
	[SONMALIYET] [float] NULL,
	[KKALDIR] [int] NULL,
	[RANDEVUZORUNLU] [int] NULL,
	[ACKZORUNLU] [int] NULL,
	[KONTURLU] [int] NULL,
	[SGIDERY] [float] NULL,
	[KARY] [float] NULL,
	[BIRIMID] [int] NULL,
	[BIRIM2ID] [int] NULL,
	[BIRIM3ID] [int] NULL,
	[BIRIM4ID] [int] NULL,
	[SALISFBIRIM] [nvarchar](15) NULL,
	[SALISFBFIYAT] [float] NULL,
	[SKODU] [nvarchar](50) NULL,
	[SAYIMBIRIMI] [nvarchar](15) NULL,
	[SALISBFIYAT] [float] NULL,
	[SONAMIKTAR] [float] NULL,
	[SONABIRIM] [nvarchar](20) NULL,
	[STEVORAN] [nvarchar](5) NULL,
	[SONKT2] [smalldatetime] NULL,
	[SDEPOLAR] [nvarchar](255) NULL,
	[ALERJEN] [int] NULL,
	[PISIRMEMETOD] [nvarchar](20) NULL,
	[PISIRMESICAKLIK] [float] NULL,
	[SUNUMSICAKLIK] [float] NULL,
	[SOGUTMASICAKLIK] [float] NULL,
	[SAKLAMASICAKLIK] [float] NULL,
	[PISIRMESURE] [float] NULL,
	[SUNUMSURE] [float] NULL,
	[SOGUTMASURE] [float] NULL,
	[HAZIRLIK] [ntext] NULL,
	[GERIDONER] [bit] NULL,
	[STOKGRUPID] [int] NULL,
	[RGRUP] [nvarchar](10) NULL,
	[SDKONTROL] [nvarchar](255) NULL,
	[SIPYAZICI] [nvarchar](15) NULL,
	[RAPORKATSAYISINET] [float] NULL,
	[STDFIREORANI] [float] NULL,
	[RAPORKATSAYISI] [float] NULL,
	[HTURU] [nvarchar](20) NULL,
	[SERVIS] [int] NULL,
	[OTOTUKET] [bit] NULL,
	[FATURABIRIMI] [nvarchar](20) NULL,
	[SAKLAMASURE] [float] NULL,
	[PISIRMEMETODU] [nvarchar](20) NULL,
	[DSATIS] [bit] NULL,
	[SISEBARKODTAKIP] [bit] NULL,
	[STOKTURUID] [int] NULL,
	[URETILMEZ] [bit] NULL,
	[IKINCIURUNIND] [bit] NULL,
	[KAREKODU] [nvarchar](30) NULL,
	[STOKRESIM] [image] NULL,
	[TGIREN] [float] NULL,
	[TCIKAN] [float] NULL,
	[BADET] [int] NULL,
	[SIL] [smallint] NULL,
	[ETERAZI] [bit] NULL,
	[RENKGRUPID] [int] NULL,
	[BEDENGRUPID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[SONTARIH] [smalldatetime] NULL,
	[PSTOK] [bit] NULL,
	[GUNCELLEME] [smalldatetime] NULL,
	[MADET] [float] NULL,
	[KODAD] [nvarchar](150) NULL,
	[SERILOTVAR] [bit] NULL,
	[SONINDORAN1] [float] NULL,
	[SONINDORAN2] [float] NULL,
	[ZR_URETICIFIRMA] [int] NULL,
	[ZR_RUHSATTARIHI] [smalldatetime] NULL,
	[ZR_FORMUL] [nvarchar](100) NULL,
	[ZR_RUHSATNO] [nvarchar](30) NULL,
	[SDOVIZ1] [nvarchar](10) NULL,
	[SDOVIZ2] [nvarchar](10) NULL,
	[SDOVIZ3] [nvarchar](10) NULL,
	[SDOVIZ4] [nvarchar](10) NULL,
	[SDOVIZ5] [nvarchar](10) NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[OTVID] [int] NULL,
	[OLDSTOKID] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBEBANKA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBEBANKA](
	[SUBEBANKAID] [int] IDENTITY(1,1) NOT NULL,
	[SUBEID] [int] NULL,
	[FIRMAID] [int] NULL,
	[HESAPADI] [nvarchar](50) NULL,
	[SWIFTKODU] [nvarchar](15) NULL,
	[BANKA] [nvarchar](50) NULL,
	[SUBE] [nvarchar](30) NULL,
	[HESAPNO] [nvarchar](20) NULL,
	[IBAN] [nvarchar](40) NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_SUBEBANKA] PRIMARY KEY CLUSTERED 
(
	[SUBEBANKAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBEFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBEFIYAT](
	[SUBEFIYATID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[STOKID] [int] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[DOVIZ1] [nvarchar](5) NULL,
	[DOVIZ2] [nvarchar](5) NULL,
	[DOVIZ3] [nvarchar](5) NULL,
	[DOVIZ4] [nvarchar](5) NULL,
	[DOVIZ5] [nvarchar](5) NULL,
	[GRUPKODU] [nvarchar](10) NULL,
	[KAYITDURUM] [smallint] NULL,
 CONSTRAINT [PK_SUBEFIYAT] PRIMARY KEY CLUSTERED 
(
	[SUBEFIYATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBEFIYAT59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBEFIYAT59](
	[SUBEFIYATID] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[STOKID] [int] NULL,
	[SFIYAT1] [float] NULL,
	[SFIYAT2] [float] NULL,
	[SFIYAT3] [float] NULL,
	[SFIYAT4] [float] NULL,
	[SFIYAT5] [float] NULL,
	[SDOVIZ] [nvarchar](10) NULL,
	[DOVIZ1] [nvarchar](5) NULL,
	[DOVIZ2] [nvarchar](5) NULL,
	[DOVIZ3] [nvarchar](5) NULL,
	[DOVIZ4] [nvarchar](5) NULL,
	[DOVIZ5] [nvarchar](5) NULL,
	[GRUPKODU] [nvarchar](10) NULL,
	[KAYITDURUM] [smallint] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBELER_AR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBELER_AR](
	[SUBEID] [int] NOT NULL,
	[SUBEKODU] [nvarchar](10) NULL,
	[SUBEADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[ADRES1] [nvarchar](50) NULL,
	[ADRES2] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[YAZUNVANI] [nvarchar](150) NULL,
	[GENELMUDUR] [nvarchar](50) NULL,
	[MUHASEBE] [nvarchar](50) NULL,
	[SATINALMA] [nvarchar](50) NULL,
	[ONBURO] [nvarchar](50) NULL,
	[COST] [nvarchar](50) NULL,
	[PERSONEL] [nvarchar](50) NULL,
	[ORTAK] [nvarchar](50) NULL,
	[LOGO] [image] NULL,
	[HOTELCONNSTR] [nvarchar](500) NULL,
	[SIRKETKODU] [nvarchar](50) NULL,
	[PERSONELCONNSTR] [nvarchar](500) NULL,
	[SUBEIPNO] [nvarchar](20) NULL,
	[ETSCONNSTR] [nvarchar](500) NULL,
	[SUBEVD] [nvarchar](20) NULL,
	[SUBEVDNO] [nvarchar](20) NULL,
	[KILITTARIHI] [smalldatetime] NULL,
	[SAYIMKILITTARIHI] [smalldatetime] NULL,
	[TRANSFERHESAPID] [int] NULL,
	[SUBEADRES] [nvarchar](250) NULL,
	[SUBEIL] [nvarchar](50) NULL,
	[SUBEILCE] [nvarchar](50) NULL,
	[SUBEPKODU] [nvarchar](10) NULL,
	[TSICILNO] [nvarchar](50) NULL,
	[MERSISNO] [nvarchar](50) NULL,
	[IL] [nvarchar](50) NULL,
	[ILCE] [nvarchar](50) NULL,
	[EFATURA_GONETIKET] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[SUBEFAX] [nvarchar](20) NULL,
	[SUBETEL] [nvarchar](20) NULL,
	[FIRMAID] [int] NULL,
	[MEDISOFTCONNSTR] [nvarchar](500) NULL,
	[EFATURA_WSDL] [nvarchar](250) NULL,
	[EFATURA_KULLANICI] [nvarchar](50) NULL,
	[EFATURA_PAROLA] [nvarchar](50) NULL,
	[EFATURA_PREFIKS] [nvarchar](3) NULL,
	[WEB] [nvarchar](200) NULL,
	[EMAIL] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[MERKEZSUBEID] [int] NULL,
	[EFATURA_SUBEKODU] [nvarchar](20) NULL,
	[EFATURA_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_KASAKODU] [nvarchar](20) NULL,
	[EARSIV_WSDL] [nvarchar](250) NULL,
	[EARSIV_KULLANICI] [nvarchar](30) NULL,
	[EARSIV_PAROLA] [nvarchar](30) NULL,
	[EDONUSUMTARIH] [smalldatetime] NULL,
	[EFATURA_AUTWSDL] [nvarchar](250) NULL,
	[EIRSALIYE_WSDL] [nvarchar](250) NULL,
	[EIRSALIYE_KULLANICI] [nvarchar](30) NULL,
	[EIRSALIYE_PAROLA] [nvarchar](30) NULL,
	[EIRSALIYE_PREFIKS] [nvarchar](3) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBELER_ARS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBELER_ARS](
	[SUBEID] [int] NOT NULL,
	[SUBEKODU] [nvarchar](10) NULL,
	[SUBEADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[ADRES1] [nvarchar](50) NULL,
	[ADRES2] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[YAZUNVANI] [nvarchar](150) NULL,
	[GENELMUDUR] [nvarchar](50) NULL,
	[MUHASEBE] [nvarchar](50) NULL,
	[SATINALMA] [nvarchar](50) NULL,
	[ONBURO] [nvarchar](50) NULL,
	[COST] [nvarchar](50) NULL,
	[PERSONEL] [nvarchar](50) NULL,
	[ORTAK] [nvarchar](50) NULL,
	[LOGO] [image] NULL,
	[HOTELCONNSTR] [nvarchar](500) NULL,
	[SIRKETKODU] [nvarchar](50) NULL,
	[PERSONELCONNSTR] [nvarchar](500) NULL,
	[SUBEIPNO] [nvarchar](20) NULL,
	[ETSCONNSTR] [nvarchar](500) NULL,
	[SUBEVD] [nvarchar](20) NULL,
	[SUBEVDNO] [nvarchar](20) NULL,
	[KILITTARIHI] [smalldatetime] NULL,
	[SAYIMKILITTARIHI] [smalldatetime] NULL,
	[TRANSFERHESAPID] [int] NULL,
	[SUBEADRES] [nvarchar](250) NULL,
	[SUBEIL] [nvarchar](50) NULL,
	[SUBEILCE] [nvarchar](50) NULL,
	[SUBEPKODU] [nvarchar](10) NULL,
	[TSICILNO] [nvarchar](50) NULL,
	[MERSISNO] [nvarchar](50) NULL,
	[IL] [nvarchar](50) NULL,
	[ILCE] [nvarchar](50) NULL,
	[EFATURA_GONETIKET] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[SUBEFAX] [nvarchar](20) NULL,
	[SUBETEL] [nvarchar](20) NULL,
	[FIRMAID] [int] NULL,
	[MEDISOFTCONNSTR] [nvarchar](500) NULL,
	[EFATURA_WSDL] [nvarchar](250) NULL,
	[EFATURA_KULLANICI] [nvarchar](50) NULL,
	[EFATURA_PAROLA] [nvarchar](50) NULL,
	[EFATURA_PREFIKS] [nvarchar](3) NULL,
	[WEB] [nvarchar](200) NULL,
	[EMAIL] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[MERKEZSUBEID] [int] NULL,
	[EFATURA_SUBEKODU] [nvarchar](20) NULL,
	[EFATURA_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_KASAKODU] [nvarchar](20) NULL,
	[EARSIV_WSDL] [nvarchar](250) NULL,
	[EARSIV_KULLANICI] [nvarchar](30) NULL,
	[EARSIV_PAROLA] [nvarchar](30) NULL,
	[EDONUSUMTARIH] [smalldatetime] NULL,
	[EFATURA_AUTWSDL] [nvarchar](250) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBELER59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBELER59](
	[SUBEID] [int] NOT NULL,
	[SUBEKODU] [nvarchar](10) NULL,
	[SUBEADI] [nvarchar](50) NULL,
	[TEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[ADRES1] [nvarchar](50) NULL,
	[ADRES2] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[YAZUNVANI] [nvarchar](150) NULL,
	[GENELMUDUR] [nvarchar](50) NULL,
	[MUHASEBE] [nvarchar](50) NULL,
	[SATINALMA] [nvarchar](50) NULL,
	[ONBURO] [nvarchar](50) NULL,
	[COST] [nvarchar](50) NULL,
	[PERSONEL] [nvarchar](50) NULL,
	[ORTAK] [nvarchar](50) NULL,
	[LOGO] [image] NULL,
	[HOTELCONNSTR] [nvarchar](500) NULL,
	[SIRKETKODU] [nvarchar](50) NULL,
	[PERSONELCONNSTR] [nvarchar](500) NULL,
	[SUBEIPNO] [nvarchar](20) NULL,
	[ETSCONNSTR] [nvarchar](500) NULL,
	[SUBEVD] [nvarchar](20) NULL,
	[SUBEVDNO] [nvarchar](20) NULL,
	[KILITTARIHI] [datetime] NULL,
	[SAYIMKILITTARIHI] [datetime] NULL,
	[TRANSFERHESAPID] [int] NULL,
	[SUBEADRES] [nvarchar](250) NULL,
	[SUBEIL] [nvarchar](50) NULL,
	[SUBEILCE] [nvarchar](50) NULL,
	[SUBEPKODU] [nvarchar](10) NULL,
	[TSICILNO] [nvarchar](50) NULL,
	[MERSISNO] [nvarchar](50) NULL,
	[IL] [nvarchar](50) NULL,
	[ILCE] [nvarchar](50) NULL,
	[EFATURA_GONETIKET] [nvarchar](250) NULL,
	[EFATURA_PKUTUSU] [nvarchar](250) NULL,
	[SUBEFAX] [nvarchar](20) NULL,
	[SUBETEL] [nvarchar](20) NULL,
	[FIRMAID] [int] NULL,
	[MEDISOFTCONNSTR] [nvarchar](500) NULL,
	[EFATURA_WSDL] [nvarchar](250) NULL,
	[EFATURA_KULLANICI] [nvarchar](50) NULL,
	[EFATURA_PAROLA] [nvarchar](50) NULL,
	[EFATURA_PREFIKS] [nvarchar](3) NULL,
	[WEB] [nvarchar](200) NULL,
	[EMAIL] [nvarchar](200) NULL,
	[SIL] [smallint] NULL,
	[MERKEZSUBEID] [int] NULL,
	[EFATURA_SUBEKODU] [nvarchar](20) NULL,
	[EFATURA_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_ONLINE_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_PREFIKS] [nvarchar](3) NULL,
	[EARSIV_KASAKODU] [nvarchar](20) NULL,
	[EARSIV_WSDL] [nvarchar](250) NULL,
	[EARSIV_KULLANICI] [nvarchar](30) NULL,
	[EARSIV_PAROLA] [nvarchar](30) NULL,
	[EFATURA_AUTWSDL] [nvarchar](250) NULL,
	[EDONUSUMTARIH] [smalldatetime] NULL,
	[EIRSALIYE_WSDL] [nvarchar](250) NULL,
	[EIRSALIYE_KULLANICI] [nvarchar](30) NULL,
	[EIRSALIYE_PAROLA] [nvarchar](30) NULL,
	[EIRSALIYE_PREFIKS] [nvarchar](3) NULL,
	[EMUSTAHSIL_WSDL] [nvarchar](250) NULL,
	[EMUSTAHSIL_KULLANICI] [nvarchar](30) NULL,
	[EMUSTAHSIL_PAROLA] [nvarchar](30) NULL,
	[EMUSTAHSIL_PREFIKS] [nvarchar](3) NULL,
	[ESMM_WSDL] [nvarchar](250) NULL,
	[ESMM_KULLANICI] [nvarchar](30) NULL,
	[ESMM_PAROLA] [nvarchar](30) NULL,
	[ESMM_PREFIKS] [nvarchar](3) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[IKSUBEID] [int] NULL,
	[EIRSALIYE_GONETIKET] [nvarchar](50) NULL,
	[EIRSALIYE_PKUTUSU] [nvarchar](50) NULL,
	[UZAKHOTELCONNSTR] [nvarchar](500) NULL,
	[BANKAIBAN] [nvarchar](26) NULL,
	[OLDSUBEID] [int] NULL,
	[SUBESQLIP] [nvarchar](50) NULL,
	[SUBESQLUSER] [nvarchar](30) NULL,
	[SUBESQLPASS] [nvarchar](30) NULL,
	[SUBESQLDB] [nvarchar](30) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SUBESABLON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SUBESABLON](
	[SUBESABLONID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DOSYAADI] [nvarchar](30) NULL,
	[DOSYA] [text] NULL,
	[TURU] [nvarchar](10) NULL,
 CONSTRAINT [PK_SUBESABLON] PRIMARY KEY CLUSTERED 
(
	[SUBESABLONID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_ACENTAFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_ACENTAFIYAT](
	[ACENTAFIYATID] [int] IDENTITY(1,1) NOT NULL,
	[ACENTALARID] [int] NULL,
	[PROGRAMID] [int] NULL,
	[BASLANGIC] [smalldatetime] NULL,
	[BITIS] [smalldatetime] NULL,
	[KISIFIYAT] [float] NULL,
	[CCKFIYAT] [float] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[EKFIYAT] [float] NULL,
	[DBLFIYAT] [float] NULL,
 CONSTRAINT [PK_T_ACENTAFIYAT] PRIMARY KEY CLUSTERED 
(
	[ACENTAFIYATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_ACENTALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_ACENTALAR](
	[ACENTALARID] [int] IDENTITY(1,1) NOT NULL,
	[ANAACENTAID] [int] NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[OZELKOD] [nvarchar](20) NULL,
	[KODU] [nvarchar](20) NULL,
	[UNVANI] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](50) NULL,
	[ADRES] [nvarchar](100) NULL,
	[ADRES2] [nvarchar](100) NULL,
	[TEL] [nvarchar](20) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[IL] [nvarchar](15) NULL,
	[ILCE] [nvarchar](15) NULL,
	[HESAPID] [int] NULL,
	[BELDEID] [int] NULL,
	[VD] [nvarchar](20) NULL,
	[VDNO] [nvarchar](15) NULL,
	[EMAIL] [nvarchar](30) NULL,
	[WEB] [nvarchar](30) NULL,
	[DVZ] [nvarchar](5) NULL,
	[ODEMEYONTEMI] [nvarchar](20) NULL,
	[PRFIYATIKULLAN] [bit] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[REHBER] [nvarchar](20) NULL,
	[FATURAKESME] [bit] NULL,
	[KURTARIHI] [bit] NULL,
	[CARIISLE] [bit] NULL,
	[MERKEZFIRMAID] [int] NULL,
	[MERKEZACENTAID] [int] NULL,
	[KULLANICIKODU] [nvarchar](50) NULL,
	[KULLANICISIFRE] [nvarchar](20) NULL,
	[AKTIF] [bit] NULL,
 CONSTRAINT [PK_ACENTALAR] PRIMARY KEY CLUSTERED 
(
	[ACENTALARID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_ARAC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_ARAC](
	[ARACID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PLAKA] [nvarchar](15) NULL,
	[MARKA] [nvarchar](30) NULL,
	[MODELYILI] [nvarchar](4) NULL,
	[KAPASITE] [int] NULL,
	[DOLUKISI] [int] NULL,
	[PROGRAMID] [int] NULL,
	[BOLGEID] [int] NULL,
	[SOFORID] [int] NULL,
	[ARACSAHIBI] [nvarchar](30) NULL,
	[ARACSAHIBITEL] [nvarchar](30) NULL,
	[AKTIF] [bit] NULL,
	[ARACNOT] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[MERKEZARACID] [int] NULL,
 CONSTRAINT [PK_T_ARAC] PRIMARY KEY CLUSTERED 
(
	[ARACID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_BELDE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_BELDE](
	[BELDEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BELDEADI] [nvarchar](30) NULL,
	[ARACFIYATI] [float] NULL,
	[KISIFIYATI] [float] NULL,
	[DVZ] [nvarchar](10) NULL,
	[BOLGEADI] [nvarchar](20) NULL,
	[BOLGEID] [int] NULL,
	[UZAKLIK] [int] NULL,
	[BELDESIRANO] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[MERKEZBELDEID] [int] NULL,
 CONSTRAINT [PK_T_BELDE] PRIMARY KEY CLUSTERED 
(
	[BELDEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_BOLGE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_BOLGE](
	[BOLGEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[BOLGE] [nvarchar](20) NULL,
	[UCRET] [float] NULL,
	[UCRETDVZ] [nvarchar](10) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[MERKEZBOLGEID] [int] NULL,
 CONSTRAINT [PK_T_BOLGE] PRIMARY KEY CLUSTERED 
(
	[BOLGEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_OTELLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_OTELLER](
	[OTELLERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[OKODU] [nvarchar](20) NULL,
	[KODU] [nvarchar](20) NULL,
	[OTELADI] [nvarchar](20) NULL,
	[FIRMAADI] [nvarchar](50) NULL,
	[YETKILI] [nvarchar](20) NULL,
	[ADRES] [nvarchar](100) NULL,
	[IL] [nvarchar](20) NULL,
	[ILCE] [nvarchar](20) NULL,
	[BELDE] [nvarchar](20) NULL,
	[TEL] [nvarchar](20) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[FAX] [nvarchar](20) NULL,
	[BOLGE] [nvarchar](20) NULL,
	[UZAKLIKKM] [float] NULL,
	[YON] [nvarchar](10) NULL,
	[STDSAAT] [time](7) NULL,
	[BELDEID] [int] NULL,
	[HESAPID] [int] NULL,
	[BOLGEID] [int] NULL,
	[DOVIZ] [nvarchar](5) NULL,
	[SIRANO] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[OGLENSAAT] [time](7) NULL,
	[AKSAMSAAT] [time](7) NULL,
	[MERKEZOTELID] [int] NULL,
 CONSTRAINT [PK_OTELLER] PRIMARY KEY CLUSTERED 
(
	[OTELLERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_PROGRAMLAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_PROGRAMLAR](
	[PROGRAMID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROGRAMGRUPID] [int] NULL,
	[PROGRAMKODU] [nvarchar](50) NULL,
	[PROGRAMADI] [nvarchar](50) NULL,
	[DIL] [nvarchar](5) NULL,
	[DURUM] [nvarchar](20) NULL,
	[DURUMID] [int] NULL,
	[ACENTAFIYATI] [float] NULL,
	[MUNFERITFIYATI] [float] NULL,
	[ACENTACCKFIYATI] [float] NULL,
	[MUNFERITCCKFIYATI] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[BASLAMASAATI] [time](7) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[ZAMANTURU] [nvarchar](5) NULL,
	[GELIRHESAPID] [int] NULL,
	[MERKEZPROGRAMID] [int] NULL,
 CONSTRAINT [PK_T_PROGRAMLAR] PRIMARY KEY CLUSTERED 
(
	[PROGRAMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_PROGRAMOTEL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_PROGRAMOTEL](
	[PROGRAMOTELSIRAID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[PROGRAMID] [int] NULL,
	[OTELID] [int] NULL,
	[SIRA] [int] NULL,
	[ADD_USERID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[SIL] [tinyint] NULL,
	[SABAHSAAT] [time](7) NULL,
	[OGLENSAAT] [time](7) NULL,
	[AKSAMSAAT] [time](7) NULL,
 CONSTRAINT [PK_T_PROGRAMOTEL] PRIMARY KEY CLUSTERED 
(
	[PROGRAMOTELSIRAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_REHBER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_REHBER](
	[REHBERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ACENTAID] [int] NULL,
	[ADSOYAD] [nvarchar](30) NULL,
	[ADRES] [nvarchar](150) NULL,
	[TELEFON] [nvarchar](30) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_T_REHBER] PRIMARY KEY CLUSTERED 
(
	[REHBERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_SOFOR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_SOFOR](
	[SOFORID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[KODU] [nvarchar](50) NOT NULL,
	[ADISOYADI] [nvarchar](25) NULL,
	[ADRES] [nvarchar](100) NULL,
	[TEL] [nvarchar](20) NULL,
	[CEPTEL] [nvarchar](20) NULL,
	[ARACPLAKA] [nvarchar](15) NULL,
	[ARACMODEL] [nvarchar](15) NULL,
	[ARACMARKA] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
	[ARACKAPASITE] [int] NULL,
	[CALISIYOR] [bit] NULL,
	[ATANANKISI] [int] NULL,
	[BOLGEID] [int] NULL,
	[BELDEID] [int] NULL,
	[HESAPID] [int] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[MERKEZSOFORID] [int] NULL,
	[KULLANICIKODU] [nvarchar](50) NULL,
	[KULLANICISIFRE] [nvarchar](20) NULL,
	[GRUP] [nvarchar](10) NULL,
 CONSTRAINT [PK_SOFORID] PRIMARY KEY CLUSTERED 
(
	[SOFORID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[T_TURREZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_TURREZ](
	[REZKNO] [int] NOT NULL,
	[ENO] [nvarchar](10) NULL,
	[TARIH] [smalldatetime] NULL,
	[GSAATI] [datetime] NULL,
	[ACENTAID] [int] NULL,
	[ACENTAKOD] [nvarchar](20) NULL,
	[ACENTA] [nvarchar](20) NULL,
	[OTELID] [int] NULL,
	[OKODU] [nvarchar](20) NULL,
	[OTELADI] [nvarchar](20) NULL,
	[MADISOYADI] [nvarchar](25) NULL,
	[ODANO] [nvarchar](10) NULL,
	[KISI] [float] NULL,
	[FREEKISI] [float] NULL,
	[BOLGEID] [int] NULL,
	[BOLGE] [nvarchar](20) NULL,
	[SOFORID] [int] NULL,
	[SOFOR] [nvarchar](20) NULL,
	[BOLUNDU] [nvarchar](5) NULL,
	[UYARINOTU] [nvarchar](100) NULL,
	[GENELNOT] [nvarchar](100) NULL,
	[YETKILI] [nvarchar](15) NULL,
	[KM] [float] NULL,
	[GSOFORID] [int] NULL,
	[GSOFOR] [nvarchar](20) NULL,
	[TUTAR] [float] NULL,
	[DVZ] [nvarchar](5) NULL,
	[ODEMEYONTEMI] [nvarchar](15) NULL,
	[SIL] [smallint] NULL,
	[REZDURUMID] [tinyint] NULL,
	[REHBERID] [int] NULL,
	[SATISTARIHI] [smalldatetime] NULL,
	[KUR] [float] NULL,
	[GELIRHESAPID] [int] NULL,
	[ISLEMGRUPID] [int] NULL,
	[SUBEID] [int] NULL,
	[ALINAN] [float] NULL,
	[TKISI] [int] NULL,
	[TEKNEID] [int] NULL,
	[PROGRAMID] [int] NULL,
	[PROGRAMGRUPID] [int] NULL,
	[UCRCCK] [float] NULL,
	[BELDEID] [int] NULL,
	[EKFIYAT] [float] NULL,
	[REHBER] [nvarchar](20) NULL,
	[REZDURUMU] [nvarchar](10) NULL,
	[ZAMANTIPI] [nvarchar](5) NULL,
	[FATID] [int] NULL,
	[OTELKM] [float] NULL,
	[FTKESILDI] [bit] NULL,
	[MUHFISID] [int] NULL,
	[REZUUID] [uniqueidentifier] NULL,
	[TAHSILATKUR] [float] NULL,
	[MERKEZREZID] [int] NULL,
	[SATISTUTARI] [float] NULL,
	[TAHSILAT] [float] NULL,
	[ARACPLAKAID] [int] NULL,
	[PROGRAMOTELSIRAID] [int] NULL,
 CONSTRAINT [PK_TURREZ] PRIMARY KEY CLUSTERED 
(
	[REZKNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TAKSITFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TAKSITFIYAT](
	[TAKSITFIYATID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[STDKOMISYON] [float] NULL,
	[AKTIF] [bit] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_TAKSITFIYAT] PRIMARY KEY CLUSTERED 
(
	[TAKSITFIYATID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TAKSITFIYATDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TAKSITFIYATDETAY](
	[TAKSITFIYATDETAYID] [int] IDENTITY(1,1) NOT NULL,
	[TAKSITFIYATID] [int] NULL,
	[STOKID] [int] NULL,
	[FIYAT] [float] NULL,
	[DOVIZ] [nvarchar](10) NULL,
	[OZELFIYAT] [float] NULL,
	[ORAN] [float] NULL,
 CONSTRAINT [PK_TAKSITFIYATDETAY] PRIMARY KEY CLUSTERED 
(
	[TAKSITFIYATDETAYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TMATRIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TMATRIS](
	[TMATRISID] [int] IDENTITY(1,1) NOT NULL,
	[FATID] [int] NULL,
	[STOKID] [int] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL,
	[RENK] [nvarchar](50) NULL,
	[BEDEN] [nvarchar](15) NULL,
	[MIKTAR] [float] NULL,
	[COL] [int] NULL,
	[ROW] [int] NULL,
 CONSTRAINT [PK_TMATRIS] PRIMARY KEY CLUSTERED 
(
	[TMATRISID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUKETIMFIS59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUKETIMFIS59](
	[DEPOFISID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[TARIH] [datetime] NULL,
	[SAAT] [time](7) NULL,
	[YETKILI] [nvarchar](15) NULL,
	[USERID] [int] NULL,
	[ISLEM] [nvarchar](10) NULL,
	[ENO] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[GDEPOID] [int] NULL,
	[CDEPOID] [int] NULL,
	[TADET] [float] NULL,
	[TTUTAR] [float] NULL,
	[GSKODU] [nvarchar](10) NULL,
	[CSKODU] [nvarchar](10) NULL,
	[URUNFISID] [int] NULL,
	[URETILDI] [bit] NULL,
	[LOGOAKTAR] [int] NULL,
	[LOGODANGELDI] [bit] NULL,
	[ISLEMDETAY] [nvarchar](50) NULL,
	[SDEPART] [nvarchar](15) NULL,
	[ONAY] [bit] NULL,
	[MUHFISID] [int] NULL,
	[DURUMU] [int] NULL,
	[CSUBEID] [int] NULL,
	[GSUBEID] [int] NULL,
	[MUHFC] [int] NULL,
	[BARKODBASILDI] [bit] NULL,
	[BMALIYET] [float] NULL,
	[MUHASEBELESTIRME] [bit] NULL,
	[OZELKOD1] [nvarchar](20) NULL,
	[INDORAN] [float] NULL,
	[INDTUTAR] [float] NULL,
	[HESAPID] [int] NULL,
	[KHESAPID] [int] NULL,
	[ALTCARIID] [int] NULL,
	[ISLEMGRUPID1] [int] NULL,
	[ISLEMGRUPID2] [int] NULL,
	[ISLEMGRUPID3] [int] NULL,
	[NAKIT] [float] NULL,
	[KKARTI] [float] NULL,
	[ACIK] [float] NULL,
	[DKURU] [float] NULL,
	[DKODU] [nvarchar](5) NULL,
	[SIL] [smallint] NULL,
	[NAKITHESAPID] [int] NULL,
	[KKARTIHESAPID] [int] NULL,
	[GERCEKTARIH] [datetime] NULL,
	[VADESI] [smalldatetime] NULL,
	[CARIID] [int] NULL,
	[CALLSIPARISID] [int] NULL,
	[FTIPI] [tinyint] NULL,
	[DURUMID] [smallint] NULL,
	[FUNVANI] [nvarchar](120) NULL,
	[FVD] [nvarchar](20) NULL,
	[FVDNO] [nvarchar](20) NULL,
	[OKCFISNO] [nvarchar](20) NULL,
	[TICKET1] [float] NULL,
	[TICKET2] [float] NULL,
	[TICKET3] [float] NULL,
	[ALINANPARA] [float] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[PROJEID] [int] NULL,
	[MODULID] [int] NULL,
	[TICKET4] [float] NULL,
	[TICKET5] [float] NULL,
	[DEPOFISUUID] [uniqueidentifier] NULL,
	[TOPLAM] [float] NULL,
	[KDV] [float] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[GTOPLAM] [float] NULL,
	[SUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUKETIMFISISL59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUKETIMFISISL59](
	[DEPOFISISLID] [int] NOT NULL,
	[DEPOFISID] [int] NULL,
	[STOKID] [int] NULL,
	[MIKTAR] [float] NULL,
	[FBIRIM] [nvarchar](50) NULL,
	[FMIKTAR] [float] NULL,
	[BFIYAT] [float] NULL,
	[YETKILI] [nvarchar](15) NULL,
	[ACIKLAMA] [nvarchar](200) NULL,
	[MARKAID] [int] NULL,
	[ISLREFID] [int] NULL,
	[FBFIYAT] [float] NULL,
	[URETSEVIYE] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[SKTARIHI] [datetime] NULL,
	[RGDEPOID] [int] NULL,
	[RCDEPOID] [int] NULL,
	[SARFDEPOID] [int] NULL,
	[TEMPITSID] [int] NULL,
	[TUKETILEN] [int] NULL,
	[URETILEN] [int] NULL,
	[ETSCARIID] [int] NULL,
	[INDORAN] [float] NULL,
	[KDVORAN] [float] NULL,
	[DKURU] [float] NULL,
	[DTURU] [nvarchar](10) NULL,
	[ANASTOKID] [int] NULL,
	[SERILOTID] [int] NULL,
	[ZRURUNID] [int] NULL,
	[ZRHASTALIKID] [int] NULL,
	[URETIMTARIHI] [smalldatetime] NULL,
	[SARJNO] [nvarchar](20) NULL,
	[FIYATTIPID] [tinyint] NULL,
	[OTV] [float] NULL,
	[OIV] [float] NULL,
	[KDV] [float] NULL,
	[BMALIYET] [float] NULL,
	[FBMALIYET] [float] NULL,
	[BKATSAYI] [float] NULL,
	[SATISZAMANI] [datetime] NULL,
	[SILINDI] [smallint] NULL,
	[RENKID] [int] NULL,
	[BEDENID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSGRUP](
	[TUSGRUPID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TUSGRUPADI] [nvarchar](20) NULL,
	[SIRA] [smallint] NULL,
	[AKTIF] [bit] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDTUSGRUPID] [int] NULL,
 CONSTRAINT [PK_TUSGRUP] PRIMARY KEY CLUSTERED 
(
	[TUSGRUPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSGRUP59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSGRUP59](
	[TUSGRUPID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TUSGRUPADI] [nvarchar](20) NULL,
	[SIRA] [smallint] NULL,
	[AKTIF] [bit] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDTUSGRUPID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSTOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSTOK](
	[TUSSTOKID] [int] IDENTITY(1,1) NOT NULL,
	[TUSGRUPID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[STOKID] [int] NULL,
	[SIRA] [int] NULL,
	[DSTOKID] [int] NULL,
	[AKTIF] [bit] NULL,
	[STOKRESIM] [image] NULL,
	[TUSRESIMYOLU] [nvarchar](500) NULL,
 CONSTRAINT [PK_TUSSTOK] PRIMARY KEY CLUSTERED 
(
	[TUSSTOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSTOK59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSTOK59](
	[TUSSTOKID] [int] NOT NULL,
	[TUSGRUPID] [int] NULL,
	[BARKOD] [nvarchar](30) NULL,
	[STOKID] [int] NULL,
	[SIRA] [int] NULL,
	[DSTOKID] [int] NULL,
	[AKTIF] [bit] NULL,
	[STOKRESIM] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSUBE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSUBE](
	[TUSSUBEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDTUSSUBEID] [int] NULL,
 CONSTRAINT [PK_TUSSUBE] PRIMARY KEY CLUSTERED 
(
	[TUSSUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSUBE59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSUBE59](
	[TUSSUBEID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[SIL] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[OLDTUSSUBEID] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSUBEGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSUBEGRUP](
	[TUSSUBEGRUPID] [int] IDENTITY(1,1) NOT NULL,
	[TUSSUBEID] [int] NULL,
	[TUSGRUPID] [int] NULL,
	[SIRA] [int] NULL,
 CONSTRAINT [PK_TUSSUBEGRUP] PRIMARY KEY CLUSTERED 
(
	[TUSSUBEGRUPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TUSSUBEGRUP59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TUSSUBEGRUP59](
	[TUSSUBEGRUPID] [int] NOT NULL,
	[TUSSUBEID] [int] NULL,
	[TUSGRUPID] [int] NULL,
	[SIRA] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ULKEBARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ULKEBARKOD](
	[ULKEBARKODID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ULKEADI] [nvarchar](30) NULL,
	[ULKEBARKODBASLANGIC] [smallint] NULL,
	[ULKEBARKODBITIS] [smallint] NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_ULKEBARKOD] PRIMARY KEY CLUSTERED 
(
	[ULKEBARKODID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ULKELER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ULKELER](
	[ULKELERID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[ULKEADITR] [nvarchar](50) NULL,
	[ULKEADITRUZUN] [nvarchar](150) NULL,
	[ULKEISOKODU] [nvarchar](5) NULL,
	[KISAKODU] [nvarchar](2) NULL,
	[BASKENTTR] [nvarchar](50) NULL,
	[ULKEADIENG] [nvarchar](50) NULL,
	[BASKENTENG] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_ULKELER] PRIMARY KEY CLUSTERED 
(
	[ULKELERID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[URETICI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[URETICI](
	[URETICIID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[URETICIKODU] [nvarchar](20) NULL,
	[URETICIFIRMA] [nvarchar](150) NULL,
	[ADRES] [nvarchar](150) NULL,
	[TEL] [nvarchar](20) NULL,
	[YETKILI] [nvarchar](30) NULL,
	[ULKE] [nvarchar](20) NULL,
	[EMAIL] [nvarchar](50) NULL,
	[WEB] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_URETICI] PRIMARY KEY CLUSTERED 
(
	[URETICIID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[URETIMMAKINE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[URETIMMAKINE](
	[URETIMMAKINEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[MAKINEADI] [nvarchar](50) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
 CONSTRAINT [PK_URETIMMAKINE] PRIMARY KEY CLUSTERED 
(
	[URETIMMAKINEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[URETIMPLAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[URETIMPLAN](
	[URETIMPLANID] [int] NOT NULL,
	[TARIH] [datetime] NULL,
	[KTARIH] [datetime] NULL,
	[USERID] [int] NOT NULL,
	[SUBEID] [int] NOT NULL,
	[YETKILI] [nvarchar](15) NULL,
	[DEPOID] [int] NULL,
	[GRUP] [nvarchar](20) NULL,
	[ACIKLAMA] [nvarchar](50) NULL,
 CONSTRAINT [PK_URETIMPLAN] PRIMARY KEY CLUSTERED 
(
	[URETIMPLANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_URETIMPLAN] UNIQUE NONCLUSTERED 
(
	[URETIMPLANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[URETIMRECETE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[URETIMRECETE](
	[URETIMRECETEID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[TARIH] [nchar](10) NULL,
	[STOKID] [int] NULL,
	[RECETEADI] [nvarchar](50) NULL,
	[RECETEMALIYETI] [float] NULL,
	[ACIKLAMA] [nvarchar](100) NULL,
	[ADD_DATE] [datetime] NULL,
	[ADD_USERID] [int] NULL,
	[DEL_DATE] [datetime] NULL,
	[DEL_USERID] [int] NULL,
	[EDIT_DATE] [datetime] NULL,
	[EDIT_USERID] [int] NULL,
	[SIL] [smallint] NULL,
	[CARPAN] [float] NULL,
 CONSTRAINT [PK_URETIMRECETE] PRIMARY KEY CLUSTERED 
(
	[URETIMRECETEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[URUNEKOZELLIK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[URUNEKOZELLIK](
	[URUNEKOZELLIKID] [int] IDENTITY(1,1) NOT NULL,
	[STOKID] [int] NOT NULL,
	[EKOZELLIKID] [int] NULL,
	[ACIKLAMASI] [int] NULL,
	[FIYAT] [float] NULL,
 CONSTRAINT [PK_URUNEKOZELLIK] PRIMARY KEY CLUSTERED 
(
	[URUNEKOZELLIKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[USER_ARS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USER_ARS](
	[USERID] [int] NOT NULL,
	[KODU] [nvarchar](15) NULL,
	[ADI] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](15) NULL,
	[DEPT] [nvarchar](15) NULL,
	[SIFRESI] [nvarchar](15) NULL,
	[DIL] [nvarchar](15) NULL,
	[GRUBU] [nvarchar](15) NULL,
	[ONBURO] [int] NULL,
	[STOK] [int] NULL,
	[SANTRAL] [int] NULL,
	[POS] [int] NULL,
	[WINTOM] [int] NULL,
	[MUHASEBE] [int] NULL,
	[YETKISI] [int] NULL,
	[PERSONEL] [int] NULL,
	[SKODU] [nvarchar](100) NULL,
	[YGRUBU] [bit] NULL,
	[RAPORLAR] [int] NULL,
	[ETSGIRISIZNI] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[ETS] [int] NULL,
	[SATINALMA] [int] NULL,
	[TICSET] [int] NULL,
	[MEDISOFT] [int] NULL,
	[YETKISIOTEL] [int] NULL,
	[YETKISIPOS] [int] NULL,
	[YETKISIETS] [int] NULL,
	[YETKISIPERSONEL] [int] NULL,
	[YETKISIMEDISOFT] [int] NULL,
	[HAZIRLAMA] [int] NULL,
	[KONTROLETME] [int] NULL,
	[ONAYLAMA] [int] NULL,
	[SATGOREV] [nvarchar](20) NULL,
	[SIFRESIFRELI] [bit] NULL,
	[EMAIL] [nvarchar](50) NULL,
	[MUHONAY] [int] NULL,
	[USERGRUPID] [int] NULL,
	[SATINALMADURUM] [nvarchar](250) NULL,
	[MASMERID] [int] NULL,
	[SABAGIMSIZGERIGONDER] [int] NULL,
	[TAKVIMKAYNAK] [nvarchar](250) NULL,
	[MASRAFMERKEZLERI] [nvarchar](500) NULL,
	[GELIRLERIGOREMEZ] [bit] NULL,
	[FATURA] [int] NULL,
	[ETSISLEMLER] [int] NULL,
	[ETSFATURA] [int] NULL,
	[ETSDEMIRBAS] [int] NULL,
	[ETSDEVREMULK] [int] NULL,
	[ETSENTEGRASYON] [int] NULL,
	[OTELMENU] [nvarchar](250) NULL,
	[SATISSIL] [bit] NULL,
	[SATISDUZELT] [bit] NULL,
	[INDIRIMVER] [bit] NULL,
	[TANIMEKRANI] [bit] NULL,
	[SIL] [smallint] NULL,
	[FIYATDEGISTIR] [bit] NULL,
	[SATIRSILME] [bit] NULL,
	[VARSAYILANISLEMGRUBU1] [int] NULL,
	[VARSAYILANISLEMGRUBU2] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[USER_HC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USER_HC](
	[USERID] [int] NOT NULL,
	[KODU] [nvarchar](15) NULL,
	[ADI] [nvarchar](30) NULL,
	[GOREVI] [nvarchar](15) NULL,
	[DEPT] [nvarchar](15) NULL,
	[SIFRESI] [nvarchar](15) NULL,
	[DIL] [nvarchar](15) NULL,
	[GRUBU] [nvarchar](15) NULL,
	[ONBURO] [int] NULL,
	[STOK] [int] NULL,
	[SANTRAL] [int] NULL,
	[POS] [int] NULL,
	[WINTOM] [int] NULL,
	[MUHASEBE] [int] NULL,
	[YETKISI] [int] NULL,
	[PERSONEL] [int] NULL,
	[SKODU] [nvarchar](100) NULL,
	[YGRUBU] [bit] NULL,
	[RAPORLAR] [int] NULL,
	[ETSGIRISIZNI] [int] NULL,
	[SUBEID] [int] NULL,
	[DEPOID] [int] NULL,
	[ETS] [int] NULL,
	[SATINALMA] [int] NULL,
	[TICSET] [int] NULL,
	[MEDISOFT] [int] NULL,
	[YETKISIOTEL] [int] NULL,
	[YETKISIPOS] [int] NULL,
	[YETKISIETS] [int] NULL,
	[YETKISIPERSONEL] [int] NULL,
	[YETKISIMEDISOFT] [int] NULL,
	[HAZIRLAMA] [int] NULL,
	[KONTROLETME] [int] NULL,
	[ONAYLAMA] [int] NULL,
	[SATGOREV] [nvarchar](20) NULL,
	[SIFRESIFRELI] [bit] NULL,
	[EMAIL] [nvarchar](50) NULL,
	[MUHONAY] [int] NULL,
	[USERGRUPID] [int] NULL,
	[SATINALMADURUM] [nvarchar](250) NULL,
	[MASMERID] [int] NULL,
	[SABAGIMSIZGERIGONDER] [int] NULL,
	[TAKVIMKAYNAK] [nvarchar](250) NULL,
	[MASRAFMERKEZLERI] [nvarchar](500) NULL,
	[GELIRLERIGOREMEZ] [bit] NULL,
	[FATURA] [int] NULL,
	[ETSISLEMLER] [int] NULL,
	[ETSFATURA] [int] NULL,
	[ETSDEMIRBAS] [int] NULL,
	[ETSDEVREMULK] [int] NULL,
	[ETSENTEGRASYON] [int] NULL,
	[OTELMENU] [nvarchar](250) NULL,
	[SATISSIL] [bit] NULL,
	[SATISDUZELT] [bit] NULL,
	[INDIRIMVER] [bit] NULL,
	[TANIMEKRANI] [bit] NULL,
	[DEPARTID] [int] NULL,
	[COKLUCALISMA] [tinyint] NULL,
	[SATINALMASTATU] [nvarchar](100) NULL,
	[PDEPARTMANS] [nvarchar](100) NULL,
	[SIL] [smallint] NULL,
	[FIYATDEGISTIR] [bit] NULL,
	[SATIRSILME] [bit] NULL,
	[VARSAYILANISLEMGRUBU1] [int] NULL,
	[VARSAYILANISLEMGRUBU2] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[USERGRID]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USERGRID](
	[USERGRIDID] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[FORMADI] [nvarchar](100) NULL,
	[TABLOADI] [nvarchar](20) NULL,
	[TASARIM] [text] NULL,
	[TASARIM2] [varbinary](max) NULL,
	[ALANADI] [nvarchar](20) NULL,
	[ALANETIKETI] [nvarchar](20) NULL,
	[AKTIF] [bit] NULL,
 CONSTRAINT [PK_UserGrid] PRIMARY KEY CLUSTERED 
(
	[USERGRIDID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[USERGRID59]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USERGRID59](
	[USERGRIDID] [int] NOT NULL,
	[FIRMAID] [int] NULL,
	[SUBEID] [int] NULL,
	[USERID] [int] NULL,
	[FORMADI] [nvarchar](100) NULL,
	[TABLOADI] [nvarchar](20) NULL,
	[TASARIM] [text] NULL,
	[TASARIM2] [varbinary](max) NULL,
	[ALANADI] [nvarchar](20) NULL,
	[ALANETIKETI] [nvarchar](20) NULL,
	[AKTIF] [bit] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[YEMEKSEPETI_Options]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YEMEKSEPETI_Options](
	[Id] [nvarchar](50) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[ProductId] [nvarchar](50) NULL,
	[Name] [nvarchar](50) NULL,
	[Price] [float] NULL,
	[Type] [nvarchar](50) NULL,
	[StokId] [int] NULL,
 CONSTRAINT [PK_YEMEKSEPETI_Options] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_YEMEKSEPETI_Options] UNIQUE NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[YEMEKSEPETI_OrderProductOptions]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YEMEKSEPETI_OrderProductOptions](
	[Counter] [int] IDENTITY(1,1) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[Id] [nvarchar](50) NULL,
	[Name] [nvarchar](50) NULL,
	[ProductOrderId] [int] NULL,
	[OrderId] [int] NULL,
	[ProductId] [nvarchar](50) NULL,
 CONSTRAINT [PK_YEMEKSEPETI_OrderProductOptions] PRIMARY KEY CLUSTERED 
(
	[Counter] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_YEMEKSEPETI_OrderProductOptions] UNIQUE NONCLUSTERED 
(
	[Counter] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[YEMEKSEPETI_OrderProducts]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YEMEKSEPETI_OrderProducts](
	[Counter] [int] IDENTITY(1,1) NOT NULL,
	[id] [nvarchar](50) NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[OrderId] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Price] [float] NULL,
	[Quantity] [int] NULL,
	[Options] [nvarchar](50) NULL,
	[OptionIds] [nvarchar](150) NULL,
	[OrderIndex] [int] NULL,
	[ParentIndex] [int] NULL,
	[PromoParentIndex] [int] NULL,
	[ProductOptionId] [nvarchar](50) NULL,
 CONSTRAINT [PK_YEMEKSEPETI_OrderProducts] PRIMARY KEY CLUSTERED 
(
	[Counter] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_YEMEKSEPETI_OrderProducts] UNIQUE NONCLUSTERED 
(
	[Counter] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[YEMEKSEPETI_Orders]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YEMEKSEPETI_Orders](
	[Id] [int] NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[MessageId] [int] NULL,
	[RestaurantName] [nvarchar](50) NULL,
	[RestaurantCatalog] [nvarchar](50) NULL,
	[RestaurantCategory] [nvarchar](50) NULL,
	[CustomerName] [nvarchar](50) NULL,
	[CustomerId] [int] NULL,
	[CustomerType] [int] NULL,
	[PaymentNote] [nvarchar](500) NULL,
	[OrderTotal] [float] NULL,
	[CustomerPhone] [nvarchar](50) NULL,
	[PromoCode] [nvarchar](50) NULL,
	[CustomerPhone2] [nvarchar](50) NULL,
	[City] [nvarchar](50) NULL,
	[Region] [nvarchar](50) NULL,
	[Organization] [nvarchar](50) NULL,
	[Address] [nvarchar](500) NULL,
	[AddressDescription] [nvarchar](500) NULL,
	[AddressId] [nvarchar](50) NULL,
	[PaymentMethodId] [int] NULL,
	[DeliveryTime] [datetime] NULL,
	[ChangeInTotal] [float] NULL,
	[Currency] [nvarchar](50) NULL,
	[OrderNote] [nvarchar](500) NULL,
	[OrderStatu] [nvarchar](10) NULL,
	[OrderImported] [bit] NULL,
 CONSTRAINT [PK_YEMEKSEPETI_Orders] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_YEMEKSEPETI_Orders] UNIQUE NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[YEMEKSEPETI_Products]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[YEMEKSEPETI_Products](
	[Id] [nvarchar](50) NOT NULL,
	[FIRMAID] [int] NOT NULL,
	[SUBEID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Price] [float] NULL,
	[Title] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[StokId] [int] NULL,
 CONSTRAINT [PK_YEMEKSEPETI_Products] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY],
 CONSTRAINT [IX_YEMEKSEPETI_Products] UNIQUE NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[EFATURA_ODEMESEKLI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[EFATURA_ODEMESEKLI]
AS
SELECT 'ZZZ' AS ODEMEKODU, 'Diğer' as ACIKLAMA
UNION ALL
SELECT '20' AS ODEMEKODU, 'Çek' as ACIKLAMA
UNION ALL
SELECT '42' AS ODEMEKODU, 'Havale' as ACIKLAMA
UNION ALL 
SELECT '6' AS ODEMEKODU, 'Kredi' as ACIKLAMA
UNION ALL
SELECT '48' AS ODEMEKODU, 'Kredi Kartı' as ACIKLAMA
UNION ALL
SELECT '20' AS ODEMEKODU, 'Çek' as ACIKLAMA
UNION ALL
SELECT '10' AS ODEMEKODU, 'Nakit' as ACIKLAMA
UNION ALL
SELECT '49' AS ODEMEKODU, 'Otomatik Ödeme' as ACIKLAMA
UNION ALL
SELECT '60' AS ODEMEKODU, 'Senet' as ACIKLAMA
UNION ALL
SELECT '1' AS ODEMEKODU, 'Sözleşme Kapsamında' as ACIKLAMA
GO
/****** Object:  View [dbo].[FU_EDEVLETDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE VIEW [dbo].[FU_EDEVLETDURUM]
AS
SELECT 0 AS ID, 'Normal' AS EDURUM
UNION ALL
SELECT 1 AS ID, 'EFatura' AS EDURUM
UNION ALL
SELECT 2 AS ID, 'EArşiv' AS EDURUM
GO
/****** Object:  View [dbo].[FU_EFATTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[FU_EFATTUR]
AS
SELECT 0 AS ID, 'Temel Fatura' AS EDURUM
UNION ALL
SELECT 1 AS ID, 'Ticari Fatura' AS EDURUM
UNION ALL
SELECT 2 AS ID, 'Yolcu Beraber Fatura' AS EDURUM
UNION ALL
SELECT 3 AS ID, 'eArşiv Fatura' AS EDURUM
UNION ALL
SELECT 6 AS ID, 'KAMU' AS EDURUM
GO
/****** Object:  View [dbo].[FU_EFATURADURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_EFATURADURUM]
AS
SELECT 0 AS ID, 'Normal' AS EDURUM
UNION ALL
SELECT 1 AS ID, 'Beklemede' AS EDURUM
UNION ALL
SELECT 2 AS ID, 'XML Hazırlandı' AS EDURUM
UNION ALL
SELECT 3 AS ID, 'Yüklendi' AS EDURUM
UNION ALL
SELECT 4 AS ID, 'Gönderildi' AS EDURUM
UNION ALL
SELECT 5 AS ID, 'Redetti' AS EDURUM
UNION ALL
SELECT 6 AS ID, 'Kabul Etti' AS EDURUM
UNION ALL
SELECT 7 AS ID, 'İptal Edildi' AS EDURUM
GO
/****** Object:  View [dbo].[FU_EFITIMDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_EFITIMDURUM]
AS
SELECT '01-PLANLAMA' AS DURUM
UNION ALL
SELECT '02-GERCEKLESEN' AS DURUM
GO
/****** Object:  View [dbo].[FU_EGITIMDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_EGITIMDURUM]
AS
SELECT '01-PLANLAMA' AS DURUM
UNION ALL
SELECT '02-GERCEKLESEN' AS DURUM
GO
/****** Object:  View [dbo].[FU_EMLAKNOTTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_EMLAKNOTTUR]
AS
SELECT 1 AS NOTTURID, 'Satış Notları' as ACIKLAMA 
UNION ALL
SELECT 2 AS NOTTURID, 'Takip Edilecek Notlar' as ACIKLAMA 
UNION ALL
SELECT 3 AS NOTTURID, 'Evrak Kontrol Listesi' as ACIKLAMA
UNION ALL
SELECT 4 AS NOTTURID, 'Satış Sonrası Evrak Takip' as ACIKLAMA 
UNION ALL
SELECT 5 AS NOTTURID, 'Tapu Devri' as ACIKLAMA
GO
/****** Object:  View [dbo].[FU_FIRMAISLEMTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_FIRMAISLEMTUR]
AS
SELECT 1 AS FISTURID, 'B' AS BA, 'YILLIK KULLANIM BEDELİ' AS FISADI
UNION ALL
SELECT 2 AS FISTURID, 'B' AS BA, 'BORÇ DEKONTU' AS FISADI
UNION ALL
SELECT 3 AS FISTURID, 'A' AS BA, 'NAKİT TAHSİLAT' AS FISADI
UNION ALL
SELECT 4 AS FISTURID, 'A' AS BA, 'KREDI KARTI TAHSİLAT' AS FISADI
UNION ALL
SELECT 5 AS FISTURID, 'A' AS BA, 'HAVALE / EFT İLE TAHSİLAT' AS FISADI
UNION ALL
SELECT 6 AS FISTURID, 'A' AS BA, 'ALACAK DEKONTU' AS FISADI

GO
/****** Object:  View [dbo].[FU_MUHGRUPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_MUHGRUPTIP]
AS
SELECT 1 AS TIPID,		'HESAPGRUBU1' AS ACIKLAMA
UNION ALL
SELECT 2,		'HESAPGRUBU2'
UNION ALL
SELECT 3,		'ISLEMGRUBU1'
UNION ALL
SELECT 4,		'ISLEMGRUBU2'
UNION ALL
SELECT 5,		'ISLEMGRUBU3'
UNION ALL
SELECT 6,		'MASRAFMERKEZI'
UNION ALL
SELECT 7,		'PROJEKODU'
UNION ALL
SELECT 8,		'OZELKOD'
UNION ALL
SELECT 9,		'DEPARTMAN'
GO
/****** Object:  View [dbo].[FU_STOKTURU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_STOKTURU]
AS
SELECT 1 AS TURID, 'HAMMADDE' as STOKTURU
UNION ALL
SELECT 2 AS TURID, 'YARI MAMUL' as STOKTURU
UNION ALL
SELECT 3 AS TURID, 'MAMUL' as STOKTURU
UNION ALL
SELECT 4 AS TURID, 'TİCARİ MAL' as STOKTURU
UNION ALL
SELECT 5 AS TURID, 'DEMİRBAŞ' as STOKTURU

GO
/****** Object:  View [dbo].[FU_UCHESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FU_UCHESAP]
AS
SELECT 0 AS TURID,'Ana Hesap' AS TURADI
UNION ALL
SELECT 1 AS TURID,'Uç Hesap' AS TURADI
GO
/****** Object:  View [dbo].[IKEGITIMDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[IKEGITIMDURUM]
AS
SELECT 0 AS DURUMID, 'BEKLEMEDE' AS DURUMU
UNION ALL
SELECT 1, 'VERILDI' AS DURUMU
UNION ALL
SELECT 2, 'IPTAL' AS DURUMU
GO
/****** Object:  View [dbo].[QMUH_FISTURIRS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE VIEW [dbo].[QMUH_FISTURIRS]  AS 
   SELECT -1 AS FISTURID,'Gelir Bütçesi' AS FISTURADI,6 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,0 BELGETURUID  UNION ALL    
   SELECT -2 AS FISTURID,'Gider Bütçesi' AS FISTURADI,7 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,0    UNION ALL    SELECT -3 AS FISTURID,'Geçen Yıl Gelir' AS FISTURADI,6 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,0   UNION ALL    SELECT -4 AS FISTURID,'Geçen Yıl Gider' AS FISTURADI,7 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,0    UNION ALL    SELECT 1 AS FISTURID,'Kasaya Tahsilat' AS FISTURADI,100 AS HESAPTIPID, 'BORC' AS ALANTIPI,'' AS CEKSONDURUMID,9    UNION ALL    SELECT 2 AS FISTURID,'Kasadan Ödeme' AS FISTURADI,100 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,10   UNION ALL    SELECT 3 AS FISTURID,'Bankaya Tahsilat' AS FISTURADI,102 AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,4    UNION ALL    SELECT 4 AS FISTURID,'Bankadan Ödeme' AS FISTURADI,102 AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,4    UNION ALL    
   SELECT 5 AS FISTURID,'Borç Dekontu' AS FISTURADI,NULL AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,17    UNION ALL    SELECT 6 AS FISTURID,'Alacak Dekontu' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,17  
   UNION ALL   SELECT 7 AS FISTURID,'Taksitli Tahsilatlar' AS FISTURADI,NULL AS HESAPTIPID, 'ALACAK' AS ALANTIPI,NULL,9    UNION ALL    SELECT 8 AS FISTURID,'Taksitli Ödemeler' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,10  UNION ALL   SELECT 9 AS FISTURID,'Virman' AS FISTURADI,NULL AS HESAPTIPID, 'BORC' AS ALANTIPI,NULL,17  UNION ALL  SELECT 21 AS FISTURID,'Çek-Senet Giriş (Portfoye Alındı)',120,'ALACAK','-1',2 UNION ALL  SELECT 22 AS FISTURID,'Çek-Senet Giriş (Portfoye Geri Alındı)',320,'ALACAK','23,24,25,26,27,31,32',2 UNION ALL  SELECT 23 AS FISTURID,'Çek-Senet Çıkış (Tahsile Verildi)',101,'BORC',  '21,22',2    UNION ALL  SELECT 24 AS FISTURID,'Çek-Senet Çıkış (Teminata Verildi)',102,'BORC',  '21,22',2    UNION ALL  SELECT 25 AS 
FISTURID,'Çek-Senet Çıkış (Protesto Edildi)',NULL,'BORC',  '21,22',2    UNION ALL  SELECT 26 AS FISTURID,'Çek-Senet Çıkış (Adli Takipte)',NULL,'BORC',  '21,22',2    UNION ALL  SELECT 31 AS FISTURID,'Çek-Senet Çıkış (Ciro Edildi)',320,'BORC',  '21,22',2   UNION ALL  SELECT 32 AS FISTURID,'Çek-Senet Çıkış (İade Edildi)',320,'BORC',  '21,22',2     UNION ALL  SELECT 33 AS FISTURID,'Çek-Senet Ödeme (Bankadan Ödendi)',102,'ALACAK','31',2 UNION ALL  SELECT 34 AS FISTURID,'Çek-Senet Ödeme (Kasadan Ödendi)',100,'ALACAK','31',2 UNION ALL  SELECT 35 AS FISTURID,'Çek-Senet Tahsil (Bankaya Tahsil)',102,'BORC',  '21,22,23',2   UNION ALL  SELECT 36 AS FISTURID,'Çek-Senet Tahsil (Kasaya Tahsil)',100,'BORC',  '21,22,23',2   UNION ALL   SELECT 41 AS FISTURID,'Mahsup',NULL                          ,'',   NULL,NULL   UNION ALL   SELECT 42 AS FISTURID,'Tahsil',null,'',   NULL,9   UNION ALL   SELECT 43 AS FISTURID,'Tediye',null,'', NULL,10   UNION ALL   SELECT 44 AS FISTURID,'Yansıtma',NULL,                          '',   NULL,NULL   UNION ALL    SELECT 45 AS FISTURID,'Kur Farkı',NULL,                          '',   NULL,15   UNION ALL    SELECT 48 AS FISTURID,'Kapanış',NULL,                          '',   NULL,NULL   UNION ALL    SELECT 49 AS FISTURID,'Açılış',NULL,                          '',   NULL,NULL   UNION ALL   
SELECT 51 AS FISTURID,'Stok Alış İrsaliyesi',320,'ALACAK',NULL,1  UNION ALL 
SELECT 52 AS FISTURID,'Stok Satış İrsaliyesi',120,'BORC',NULL,1  UNION ALL   
SELECT 53 AS FISTURID,'Stok Alış İade İrsaliyesi',120,'BORC',NULL,1  UNION ALL  
SELECT 54 AS FISTURID,'Stok Satış İade İrsaliyesi',320,'ALACAK',NULL,1  UNION ALL  
SELECT 61 AS FISTURID,'Hizmet Alış İrsaliyesi',320,'ALACAK',NULL,1  UNION ALL  SELECT 62 AS FISTURID,'Hizmet Satış İrsaliyesi',120,'BORC',NULL,1  UNION ALL 
SELECT 63 AS FISTURID,'Hizmet Alış İade İrsaliyesi',120,'BORC',NULL,1  UNION ALL  SELECT 64 AS FISTURID,'Hizmet Satış İade İrsaliyesi',320,'ALACAK',NULL,1  UNION ALL  SELECT 50 AS FISTURID,'Fiyat Teklifi',120,'BORC',NULL,1  UNION ALL  SELECT 65 AS FISTURID,'Gider 
Pusulası',320,'ALACAK',NULL,6  UNION ALL  SELECT 66 AS FISTURID,'Serbest Meslek Makbuzu',120,'BORC',NULL,8  UNION ALL  SELECT 67 AS FISTURID,'Müstahsil Makbuzu',320,'ALACAK',NULL,7  

GO
/****** Object:  View [dbo].[QMUH_GRUPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE VIEW [dbo].[QMUH_GRUPTIP] AS 
  SELECT  1 AS TIPID,'Hesap Grup 1 ' AS TIPADI UNION ALL   SELECT  2 AS TIPID,'Hesap Grup 2 ' AS TIPADI UNION ALL   SELECT  3 AS TIPID,'İşlem Grup 1 ' AS TIPADI UNION ALL   SELECT  4 AS TIPID,'İşlem Grup 2 ' AS TIPADI UNION ALL   SELECT  5 AS TIPID,'İşlem Grup 3 ' AS TIPADI UNION ALL   SELECT  6 AS TIPID,'Masraf Merkezi' AS TIPADI UNION ALL   SELECT  7 AS TIPID,'Proje Kodu ' AS TIPADI   UNION ALL    SELECT  8 AS TIPID,'Özel Kod I ' AS TIPADI
GO
/****** Object:  View [dbo].[VW_AYGUNU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[VW_AYGUNU]
AS
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) AS AYINILKGUNU,
DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) AS AYINSONGUNU
GO
/****** Object:  View [dbo].[VW_FISDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[VW_FISDURUM]
AS
SELECT 'ISLEMDE' AS FISDURUM, 1 AS FISDURUMID UNION ALL SELECT 'ONAYLI' AS FISDURUM, 2 AS FISDURUMID  UNION ALL SELECT 'PLANLAMA' AS FISDURUM, -1 UNION ALL SELECT 'SILINDI' AS FISDURUM, -2 AS FISDURUMID
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[ADISYON]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FISCOUNTER_STOKID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FISCOUNTER_STOKID] ON [dbo].[ADSSATIR]
(
	[FISCOUNTER] ASC,
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[BEDENLER]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_CONFIG_1]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_CONFIG_1] ON [dbo].[CONFIG]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[SECTIONSTR] ASC,
	[KEYNAME] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[CONFIG]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[DEPO]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[DEPOFIS]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[DOVIZ]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[DOVIZISL]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [IDX_EFATURA_FIRMA_KAYITTARIHI]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_FIRMA_KAYITTARIHI] ON [dbo].[EFATURA_FIRMA]
(
	[KAYITTARIHI] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_FIRMA_VDNO]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_FIRMA_VDNO] ON [dbo].[EFATURA_FIRMA]
(
	[VDNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_LOG_EFATNO]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_LOG_EFATNO] ON [dbo].[EFATURA_LOG]
(
	[EFATNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_LOG_ISLEM]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_LOG_ISLEM] ON [dbo].[EFATURA_LOG]
(
	[ISLEM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_LOG_UUID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_LOG_UUID] ON [dbo].[EFATURA_LOG]
(
	[UUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_LOG_UUID_ISLEM]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_LOG_UUID_ISLEM] ON [dbo].[EFATURA_LOG]
(
	[UUID] ASC,
	[ISLEM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IDX_EFATURA_POSTAKUTUSU_VKN]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IDX_EFATURA_POSTAKUTUSU_VKN] ON [dbo].[EFATURA_POSTAKUTUSU]
(
	[VKN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_EKR_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_EKR_FIRMAID_SUBEID] ON [dbo].[EKRANLAR]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_EML_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_EML_FIRMAID_SUBEID] ON [dbo].[EMLAKKIRALAMA]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[EMLAKSATIS]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [NCI_FATID_STOKID_BARKOD]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FATID_STOKID_BARKOD] ON [dbo].[FATISL]
(
	[FATID] ASC,
	[STOKID] ASC,
	[BARKOD] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_TARIH_FISHESAPID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_TARIH_FISHESAPID] ON [dbo].[FATURA]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[TARIH] ASC,
	[FISHESAPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [UX_IKPERSONEL]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [UX_IKPERSONEL] ON [dbo].[IKPERSONEL]
(
	[PSICILID] ASC,
	[FIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_TARIH_MODULID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_TARIH_MODULID] ON [dbo].[MUH_FIS]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[TARIH] ASC,
	[MODULID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_TIPID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_TIPID] ON [dbo].[MUH_GRUP]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[TIPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_MUH_HESAP_2]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_MUH_HESAP_2] ON [dbo].[MUH_HESAP]
(
	[KODU] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[MUH_HESAP]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FISID_HESAPID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FISID_HESAPID] ON [dbo].[MUH_HESAPISL]
(
	[FISID] ASC,
	[HESAPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_NOVA_RAPORSABLON_ARA]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_NOVA_RAPORSABLON_ARA] ON [dbo].[NOVA_RAPORSABLON]
(
	[FIRMAID] ASC,
	[VERIKAYNAK] ASC,
	[TURU] ASC,
	[SIL] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NCI_US_FIRMAID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_US_FIRMAID] ON [dbo].[NOVAUSER]
(
	[FIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_ND_NOVAUSERID,EKRANID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_ND_NOVAUSERID,EKRANID] ON [dbo].[NOVAUSERD]
(
	[NOVAUSERID] ASC,
	[EKRANID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [NCI_RAP_FIRMAID_BOLUM]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_RAP_FIRMAID_BOLUM] ON [dbo].[RAPORLAR]
(
	[FIRMAID] ASC,
	[BOLUM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[RENKLER]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_DEPOID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_DEPOID] ON [dbo].[SAYIMFIS]
(
	[FIRMAID] ASC,
	[DEPOID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAI_SUBEID_STOKID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAI_SUBEID_STOKID] ON [dbo].[SERILOT]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID] ON [dbo].[SGRUP]
(
	[FIRMAID] ASC,
	[SUBEID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_BARKOD]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_BARKOD] ON [dbo].[STOK]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[BARKOD] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [IX_STOKRESIM_ARA]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_STOKRESIM_ARA] ON [dbo].[STOKRESIM]
(
	[FIRMAID] ASC,
	[STOKID] ASC,
	[SIL] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_DEPOID_STOKID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_DEPOID_STOKID] ON [dbo].[SUBEFIYAT]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[DEPOID] ASC,
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_TARIH]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_TARIH] ON [dbo].[TUKETIMFIS]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[TARIH] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_TI_DEPOFISID_STOKID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_TI_DEPOFISID_STOKID] ON [dbo].[TUKETIMFISISL]
(
	[DEPOFISID] ASC,
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [NCI_FIRMAID_SUBEID_STOKID]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [NCI_FIRMAID_SUBEID_STOKID] ON [dbo].[URETIMRECETE]
(
	[FIRMAID] ASC,
	[SUBEID] ASC,
	[STOKID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [IX_YASLANDIRMA]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_YASLANDIRMA] ON [dbo].[YASLANDIRMA]
(
	[TARIH] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [IX_YASLANDIRMA_1]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_YASLANDIRMA_1] ON [dbo].[YASLANDIRMA]
(
	[FIRMAID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
/****** Object:  Index [IX_YASLANDIRMA_2]    Script Date: 17.07.2026 15:19:18 ******/
CREATE NONCLUSTERED INDEX [IX_YASLANDIRMA_2] ON [dbo].[YASLANDIRMA]
(
	[HESAPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
GO
ALTER TABLE [dbo].[EFATURA_LOG] ADD  DEFAULT (getdate()) FOR [TARIH]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_ETS_FATISL_SATIRIND]  DEFAULT ((0)) FOR [SATIRIND]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_ETS_FATISL_SATIRIND2]  DEFAULT ((0)) FOR [SATIRIND2]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_SATIRIND3]  DEFAULT ((0)) FOR [SATIRIND3]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_SATIRIND4]  DEFAULT ((0)) FOR [SATIRIND4]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_FADET]  DEFAULT ((0)) FOR [FADET]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_FBFIYAT]  DEFAULT ((0)) FOR [FBFIYAT]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_ARATOPLAM]  DEFAULT ((0)) FOR [ARATOPLAM]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_DFBFIYAT]  DEFAULT ((0)) FOR [DFBFIYAT]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_DBFIYAT]  DEFAULT ((0)) FOR [DBFIYAT]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_DTOPLAM]  DEFAULT ((0)) FOR [DTOPLAM]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_DOVIZKURU]  DEFAULT ((0)) FOR [DOVIZKURU]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_TOPLAM]  DEFAULT ((0)) FOR [TOPLAM]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_KDVLIFIYAT]  DEFAULT ((0)) FOR [KDVLIFIYAT]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_OTV]  DEFAULT ((0)) FOR [OTV]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_OIV]  DEFAULT ((0)) FOR [OIV]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_FBMALIYET]  DEFAULT ((0)) FOR [FBMALIYET]
GO
ALTER TABLE [dbo].[FATISL] ADD  CONSTRAINT [DF_FATISL_BKATSAYI]  DEFAULT ((0)) FOR [BKATSAYI]
GO
ALTER TABLE [dbo].[FATURA] ADD  CONSTRAINT [DF_ETS_FATURA_SIND]  DEFAULT ((0)) FOR [SIND]
GO
ALTER TABLE [dbo].[FATURADETAY] ADD  DEFAULT (newid()) FOR [UUID]
GO
ALTER TABLE [dbo].[FIRMALAR] ADD  CONSTRAINT [DF_FIRMALAR_FIRMAUUID]  DEFAULT (newid()) FOR [FIRMAUUID]
GO
ALTER TABLE [dbo].[IndexMaintenanceLog] ADD  DEFAULT (getdate()) FOR [LogDate]
GO
ALTER TABLE [dbo].[NOVA_DBBAKIM] ADD  CONSTRAINT [DF_NOVA_DBBAKIM_TARIH]  DEFAULT (getdate()) FOR [TARIH]
GO
ALTER TABLE [dbo].[NOVA_RAPORSABLON] ADD  CONSTRAINT [DF_NOVA_RAPORSABLON_VARSAYILAN]  DEFAULT ((0)) FOR [VARSAYILAN]
GO
ALTER TABLE [dbo].[NOVA_RAPORSABLON] ADD  CONSTRAINT [DF_NOVA_RAPORSABLON_SIL]  DEFAULT ((0)) FOR [SIL]
GO
ALTER TABLE [dbo].[NOVA_RAPORSABLON] ADD  CONSTRAINT [DF_NOVA_RAPORSABLON_ADDDATE]  DEFAULT (getdate()) FOR [ADD_DATE]
GO
ALTER TABLE [dbo].[NOVA_UYGULAMA_SERVISI] ADD  CONSTRAINT [DF_NOVA_UYGULAMA_SERVISI_US_ZAMANMS]  DEFAULT ((0)) FOR [US_ZAMANSN]
GO
ALTER TABLE [dbo].[NOVA_UYGULAMA_SERVISI] ADD  CONSTRAINT [DF_NOVA_UYGULAMA_SERVISI_US_AKTIF]  DEFAULT ((0)) FOR [US_AKTIF]
GO
ALTER TABLE [dbo].[NOVA_UYGULAMA_SERVISI_MAIL_SENDER] ADD  CONSTRAINT [DF_NOVA_UYGULAMA_SERVISI_MAIL_SENDER_MS_AKTIF]  DEFAULT ((0)) FOR [MS_AKTIF]
GO
ALTER TABLE [dbo].[STOKRESIM] ADD  CONSTRAINT [DF_STOKRESIM_SIL]  DEFAULT ((0)) FOR [SIL]
GO
ALTER TABLE [dbo].[STOKRESIM] ADD  CONSTRAINT [DF_STOKRESIM_ADD]  DEFAULT (getdate()) FOR [ADD_DATE]
GO
ALTER TABLE [dbo].[YEMEKSEPETI_Orders] ADD  CONSTRAINT [DF_YEMEKSEPETI_Orders_OrderImported]  DEFAULT ((0)) FOR [OrderImported]
GO
ALTER TABLE [dbo].[ADSODEME]  WITH CHECK ADD  CONSTRAINT [FK_ADSODEME_ADISYON_FISCOUNTER] FOREIGN KEY([FISCOUNTER])
REFERENCES [dbo].[ADISYON] ([FISCOUNTER])
GO
ALTER TABLE [dbo].[ADSODEME] CHECK CONSTRAINT [FK_ADSODEME_ADISYON_FISCOUNTER]
GO
ALTER TABLE [dbo].[ADSSATIR]  WITH CHECK ADD  CONSTRAINT [FKe_ADSSATIR_FISCOUNTER_ADISYON_FISCOUNTER] FOREIGN KEY([FISCOUNTER])
REFERENCES [dbo].[ADISYON] ([FISCOUNTER])
GO
ALTER TABLE [dbo].[ADSSATIR] CHECK CONSTRAINT [FKe_ADSSATIR_FISCOUNTER_ADISYON_FISCOUNTER]
GO
ALTER TABLE [dbo].[BARKOD]  WITH CHECK ADD  CONSTRAINT [FK_BARKOD_STOK] FOREIGN KEY([STOKID])
REFERENCES [dbo].[STOK] ([STOKID])
GO
ALTER TABLE [dbo].[BARKOD] CHECK CONSTRAINT [FK_BARKOD_STOK]
GO
ALTER TABLE [dbo].[CEKLER]  WITH CHECK ADD  CONSTRAINT [FKe_CEKLER_SUBEID_SUBELER_SUBEID] FOREIGN KEY([SUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[CEKLER] CHECK CONSTRAINT [FKe_CEKLER_SUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[DEPART]  WITH CHECK ADD  CONSTRAINT [FKe_DEPART_SUBEID_SUBELER_SUBEID] FOREIGN KEY([SUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[DEPART] CHECK CONSTRAINT [FKe_DEPART_SUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[DEPOFIS]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFIS_CDEPOID_DEPO_DEPOID] FOREIGN KEY([CDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[DEPOFIS] CHECK CONSTRAINT [FKe_DEPOFIS_CDEPOID_DEPO_DEPOID]
GO
ALTER TABLE [dbo].[DEPOFIS]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFIS_GDEPOID_DEPO_DEPOID] FOREIGN KEY([GDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[DEPOFIS] CHECK CONSTRAINT [FKe_DEPOFIS_GDEPOID_DEPO_DEPOID]
GO
ALTER TABLE [dbo].[DEPOFIS]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFIS_GSUBEID_SUBELER_SUBEID] FOREIGN KEY([GSUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[DEPOFIS] CHECK CONSTRAINT [FKe_DEPOFIS_GSUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[DEPOFIS]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFIS_SUBEID_SUBELER_SUBEID] FOREIGN KEY([CSUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[DEPOFIS] CHECK CONSTRAINT [FKe_DEPOFIS_SUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[DEPOFISISL]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFISISL_DEPOFISID_DEPOFIS_DEPOFISID] FOREIGN KEY([DEPOFISID])
REFERENCES [dbo].[DEPOFIS] ([DEPOFISID])
GO
ALTER TABLE [dbo].[DEPOFISISL] CHECK CONSTRAINT [FKe_DEPOFISISL_DEPOFISID_DEPOFIS_DEPOFISID]
GO
ALTER TABLE [dbo].[DEPOFISISL]  WITH CHECK ADD  CONSTRAINT [FKe_DEPOFISISL_RGDEPOID_DEPO_DEPOID] FOREIGN KEY([RGDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[DEPOFISISL] CHECK CONSTRAINT [FKe_DEPOFISISL_RGDEPOID_DEPO_DEPOID]
GO
ALTER TABLE [dbo].[EMLAKTAKSIT]  WITH CHECK ADD  CONSTRAINT [FK_EMLAKTAKSIT_EMLAKSATISID] FOREIGN KEY([EMLAKSATISID])
REFERENCES [dbo].[EMLAKSATIS] ([EMLAKSATISID])
GO
ALTER TABLE [dbo].[EMLAKTAKSIT] CHECK CONSTRAINT [FK_EMLAKTAKSIT_EMLAKSATISID]
GO
ALTER TABLE [dbo].[FATISL]  WITH CHECK ADD  CONSTRAINT [FK_FATISL_FATID_FATURA_FATID] FOREIGN KEY([FATID])
REFERENCES [dbo].[FATURA] ([FATID])
GO
ALTER TABLE [dbo].[FATISL] CHECK CONSTRAINT [FK_FATISL_FATID_FATURA_FATID]
GO
ALTER TABLE [dbo].[FATISL]  WITH CHECK ADD  CONSTRAINT [FKe_FATISL_RGDEPOID_DEPO_DEPOID] FOREIGN KEY([RGDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[FATISL] CHECK CONSTRAINT [FKe_FATISL_RGDEPOID_DEPO_DEPOID]
GO
ALTER TABLE [dbo].[FATURAEK]  WITH CHECK ADD  CONSTRAINT [FKe_FATURAEK_FATID_FATURA_FATID] FOREIGN KEY([FATID])
REFERENCES [dbo].[FATURA] ([FATID])
GO
ALTER TABLE [dbo].[FATURAEK] CHECK CONSTRAINT [FKe_FATURAEK_FATID_FATURA_FATID]
GO
ALTER TABLE [dbo].[FIRMAMODUL]  WITH CHECK ADD  CONSTRAINT [FK_EKRANLAR_EKRANID] FOREIGN KEY([EKRANID])
REFERENCES [dbo].[EKRANLAR] ([EKRANID])
GO
ALTER TABLE [dbo].[FIRMAMODUL] CHECK CONSTRAINT [FK_EKRANLAR_EKRANID]
GO
ALTER TABLE [dbo].[FIRMAMODUL]  WITH CHECK ADD  CONSTRAINT [FK_FIRMALAR_FIRMAID] FOREIGN KEY([FIRMAID])
REFERENCES [dbo].[FIRMALAR] ([FIRMAID])
GO
ALTER TABLE [dbo].[FIRMAMODUL] CHECK CONSTRAINT [FK_FIRMALAR_FIRMAID]
GO
ALTER TABLE [dbo].[GELIRGRUP]  WITH CHECK ADD  CONSTRAINT [FKe_GELIRGRUP_SUBEID_SUBELER_SUBEID] FOREIGN KEY([SUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[GELIRGRUP] CHECK CONSTRAINT [FKe_GELIRGRUP_SUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[MUH_FIS]  WITH CHECK ADD  CONSTRAINT [FKe_MUH_FIS_SUBEID_SUBELER_SUBEID] FOREIGN KEY([SUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[MUH_FIS] CHECK CONSTRAINT [FKe_MUH_FIS_SUBEID_SUBELER_SUBEID]
GO
ALTER TABLE [dbo].[MUH_HESAPISL]  WITH CHECK ADD  CONSTRAINT [FK_MUH_HESAPISL_HESAPID_MUH_HESAP_HESAPID] FOREIGN KEY([HESAPID])
REFERENCES [dbo].[MUH_HESAP] ([HESAPID])
GO
ALTER TABLE [dbo].[MUH_HESAPISL] CHECK CONSTRAINT [FK_MUH_HESAPISL_HESAPID_MUH_HESAP_HESAPID]
GO
ALTER TABLE [dbo].[MUH_HESAPISL]  WITH CHECK ADD  CONSTRAINT [FKe_MUH_HESAPISL_FISID_MUH_FIS_FISID] FOREIGN KEY([FISID])
REFERENCES [dbo].[MUH_FIS] ([FISID])
GO
ALTER TABLE [dbo].[MUH_HESAPISL] CHECK CONSTRAINT [FKe_MUH_HESAPISL_FISID_MUH_FIS_FISID]
GO
ALTER TABLE [dbo].[NOVAUSERD]  WITH CHECK ADD  CONSTRAINT [FK_NOVAUSERD_EKRANLAR_EKRANID] FOREIGN KEY([EKRANID])
REFERENCES [dbo].[EKRANLAR] ([EKRANID])
GO
ALTER TABLE [dbo].[NOVAUSERD] CHECK CONSTRAINT [FK_NOVAUSERD_EKRANLAR_EKRANID]
GO
ALTER TABLE [dbo].[NOVAUSERD]  WITH CHECK ADD  CONSTRAINT [FK_NOVAUSERD_NOVAUSER_NOVAUSERID] FOREIGN KEY([NOVAUSERID])
REFERENCES [dbo].[NOVAUSER] ([NOVAUSERID])
GO
ALTER TABLE [dbo].[NOVAUSERD] CHECK CONSTRAINT [FK_NOVAUSERD_NOVAUSER_NOVAUSERID]
GO
ALTER TABLE [dbo].[SATISODEME]  WITH CHECK ADD  CONSTRAINT [FK_SATISODEME_TUKETIMFIS_DEPOFISID] FOREIGN KEY([DEPOFISID])
REFERENCES [dbo].[TUKETIMFIS] ([DEPOFISID])
GO
ALTER TABLE [dbo].[SATISODEME] CHECK CONSTRAINT [FK_SATISODEME_TUKETIMFIS_DEPOFISID]
GO
ALTER TABLE [dbo].[STOK]  WITH CHECK ADD  CONSTRAINT [FKe_STOK_FIRMAID_FIRMALAR_FIRMAID] FOREIGN KEY([FIRMAID])
REFERENCES [dbo].[FIRMALAR] ([FIRMAID])
GO
ALTER TABLE [dbo].[STOK] CHECK CONSTRAINT [FKe_STOK_FIRMAID_FIRMALAR_FIRMAID]
GO
ALTER TABLE [dbo].[SUBELER]  WITH CHECK ADD  CONSTRAINT [FKe_SUBELER_SUBEFIRMALARI] FOREIGN KEY([FIRMAID])
REFERENCES [dbo].[FIRMALAR] ([FIRMAID])
GO
ALTER TABLE [dbo].[SUBELER] CHECK CONSTRAINT [FKe_SUBELER_SUBEFIRMALARI]
GO
ALTER TABLE [dbo].[TUKETIMFIS]  WITH CHECK ADD  CONSTRAINT [FK_TUKETIMFIS_DEPO] FOREIGN KEY([CDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[TUKETIMFIS] CHECK CONSTRAINT [FK_TUKETIMFIS_DEPO]
GO
ALTER TABLE [dbo].[TUKETIMFIS]  WITH CHECK ADD  CONSTRAINT [FK_TUKETIMFIS_FIRMALAR] FOREIGN KEY([FIRMAID])
REFERENCES [dbo].[FIRMALAR] ([FIRMAID])
GO
ALTER TABLE [dbo].[TUKETIMFIS] CHECK CONSTRAINT [FK_TUKETIMFIS_FIRMALAR]
GO
ALTER TABLE [dbo].[TUKETIMFIS]  WITH CHECK ADD  CONSTRAINT [FK_TUKETIMFIS_SUBELER] FOREIGN KEY([SUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[TUKETIMFIS] CHECK CONSTRAINT [FK_TUKETIMFIS_SUBELER]
GO
ALTER TABLE [dbo].[TUKETIMFIS]  WITH CHECK ADD  CONSTRAINT [FK_TUKETIMFIS_SUBELER1] FOREIGN KEY([CSUBEID])
REFERENCES [dbo].[SUBELER] ([SUBEID])
GO
ALTER TABLE [dbo].[TUKETIMFIS] CHECK CONSTRAINT [FK_TUKETIMFIS_SUBELER1]
GO
ALTER TABLE [dbo].[TUKETIMFISISL]  WITH CHECK ADD  CONSTRAINT [FK_TUKETIMFISISL_STOKID_STOK_STOKID] FOREIGN KEY([STOKID])
REFERENCES [dbo].[STOK] ([STOKID])
GO
ALTER TABLE [dbo].[TUKETIMFISISL] CHECK CONSTRAINT [FK_TUKETIMFISISL_STOKID_STOK_STOKID]
GO
ALTER TABLE [dbo].[TUKETIMFISISL]  WITH CHECK ADD  CONSTRAINT [FKe_TUKETIMFISISL_RCDEPOID_DEPO_DEPOID] FOREIGN KEY([RCDEPOID])
REFERENCES [dbo].[DEPO] ([DEPOID])
GO
ALTER TABLE [dbo].[TUKETIMFISISL] CHECK CONSTRAINT [FKe_TUKETIMFISISL_RCDEPOID_DEPO_DEPOID]
GO
/****** Object:  StoredProcedure [dbo].[API_GET_DEPO_BAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_DEPO_BAKIYE] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(20),@TARIH1 NVARCHAR(50),@TARIH2 NVARCHAR(50), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT
FNCQ_STOKBAKIYE.STOKID,STOK.KODU,STOK.BARKOD,MAX(STOKADI) AS STOKADI,STOK.FIRMAID,MAX(SUBEADI) AS SUBEADI,MAX(DEPOADI) AS DEPOADI,
GRUPKODU,GRUPADI,SUM(GCADET) AS KALAN,  SUM(GCADET)*MALIYET AS MALIYET,STOK.BIRIM,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5
FROM FNCQ_STOKBAKIYE('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''')
INNER JOIN STOK WITH (NOLOCK) ON STOK.STOKID=FNCQ_STOKBAKIYE.STOKID
LEFT JOIN SGRUP WITH (NOLOCK) ON STOK.FIRMAID = SGRUP.FIRMAID AND STOK.GRUPID = SGRUP.SGRUPID
WHERE  STOK.TURU=''Hammadde''
GROUP BY 
FNCQ_STOKBAKIYE.STOKID,STOK.FIRMAID,STOK.BARKOD,DEPOID,FNCQ_STOKBAKIYE.SUBEID,GRUPKODU,GRUPADI,SALISFIYAT,
SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,MALIYET,STOK.KODU,STOK.BIRIM '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_DEPOLAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_DEPOLAR] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(20), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(300)
SET @SQLCUMLE='SELECT DEPOID,DEPOADI,ISNULL(ANADEPO,0) AS ANADEPO,KODU,FIRMAID,SUBEID FROM DEPO WHERE ISNULL(SIL,0)<>-2 AND FIRMAID='+@FIRMAID+' '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_HESAPDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_HESAPDETAY] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30),@TARIH1 NVARCHAR(30),@TARIH2 NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT D.FISID,D.TARIH,H.HESAPID,H.KODU,H.ACIKLAMA, D.BORC,D.ALACAK,D.DBORC,D.DALACAK, D.KUR,D.DOVIZ
FROM FNCQ_HESAPDETAY_FATURA('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''','''') AS D
INNER JOIN MUH_HESAP AS H WITH(NOLOCK) ON D.HESAPID=H.HESAPID
WHERE 1=1 '+@PARAMETRE+'
ORDER BY TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_MUH_HESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_MUH_HESAP] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT H.FIRMAID,H.SUBEID,T.HESAPTIPID,H.HESAPID,T.HESAPTIPADI,H.KODU,H.ACIKLAMA,H.YETKILI,H.TEL1,H.GSM,H.FAX,H.EMAIL,
H.ADRES2 AS ILCE,H.SEHIR AS IL,H.ADRES1 AS ADRES
FROM MUH_HESAP AS H WITH(NOLOCK)
LEFT JOIN QMUH_HESAPTIP AS T WITH(NOLOCK) ON H.HESAPTIPID=T.HESAPTIPID
WHERE ISNULL(H.SIL,0)=0 AND FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_MUH_HESAP_BAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_MUH_HESAP_BAKIYE] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30),@TARIH1 NVARCHAR(30),@TARIH2 NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TABLO.HESAPKODU,QMUH_HESAPTIP.HESAPTIPID, QMUH_HESAPTIP.HESAPTIPADI,TABLO.HESAPADI,TABLO.BORC,TABLO.ALACAK,TABLO.BAKIYE,TABLO.DBORC,TABLO.DALACAK,TABLO.DBAKIYE FROM 
(SELECT SUM(BORC) AS BORC,SUM(ALACAK) AS ALACAK,(SUM(BORC)-SUM(ALACAK)) AS BAKIYE,
SUM(DBORC) AS DBORC,SUM(DALACAK) AS DALACAK,(SUM(DBORC)-SUM(DALACAK)) AS DBAKIYE,
HESAPID,HESAPKODU,HESAPADI
FROM FNCQ_HESAPDETAY_FATURA('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''','''') GROUP BY HESAPID,HESAPKODU,HESAPADI
) AS TABLO INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAP.HESAPID=TABLO.HESAPID
LEFT JOIN QMUH_HESAPTIP WITH (NOLOCK) ON MUH_HESAP.HESAPTIPID=QMUH_HESAPTIP.HESAPTIPID
WHERE ISNULL(MUH_HESAP.UCHESAP,0)=1  '+@PARAMETRE+' ORDER BY HESAPKODU '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_MUH_HESAPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[API_GET_MUH_HESAPTIP] @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(100)
SET @SQLCUMLE='SELECT * FROM QMUH_HESAPTIP WITH(NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_STOKGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_STOKGRUP] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SGRUPID,FIRMAID,SUBEID,GRUPKODU,GRUPADI,GRUPTURU FROM SGRUP WITH(NOLOCK)
WHERE ISNULL(SIL,0)=0 AND FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_STOKGRUPTURU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_STOKGRUPTURU] @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(100)
SET @SQLCUMLE='SELECT DISTINCT GRUPTURU FROM SGRUP WITH(NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_STOKLISTESI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[API_GET_STOKLISTESI] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1000)
SET @SQLCUMLE='SELECT S.FIRMAID,S.SUBEID,S.TURU,G.GRUPADI,G.GRUPKODU,S.KODU,S.ADI,M.MARKAADI, S.GARANTISURESI,S.SFIYAT1,S.SDOVIZ,S.ADD_DATE,S.EDIT_DATE
FROM STOK AS S 
INNER JOIN SGRUP AS G WITH(NOLOCK) ON S.GRUP=G.GRUPKODU 
LEFT JOIN STOKMARKA AS M WITH(NOLOCK) ON S.MARKAID=M.MARKAID
WHERE ISNULL(S.SIL,0)=0 AND ISNULL(M.SIL,0)=0 AND S.FIRMAID='+@FIRMAID+' AND S.SUBEID='+@SUBEID+' '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[API_GET_STOKTURU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[API_GET_STOKTURU] @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(100)
SET @SQLCUMLE='SELECT DISTINCT TURU FROM STOK WITH(NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[CopyTables_Full]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[CopyTables_Full]
(
    @Suffix NVARCHAR(10),   -- örn: '501' veya '59'
    @FIRMAID INT
)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE 
        @SourceTable SYSNAME,
        @TargetTable SYSNAME,
        @SQL NVARCHAR(MAX),
        @Columns NVARCHAR(MAX),
        @SelectColumns NVARCHAR(MAX),
        @HasIdentity BIT;

    ------------------------------------------------
    -- FK’leri geçici kapat
    ------------------------------------------------
    PRINT 'FK Kontrolleri Kapatılıyor...';
    EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL';

    ------------------------------------------------
    -- Öncelikli tablo sırası
    ------------------------------------------------
    DECLARE @Priority TABLE (TableName SYSNAME, Sira INT)

    INSERT INTO @Priority VALUES
    ('FIRMALAR',1),
    ('SUBELER',2),
    ('MUH_HESAP',3),
    ('DEPO',4),
    ('STOK',5),
    ('BARKOD',6),
    ('FATURA',7),
    ('FATISL',8),
    ('DEPOFIS',9),
    ('DEPOFISISL',10),
    ('TUKETIMFIS',11),
    ('TUKETIMFISISL',12)

    ------------------------------------------------
    -- Cursor
    ------------------------------------------------
    DECLARE table_cursor CURSOR FOR
    SELECT name
    FROM sys.tables
    WHERE name LIKE '%' + @Suffix
    ORDER BY
        CASE 
            WHEN LEFT(name, LEN(name)-LEN(@Suffix)) IN (SELECT TableName FROM @Priority)
            THEN (SELECT Sira FROM @Priority WHERE TableName = LEFT(name, LEN(name)-LEN(@Suffix)))
            ELSE 999
        END,
        name

    OPEN table_cursor;
    FETCH NEXT FROM table_cursor INTO @SourceTable;

    WHILE @@FETCH_STATUS = 0
    BEGIN
        BEGIN TRY

            SET @TargetTable = LEFT(@SourceTable, LEN(@SourceTable) - LEN(@Suffix));

            IF OBJECT_ID(@TargetTable) IS NULL
            BEGIN
                FETCH NEXT FROM table_cursor INTO @SourceTable;
                CONTINUE;
            END

            ------------------------------------------------
            -- Kolon listesi
            ------------------------------------------------
            SELECT 
                @Columns = STRING_AGG(QUOTENAME(name), ','),
                @SelectColumns = STRING_AGG(
                    CASE 
                        WHEN name = 'FIRMAID' THEN '@FIRMAID'
                        ELSE QUOTENAME(name)
                    END
                , ',')
            FROM sys.columns
            WHERE object_id = OBJECT_ID(@TargetTable);

            ------------------------------------------------
            -- Identity kontrol
            ------------------------------------------------
            SELECT @HasIdentity =
            CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END
            FROM sys.columns
            WHERE object_id = OBJECT_ID(@TargetTable)
            AND is_identity = 1;

            ------------------------------------------------
            -- Tablo temizleme
            ------------------------------------------------
            BEGIN TRY
                SET @SQL = 'TRUNCATE TABLE ' + QUOTENAME(@TargetTable);
                EXEC (@SQL);
            END TRY
            BEGIN CATCH
                SET @SQL = 'DELETE FROM ' + QUOTENAME(@TargetTable);
                EXEC (@SQL);
            END CATCH

            ------------------------------------------------
            -- Insert
            ------------------------------------------------
            SET @SQL = '';

            IF @HasIdentity = 1
                SET @SQL = 'SET IDENTITY_INSERT ' + QUOTENAME(@TargetTable) + ' ON;';

            SET @SQL = @SQL + '
            INSERT INTO ' + QUOTENAME(@TargetTable) + ' (' + @Columns + ')
            SELECT ' + @SelectColumns + '
            FROM ' + QUOTENAME(@SourceTable) + ';';

            IF @HasIdentity = 1
                SET @SQL = @SQL + '
            SET IDENTITY_INSERT ' + QUOTENAME(@TargetTable) + ' OFF;';

            EXEC sp_executesql
                @SQL,
                N'@FIRMAID INT',
                @FIRMAID;

            PRINT @SourceTable + ' -> OK';

        END TRY
        BEGIN CATCH
            PRINT @SourceTable + ' -> HATA: ' + ERROR_MESSAGE();
        END CATCH

        FETCH NEXT FROM table_cursor INTO @SourceTable;
    END

    CLOSE table_cursor;
    DEALLOCATE table_cursor;

    ------------------------------------------------
    -- FK kontrollerini tekrar aç
    ------------------------------------------------
    PRINT 'FK Kontrolleri Açılıyor...';
    EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL';

END
GO
/****** Object:  StoredProcedure [dbo].[CopyTables_Full2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[CopyTables_Full2]
(
    @Suffix NVARCHAR(10),          -- örn: '501' veya '59'
    @FIRMAID INT,
    @TableName SYSNAME = 'ALLTABLES' -- 'ALLTABLES' = tüm tablolar, başka tablo = sadece o tablo
)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE 
        @SourceTable SYSNAME,
        @TargetTable SYSNAME,
        @SQL NVARCHAR(MAX),
        @Columns NVARCHAR(MAX),
        @SelectColumns NVARCHAR(MAX),
        @HasIdentity BIT;

    ------------------------------------------------
    -- FK’leri geçici kapat
    ------------------------------------------------
    PRINT 'FK Kontrolleri Kapatılıyor...';
    EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL';

    ------------------------------------------------
    -- Öncelikli tablo sırası
    ------------------------------------------------
    DECLARE @Priority TABLE (TableName SYSNAME, Sira INT)

    INSERT INTO @Priority VALUES
    ('FIRMALAR',1),
    ('SUBELER',2),
    ('MUH_HESAP',3),
    ('DEPO',4),
    ('STOK',5),
    ('BARKOD',6),
    ('FATURA',7),
    ('FATISL',8),
    ('DEPOFIS',9),
    ('DEPOFISISL',10),
    ('TUKETIMFIS',11),
    ('TUKETIMFISISL',12)

    ------------------------------------------------
    -- Cursor için tablo seçimi
    ------------------------------------------------
    DECLARE table_cursor CURSOR FOR
    SELECT name
    FROM sys.tables
    WHERE name LIKE '%' + @Suffix
      AND (@TableName = 'ALLTABLES' OR LEFT(name,LEN(name)-LEN(@Suffix)) = @TableName)
    ORDER BY
        CASE 
            WHEN LEFT(name, LEN(name)-LEN(@Suffix)) IN (SELECT TableName FROM @Priority)
            THEN (SELECT Sira FROM @Priority WHERE TableName = LEFT(name, LEN(name)-LEN(@Suffix)))
            ELSE 999
        END,
        name

    OPEN table_cursor;
    FETCH NEXT FROM table_cursor INTO @SourceTable;

    WHILE @@FETCH_STATUS = 0
    BEGIN
        BEGIN TRY

            SET @TargetTable = LEFT(@SourceTable, LEN(@SourceTable) - LEN(@Suffix));

            IF OBJECT_ID(@TargetTable) IS NULL
            BEGIN
                FETCH NEXT FROM table_cursor INTO @SourceTable;
                CONTINUE;
            END

            ------------------------------------------------
            -- Kolon listesi
            ------------------------------------------------
            SELECT 
                @Columns = STRING_AGG(QUOTENAME(name), ','),
                @SelectColumns = STRING_AGG(
                    CASE 
                        WHEN name = 'FIRMAID' THEN '@FIRMAID'
                        ELSE QUOTENAME(name)
                    END
                , ',')
            FROM sys.columns
            WHERE object_id = OBJECT_ID(@TargetTable);

            ------------------------------------------------
            -- Identity kontrol
            ------------------------------------------------
            SELECT @HasIdentity =
            CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END
            FROM sys.columns
            WHERE object_id = OBJECT_ID(@TargetTable)
            AND is_identity = 1;

            ------------------------------------------------
            -- Tablo temizleme
            ------------------------------------------------
            BEGIN TRY
                SET @SQL = 'TRUNCATE TABLE ' + QUOTENAME(@TargetTable);
                EXEC (@SQL);
            END TRY
            BEGIN CATCH
                SET @SQL = 'DELETE FROM ' + QUOTENAME(@TargetTable);
                EXEC (@SQL);
            END CATCH

            ------------------------------------------------
            -- Insert
            ------------------------------------------------
            SET @SQL = '';

            IF @HasIdentity = 1
                SET @SQL = 'SET IDENTITY_INSERT ' + QUOTENAME(@TargetTable) + ' ON;';

            SET @SQL = @SQL + '
            INSERT INTO ' + QUOTENAME(@TargetTable) + ' (' + @Columns + ')
            SELECT ' + @SelectColumns + '
            FROM ' + QUOTENAME(@SourceTable) + ';';

            IF @HasIdentity = 1
                SET @SQL = @SQL + '
            SET IDENTITY_INSERT ' + QUOTENAME(@TargetTable) + ' OFF;';

            EXEC sp_executesql
                @SQL,
                N'@FIRMAID INT',
                @FIRMAID;

            PRINT @SourceTable + ' -> OK';

        END TRY
        BEGIN CATCH
            PRINT @SourceTable + ' -> HATA: ' + ERROR_MESSAGE();
        END CATCH

        FETCH NEXT FROM table_cursor INTO @SourceTable;
    END

    CLOSE table_cursor;
    DEALLOCATE table_cursor;

    ------------------------------------------------
    -- FK kontrollerini tekrar aç
    ------------------------------------------------
    PRINT 'FK Kontrolleri Açılıyor...';
    EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL';

END
GO
/****** Object:  StoredProcedure [dbo].[CopyTables_Suffix]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE   PROCEDURE [dbo].[CopyTables_Suffix]
(
    @KaynakSuffix NVARCHAR(10),   -- örn: '501'
    @FIRMAID INT
)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @Tables TABLE (TableName SYSNAME);

    INSERT INTO @Tables VALUES
    ('FIRMALAR'),
    ('SUBELER'),
    ('MUH_HESAP'),
    ('DEPO'),
    ('STOK'),
    ('BARKOD'),
    ('FATURA'),
    ('FATISL'),
    ('DEPOFIS'),
    ('DEPOFISISL'),
    ('TUKETIMFIS'),
    ('TUKETIMFISISL');

    DECLARE 
        @TableName SYSNAME,
        @SourceTable SYSNAME,
        @SQL NVARCHAR(MAX);

    DECLARE cur CURSOR FOR
        SELECT TableName FROM @Tables;

    OPEN cur;
    FETCH NEXT FROM cur INTO @TableName;

    WHILE @@FETCH_STATUS = 0
    BEGIN
        BEGIN TRY

            SET @SourceTable = @TableName + @KaynakSuffix;

            IF OBJECT_ID(@SourceTable) IS NULL
            BEGIN
                PRINT @SourceTable + ' bulunamadı';
                FETCH NEXT FROM cur INTO @TableName;
                CONTINUE;
            END

            IF EXISTS (SELECT 1 FROM sys.partitions WHERE object_id = OBJECT_ID(@TableName) AND rows > 0)
            BEGIN
                PRINT @TableName + ' dolu, pas geçildi';
                FETCH NEXT FROM cur INTO @TableName;
                CONTINUE;
            END

            IF EXISTS (
                SELECT 1
                FROM sys.columns
                WHERE object_id = OBJECT_ID(@TableName)
                AND is_identity = 1
            )
            BEGIN
                SET @SQL = '
                SET IDENTITY_INSERT ' + @TableName + ' ON;

                INSERT INTO ' + @TableName + '
                SELECT * FROM ' + @SourceTable + ';

                SET IDENTITY_INSERT ' + @TableName + ' OFF;';
            END
            ELSE
            BEGIN
                SET @SQL = '
                INSERT INTO ' + @TableName + '
                SELECT * FROM ' + @SourceTable;
            END

            EXEC(@SQL);

            PRINT @SourceTable + ' -> OK';

        END TRY
        BEGIN CATCH
            PRINT @SourceTable + ' -> HATA: ' + ERROR_MESSAGE();
        END CATCH

        FETCH NEXT FROM cur INTO @TableName;
    END

    CLOSE cur;
    DEALLOCATE cur;

END
GO
/****** Object:  StoredProcedure [dbo].[FU_CEKDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[FU_CEKDURUM]
AS
SELECT 1 AS DURUMID, 'IPTAL' AS DURUM
UNION ALL
SELECT 2 AS DURUMID, 'İADE' AS DURUM
UNION ALL
SELECT 3 AS DURUMID, 'KAYIP' AS DURUM
UNION ALL
SELECT 4 AS DURUMID, 'ZAYİ' AS DURUM
UNION ALL
SELECT 5 AS DURUMID, 'DİĞER' AS DURUM
GO
/****** Object:  StoredProcedure [dbo].[INDEX_MAINTENANCE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[INDEX_MAINTENANCE] @DBName VARCHAR(100)
AS BEGIN

        SET NOCOUNT ON;
        DECLARE

            @OBJECT_ID INT,

            @INDEX_NAME sysname,

            @SCHEMA_NAME sysname,

            @OBJECT_NAME sysname,

            @AVG_FRAG float,

            @command varchar(8000),

            @RebuildCount int,

          @ReOrganizeCount int


        CREATE TABLE #tempIM (

            [ID] [INT] IDENTITY(1,1) NOT NULL PRIMARY KEY,

            [INDEX_NAME] sysname NULL,

            [OBJECT_ID] INT NULL,

            [SCHEMA_NAME] sysname NULL,

            [OBJECT_NAME] sysname NULL,

            [AVG_FRAG] float

        )      

        SELECT @RebuildCount=0,@ReOrganizeCount=0

         

        --Get Fragentation values

        SELECT @command=

            'Use ' + @DBName + ';

            INSERT INTO #tempIM (OBJECT_ID, INDEX_NAME, SCHEMA_NAME, OBJECT_NAME, AVG_FRAG)

            SELECT

                ps.object_id,

                i.name as IndexName,

                OBJECT_SCHEMA_NAME(ps.object_id) as ObjectSchemaName,

                OBJECT_NAME (ps.object_id) as ObjectName,

                ps.avg_fragmentation_in_percent

            FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL , NULL, ''LIMITED'') ps

            INNER JOIN sys.indexes i ON i.object_id=ps.object_id and i.index_id=ps.index_id

            WHERE avg_fragmentation_in_percent > 5 AND ps.index_id > 0

                and ps.database_id=DB_ID('''+@DBName+''')

            ORDER BY avg_fragmentation_in_percent desc

            '

         

        exec(@command)

        DECLARE c CURSOR FAST_FORWARD FOR

            SELECT OBJECT_ID,INDEX_NAME, SCHEMA_NAME, OBJECT_NAME, AVG_FRAG

            FROM #tempIM

        OPEN c

        FETCH NEXT FROM c INTO @OBJECT_ID, @INDEX_NAME, @SCHEMA_NAME, @OBJECT_NAME, @AVG_FRAG

        WHILE @@FETCH_STATUS = 0

        BEGIN

            --Reorganize or Rebuild

            IF @AVG_FRAG>30 BEGIN

                SELECT @command = 'Use ' + @DBName + '; ALTER INDEX [' + @INDEX_NAME +'] ON ['

                                  + @SCHEMA_NAME + '].[' + @OBJECT_NAME + '] REBUILD   WITH (ONLINE = ON  )';

                SET @RebuildCount = @RebuildCount+1

            END ELSE BEGIN

                SELECT @command = 'Use ' + @DBName + '; ALTER INDEX [' + @INDEX_NAME +'] ON ['

                                  + @SCHEMA_NAME + '].[' + @OBJECT_NAME + '] REORGANIZE ';

                SET @ReOrganizeCount = @ReOrganizeCount+1

            END

                                   

            BEGIN TRY

                EXEC (@command);    

            END TRY

            BEGIN CATCH

            END CATCH


            FETCH NEXT FROM c INTO @OBJECT_ID, @INDEX_NAME, @SCHEMA_NAME, @OBJECT_NAME, @AVG_FRAG
        END

        CLOSE c

        DEALLOCATE c

        DROP TABLE #tempIM

        SELECT cast(@RebuildCount as varchar(5))+' index Rebuild,'+cast(@ReOrganizeCount as varchar(5))+' index Reorganize edilmistir.' as Result

END
GO
/****** Object:  StoredProcedure [dbo].[MBL_ADISYONGARSONOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MBL_ADISYONGARSONOZET]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30),  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TARIH,DEPART.ADI AS DEPARTMAN,ADISYON.TUR, GARSON.GADI, SUM(TOPLAM) AS TOPLAM, 
SUM(TOPLAM/100*ISNULL(INDORAN,0)) AS INDTUTAR, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS NETTOPLAM 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART WITH (NOLOCK) ON ADISYON.DEPID=DEPART.DEPARTMANID
INNER JOIN GARSON WITH (NOLOCK) ON ADISYON.GARSONID=GARSON.GARSONID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 AND ADISYON.FIRMAID='+@FIRMAID+' AND ADISYON.SUBEID='+@SUBEID+' '+@PARAMETRE+'
GROUP BY TARIH,DEPART.ADI,ADISYON.TUR,GADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_ADISYONOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MBL_ADISYONOZET]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,DEPART.ADI AS DEPARTMAN,ADISYON.TUR, SUM(TOPLAM) AS TOPLAM, 
SUM(TOPLAM/100*ISNULL(INDORAN,0)) AS INDTUTAR, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS NETTOPLAM 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART WITH (NOLOCK) ON ADISYON.DEPID=DEPART.DEPARTMANID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 AND ADISYON.FIRMAID='+@FIRMAID+' AND ADISYON.SUBEID='+@SUBEID+' '+@PARAMETRE+'
GROUP BY TARIH,DEPART.ADI,ADISYON.TUR'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_ADISYONTAHSILATOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MBL_ADISYONTAHSILATOZET]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,ODEMETURU,ODEMETURID,SUM(TUTAR) AS TUTAR 
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(SIL,0)=0 AND TUR=''SATIS'' AND 1=1 AND ADISYON.FIRMAID='+@FIRMAID+' AND ADISYON.SUBEID='+@SUBEID+' '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_ADISYONTOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MBL_ADISYONTOPLAM] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SUM(TOPLAM/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM
FROM ADISYON
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 AND ADISYON.FIRMAID='+@FIRMAID+' AND ADISYON.SUBEID='+@SUBEID+' '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_ADISYONURUNSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE PROCEDURE [dbo].[MBL_ADISYONURUNSATIS] @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(900)
SET @SQLCUMLE='SELECT 
(CASE WHEN IKRAM=1 THEN ''IKRAM''
	 WHEN IADE=1 THEN ''IADE''
	 WHEN ZAYII=1 THEN ''ZAYII''
	 ELSE ''SATIŞ'' END) AS DURUM,
TARIH,ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID 
AND ADISYON.SUBEID=STOK.SUBEID
WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 AND ADISYON.FIRMAID='+@FIRMAID+' AND ADISYON.SUBEID='+@SUBEID+' '+@PARAMETRE+'
GROUP BY TARIH,STOK.ADI,STOK.BIRIM,ADISYON.TUR,ADSSATIR.IKRAM,ADSSATIR.IADE, ADSSATIR.ZAYII
ORDER BY DURUM DESC,ADISYON.TUR DESC,STOK.ADI'
EXEC (@SQLCUMLE)

--SET @SQLCUMLE='SELECT TARIH,ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
--SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM 
--FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
--INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID 
--AND ADISYON.SUBEID=STOK.SUBEID
--WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
--GROUP BY TARIH,STOK.ADI,STOK.BIRIM,ADISYON.TUR
--ORDER BY ADISYON.TUR DESC,STOK.ADI'

END
GO
/****** Object:  StoredProcedure [dbo].[MBL_BANKABAKIYERAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[MBL_BANKABAKIYERAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT
KODU,
UNVANI,
SUM(BORC) AS [BORC],
SUM(ALACAK) AS [ALACAK],
(SUM(BORC)-SUM(ALACAK)) AS [BAKIYE],
(SUM([DOVIZLIBORC])) AS [DOVIZLIBORC],
(SUM([DOVIZLIALACAK])) AS [DOVIZLIALACAK],
(SUM([DOVIZLIBORC])-SUM([DOVIZLIALACAK])) AS [DOVIZBAKIYE],
DURUM=(CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN ''BORÇLU''
 WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN ''ALACAKLI''
 ELSE ''BAKİYESİZ'' END) 
FROM (
SELECT MUH_HESAPISL.FISID,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.BORC AS BORC,
MUH_HESAPISL.ALACAK AS ALACAK,
MUH_HESAPISL.DBORC AS [DOVIZLIBORC],
MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK] 
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID=1 
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=102
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'

UNION ALL

SELECT MUH_HESAPISL.FISID,
MUH_FIS.FISHESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.ALACAK as BORC,
MUH_HESAPISL.BORC AS ALACAK,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],
MUH_HESAPISL.DBORC AS [DOVIZLIALACAK]
from  MUH_HESAPISL WITH (NOLOCK) -- MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID=1
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=102
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'

) AS MAIN
GROUP BY HESAPID,KODU,UNVANI
ORDER BY KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_CARIBAKIYERAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MBL_CARIBAKIYERAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT
KODU,
UNVANI,
SUM(BORC) AS BORC,
SUM(ALACAK) AS ALACAK,
(SUM(BORC)-SUM(ALACAK)) AS BAKIYE,
(SUM([DOVIZLIBORC])) AS [DOVIZLIBORC],
(SUM([DOVIZLIALACAK])) AS [DOVIZLIALACAK],
(SUM([DOVIZLIBORC])-SUM([DOVIZLIALACAK])) AS [DOVIZBAKIYE],
DURUM=(CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN ''BORÇLU''
 WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN ''ALACAKLI''
 ELSE ''BAKİYESİZ'' END) 
FROM (
SELECT MUH_HESAPISL.FISID,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.BORC AS BORC,
MUH_HESAPISL.ALACAK AS ALACAK,
MUH_HESAPISL.DBORC AS [DOVIZLIBORC],
MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK] 
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID=1
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+' '+@PARAMETRE+'
UNION ALL

SELECT MUH_HESAPISL.FISID,
MUH_FIS.FISHESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.ALACAK as BORÇ,
MUH_HESAPISL.BORC AS ALACAK,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],
MUH_HESAPISL.DBORC AS [DOVIZLIALACAK]
from  MUH_HESAPISL WITH (NOLOCK) -- MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID=1
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+' '+@PARAMETRE+'
) AS MAIN
GROUP BY HESAPID,KODU,UNVANI ORDER BY KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_CARIMUAVINRAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[MBL_CARIMUAVINRAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT 
FISID,
QMUH_FISDURUM.FISDURUM AS [FISDURUMU],
MAIN.FIRMAID,
MAIN.SUBEID,
FISNO,
TARIH,
VADE,
FISTURU,
BELGETURU,
BELGENO,
BELGEACIKLAMA,
MAIN.ACIKLAMA,
HESAPID,
MAIN.KODU,
UNVANI,
DOVIZ,
KUR,
TOPLAM,
DTOPLAM,
TUTAR,
DTUTAR,
Borc AS BORC,
Alacak AS ALACAK,
[DOVIZLIBORC],
[DOVIZLIALACAK],
MIKTAR,
BIRIM,
BIRIMFIYAT
FROM(
SELECT
MUH_HESAPISL.FISID,
MUH_FIS.FISDURUMID,
MUH_FIS.FIRMAID,
MUH_FIS.SUBEID,
MUH_FIS.FISNO,
MUH_FIS.TARIH,
MUH_FIS.VADE,
MUH_FIS.FISTURU,
MUH_FIS.BELGETURU,
MUH_FIS.BELGENO,
MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.DOVIZ,
MUH_HESAPISL.KUR,
MUH_FIS.TOPLAM,
MUH_FIS.DTOPLAM,
MUH_HESAPISL.TUTAR,
MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.BORC AS Borc,
MUH_HESAPISL.ALACAK AS Alacak,
MUH_HESAPISL.DBORC AS [DOVIZLIBORC],
MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK],
MUH_HESAPISL.MIKTAR,
MUH_HESAPISL.BIRIM,
MUH_HESAPISL.BIRIMFIYAT
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE  (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'
UNION ALL
SELECT
MUH_HESAPISL.FISID,
MUH_FIS.FISDURUMID,
MUH_FIS.FIRMAID,
MUH_FIS.SUBEID,
MUH_FIS.FISNO,
MUH_FIS.TARIH,
MUH_FIS.VADE,
MUH_FIS.FISTURU,
MUH_FIS.BELGETURU,
MUH_FIS.BELGENO,
MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.DOVIZ,
MUH_HESAPISL.KUR,
MUH_FIS.TOPLAM,
MUH_FIS.DTOPLAM,
MUH_HESAPISL.TUTAR,
MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.ALACAK AS Borc,
MUH_HESAPISL.BORC AS Alacak,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],
MUH_HESAPISL.DBORC AS [DOVIZLIALACAK],
MUH_HESAPISL.MIKTAR,
MUH_HESAPISL.BIRIM,
MUH_HESAPISL.BIRIMFIYAT
from  MUH_HESAPISL WITH (NOLOCK)--MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+') 
AS MAIN
INNER JOIN QMUH_FISDURUM WITH (NOLOCK) ON MAIN.FISDURUMID=QMUH_FISDURUM.FISDURUMID
WHERE 1=1 '+@PARAMETRE+'
ORDER BY MAIN.KODU, MAIN.TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_DENEME44]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[MBL_DENEME44]  @FIRMAID NVARCHAR(20),@SUBEID NVARCHAR(20), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT
KODU,
UNVANI,
SUM(BORC) AS BORC,
SUM(ALACAK) AS ALACAK,
(SUM(BORC)-SUM(ALACAK)) AS BAKIYE,
(SUM([Dövizli Borc])) AS [Dövizli Borc],
(SUM([Dövizli Alacak])) AS [Dövizli Alacak],
(SUM([Dövizli Borc])-SUM([Dövizli Alacak])) AS [Döviz Bakiye],
DURUM=(CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN ''BORÇLU''
 WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN ''ALACAKLI''
 ELSE ''BAKİYESİZ'' END) 
FROM (
SELECT MUH_HESAPISL.FISID,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.BORC AS BORC,
MUH_HESAPISL.ALACAK AS ALACAK,
MUH_HESAPISL.DBORC AS [Dövizli Borc],
MUH_HESAPISL.DALACAK AS [Dövizli Alacak] 
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID='+@FIRMAID+' AND MUH_FIS.SUBEID='+@SUBEID+' 
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100
UNION ALL

SELECT MUH_HESAPISL.FISID,
MUH_FIS.FISHESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.ALACAK as BORÇ,
MUH_HESAPISL.BORC AS ALACAK,
MUH_HESAPISL.DALACAK AS [Dövizli Borç],
MUH_HESAPISL.DBORC AS [Dövizli Alacak]
from  MUH_HESAPISL WITH (NOLOCK) -- MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID='+@FIRMAID+' AND MUH_FIS.SUBEID='+@SUBEID+' 
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100
) AS MAIN
WHERE AND 1=1 '+@PARAMETRE+'
 GROUP BY HESAPID,KODU,UNVANI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_GUNLUKBANKAMUAVIN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[MBL_GUNLUKBANKAMUAVIN]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT FISID,QMUH_FISDURUM.FISDURUM AS [FISDURUMU],MAIN.FIRMAID,MAIN.SUBEID,FISNO,TARIH,VADE,FISTURU,BELGETURU,BELGENO,BELGEACIKLAMA,MAIN.ACIKLAMA,HESAPID,MAIN.KODU,UNVANI,
DOVIZ,KUR,TOPLAM,DTOPLAM,TUTAR,DTUTAR,Borc AS BORC,Alacak AS ALACAK,[DOVIZLIBORC],[DOVIZLIALACAK],MIKTAR,BIRIM,BIRIMFIYAT
FROM(

SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.BORC AS Borc,MUH_HESAPISL.ALACAK AS Alacak,MUH_HESAPISL.DBORC AS [DOVIZLIBORC],MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT
FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE  (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0  AND MUH_HESAP.HESAPTIPID=102 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'

UNION ALL

SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,MUH_HESAPISL.ALACAK AS Borc,MUH_HESAPISL.BORC AS Alacak,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],MUH_HESAPISL.DBORC AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT

FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=102 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+') 
AS MAIN

INNER JOIN QMUH_FISDURUM WITH (NOLOCK) ON MAIN.FISDURUMID=QMUH_FISDURUM.FISDURUMID
WHERE MAIN.TARIH=CONVERT(varchar, getdate(), 102)  ORDER BY MAIN.KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_GUNLUKKASARAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[MBL_GUNLUKKASARAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT 
FISID,QMUH_FISDURUM.FISDURUM AS [FISDURUMU],MAIN.FIRMAID,MAIN.SUBEID,FISNO,TARIH,VADE,FISTURU,BELGETURU,BELGENO,BELGEACIKLAMA,MAIN.ACIKLAMA,HESAPID,MAIN.KODU,UNVANI,DOVIZ,KUR,
TOPLAM,DTOPLAM,TUTAR,DTUTAR,Borc AS BORC,Alacak AS ALACAK,[DOVIZLIBORC],[DOVIZLIALACAK],MIKTAR,BIRIM,BIRIMFIYAT
FROM(
SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.BORC AS Borc,MUH_HESAPISL.ALACAK AS Alacak,MUH_HESAPISL.DBORC AS [DOVIZLIBORC],MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT
FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE  (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0  AND MUH_HESAP.HESAPTIPID=100 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'
UNION ALL
SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.ALACAK AS Borc,MUH_HESAPISL.BORC AS Alacak,MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],MUH_HESAPISL.DBORC AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT
FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+')  AS MAIN
INNER JOIN QMUH_FISDURUM WITH (NOLOCK) ON MAIN.FISDURUMID=QMUH_FISDURUM.FISDURUMID
WHERE MAIN.TARIH=CONVERT(varchar, getdate(), 102)  ORDER BY MAIN.KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_KASABAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[MBL_KASABAKIYE]  @FIRMAID NVARCHAR(20),@SUBEID NVARCHAR(20), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1600)
SET @SQLCUMLE='SELECT
KODU,
UNVANI,
SUM(BORC) AS BORC,
SUM(ALACAK) AS ALACAK,
(SUM(BORC)-SUM(ALACAK)) AS BAKIYE,
(SUM([DOVIZLIBORC])) AS [DOVIZLIBORC],
(SUM([DOVIZLIALACAK])) AS [DOVIZLIALACAK],
(SUM([DOVIZLIBORC])-SUM([DOVIZLIALACAK])) AS [DOVIZBAKIYE],
DURUM=(CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN ''BORÇLU''
 WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN ''ALACAKLI''
 ELSE ''BAKİYESİZ'' END) 
FROM (
SELECT MUH_HESAPISL.FISID,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.BORC AS BORC,
MUH_HESAPISL.ALACAK AS ALACAK,
MUH_HESAPISL.DBORC AS [DOVIZLIBORC],
MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK] 
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID='+@FIRMAID+' AND MUH_FIS.SUBEID='+@SUBEID+' 
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100
UNION ALL

SELECT MUH_HESAPISL.FISID,
MUH_FIS.FISHESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.ALACAK as BORC,
MUH_HESAPISL.BORC AS ALACAK,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],
MUH_HESAPISL.DBORC AS [DOVIZLIALACAK]
from  MUH_HESAPISL WITH (NOLOCK) -- MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE MUH_FIS.FIRMAID='+@FIRMAID+' AND MUH_FIS.SUBEID='+@SUBEID+' 
AND (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100
) AS MAIN
WHERE 1=1 '+@PARAMETRE+'
 GROUP BY HESAPID,KODU,UNVANI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_KASAMUAVINDEFTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MBL_KASAMUAVINDEFTER]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT 
FISID,
QMUH_FISDURUM.FISDURUM AS [FIS DURUMU],MAIN.FIRMAID,MAIN.SUBEID,FISNO,TARIH,VADE,FISTURU,BELGETURU,BELGENO,BELGEACIKLAMA,MAIN.ACIKLAMA,HESAPID,MAIN.KODU,UNVANI,
DOVIZ,KUR,TOPLAM,DTOPLAM,TUTAR,DTUTAR,Borc AS BORC,Alacak AS ALACAK,[DOVIZLIBORC],[DOVIZLIALACAK],MIKTAR,BIRIM,BIRIMFIYAT
FROM(

SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,
MUH_FIS.BELGEACIKLAMA,MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,
MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,MUH_HESAPISL.BORC AS Borc,MUH_HESAPISL.ALACAK AS Alacak,MUH_HESAPISL.DBORC AS [DOVIZLIBORC],MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK],
MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT
FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE  (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0  AND MUH_HESAP.HESAPTIPID=100 AND MUH_HESAP.FIRMAID='+@FIRMAID+ 'AND MUH_HESAP.SUBEID='+@SUBEID +'
UNION ALL
SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,
MUH_FIS.BELGEACIKLAMA,MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,
MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,MUH_HESAPISL.ALACAK AS Borc,MUH_HESAPISL.BORC AS Alacak,MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],MUH_HESAPISL.DBORC AS [DOVIZLIALACAK],
MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT
FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=100) AND MUH_HESAP.FIRMAID='+@FIRMAID+ 'AND MUH_HESAP.SUBEID='+@SUBEID +' 
AS MAIN

INNER JOIN QMUH_FISDURUM WITH (NOLOCK) ON MAIN.FISDURUMID=QMUH_FISDURUM.FISDURUMID
WHERE '+ @PARAMETRE+' ORDER BY MAIN.KODU,MAIN.TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_PERSONELBAKIYERAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[MBL_PERSONELBAKIYERAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT
KODU,
UNVANI,
SUM(BORC) AS BORC,
SUM(ALACAK) AS ALACAK,
(SUM(BORC)-SUM(ALACAK)) AS BAKIYE,
(SUM([DOVIZLIBORC])) AS [DOVIZLIBORC],
(SUM([DOVIZLIALACAK])) AS [DOVIZLIALACAK],
(SUM([DOVIZLIBORC])-SUM([DOVIZLIALACAK])) AS [DOVIZBAKIYE],
DURUM=(CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN ''BORÇLU''
 WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN ''ALACAKLI''
 ELSE ''BAKİYESİZ'' END) 
FROM (
SELECT MUH_HESAPISL.FISID,
MUH_HESAPISL.HESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.BORC AS BORC,
MUH_HESAPISL.ALACAK AS ALACAK,
MUH_HESAPISL.DBORC AS [DOVIZLIBORC],
MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK] 
from  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=335
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+' '+@PARAMETRE+' '+'

UNION ALL

SELECT MUH_HESAPISL.FISID,
MUH_FIS.FISHESAPID,
MUH_HESAP.KODU,
MUH_HESAP.UNVANI,
MUH_HESAPISL.ALACAK as BORÇ,
MUH_HESAPISL.BORC AS ALACAK,
MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],
MUH_HESAPISL.DBORC AS [DOVIZLIALACAK]
from  MUH_HESAPISL WITH (NOLOCK) -- MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=335
AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+' '+@PARAMETRE+' '+'
) AS MAIN
GROUP BY HESAPID,KODU,UNVANI
ORDER BY KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_PERSONELISLEMRAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[MBL_PERSONELISLEMRAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT FISID,QMUH_FISDURUM.FISDURUM AS [FISDURUMU],MAIN.FIRMAID,MAIN.SUBEID,FISNO,TARIH,VADE,FISTURU,BELGETURU,BELGENO,BELGEACIKLAMA,MAIN.ACIKLAMA,HESAPID,MAIN.KODU,UNVANI,
DOVIZ,KUR,TOPLAM,DTOPLAM,TUTAR,DTUTAR,Borc AS BORC,Alacak AS ALACAK,[DOVIZLIBORC],[DOVIZLIALACAK],MIKTAR,BIRIM,BIRIMFIYAT
FROM(

SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.BORC AS Borc,MUH_HESAPISL.ALACAK AS Alacak,MUH_HESAPISL.DBORC AS [DOVIZLIBORC],MUH_HESAPISL.DALACAK AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT

FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFISISL
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
WHERE  (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=335 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+'

UNION ALL

SELECT MUH_HESAPISL.FISID,MUH_FIS.FISDURUMID,MUH_FIS.FIRMAID,MUH_FIS.SUBEID,MUH_FIS.FISNO,MUH_FIS.TARIH,MUH_FIS.VADE,MUH_FIS.FISTURU,MUH_FIS.BELGETURU,MUH_FIS.BELGENO,MUH_FIS.BELGEACIKLAMA,
MUH_FIS.ACIKLAMA,MUH_HESAPISL.HESAPID,MUH_HESAP.KODU,MUH_HESAP.UNVANI,MUH_HESAPISL.DOVIZ,MUH_HESAPISL.KUR,MUH_FIS.TOPLAM,MUH_FIS.DTOPLAM,MUH_HESAPISL.TUTAR,MUH_HESAPISL.DTUTAR,
MUH_HESAPISL.ALACAK AS Borc,MUH_HESAPISL.BORC AS Alacak,MUH_HESAPISL.DALACAK AS [DOVIZLIBORC],MUH_HESAPISL.DBORC AS [DOVIZLIALACAK],MUH_HESAPISL.MIKTAR,MUH_HESAPISL.BIRIM,MUH_HESAPISL.BIRIMFIYAT

FROM  MUH_HESAPISL WITH (NOLOCK)--MUHFIS
INNER JOIN MUH_FIS WITH (NOLOCK) ON MUH_HESAPISL.FISID=MUH_FIS.FISID
INNER JOIN MUH_HESAP WITH (NOLOCK) ON MUH_FIS.FISHESAPID=MUH_HESAP.HESAPID
WHERE (ISNULL(MUH_FIS.SIL,0))=0 AND (ISNULL(MUH_HESAPISL.SILINDI,0))=0 AND MUH_HESAP.HESAPTIPID=335 AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND MUH_HESAP.SUBEID='+@SUBEID+') 
AS MAIN

INNER JOIN QMUH_FISDURUM WITH (NOLOCK) ON MAIN.FISDURUMID=QMUH_FISDURUM.FISDURUMID
WHERE 1=1 '+@PARAMETRE+' ORDER BY MAIN.KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_STOKBAKIYERAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[MBL_STOKBAKIYERAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @TARIH1 NVARCHAR(30), @TARIH2 NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT
FNCQ_STOKBAKIYE.STOKID,STOK.KODU,
MAX(STOKADI) AS STOKADI,
STOK.FIRMAID,GRUPKODU,GRUPADI,
SUM(GCADET) AS KALAN,
STOK.BIRIM,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,MALIYET
FROM FNCQ_STOKBAKIYE('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''')
INNER JOIN STOK WITH (NOLOCK) ON STOK.STOKID=FNCQ_STOKBAKIYE.STOKID
LEFT JOIN SGRUP WITH (NOLOCK) ON STOK.FIRMAID = SGRUP.FIRMAID AND STOK.GRUP = SGRUP.GRUPKODU
WHERE STOK.TURU=''Hammadde'' AND  STOK.FIRMAID='+@FIRMAID+' AND STOK.SUBEID='+@SUBEID+' '+@PARAMETRE+' GROUP BY 
FNCQ_STOKBAKIYE.STOKID,STOK.FIRMAID,GRUPKODU,GRUPADI,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,MALIYET,STOK.KODU,STOK.BIRIM'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_STOKBAKIYERAPORUDEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[MBL_STOKBAKIYERAPORUDEPO]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @TARIH1 NVARCHAR(30), @TARIH2 NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT
FNCQ_STOKBAKIYE.STOKID,
STOK.KODU,
MAX(STOKADI) AS STOKADI,
STOK.FIRMAID,
MAX(SUBEADI) AS SUBEADI,MAX(DEPOADI) AS DEPOADI,
GRUPKODU,
GRUPADI,
SUM(GCADET) AS KALAN,
STOK.BIRIM,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,MALIYET
FROM FNCQ_STOKBAKIYE('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''')
INNER JOIN STOK WITH (NOLOCK) ON STOK.STOKID=FNCQ_STOKBAKIYE.STOKID
LEFT JOIN SGRUP WITH (NOLOCK) ON STOK.FIRMAID = SGRUP.FIRMAID AND STOK.GRUP = SGRUP.GRUPKODU
WHERE  STOK.TURU=''Hammadde'' AND  STOK.FIRMAID='+@FIRMAID+' AND STOK.SUBEID='+@SUBEID+' '+@PARAMETRE+' 
GROUP BY FNCQ_STOKBAKIYE.STOKID,STOK.FIRMAID,DEPOID,FNCQ_STOKBAKIYE.SUBEID,GRUPKODU,GRUPADI,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,MALIYET,STOK.KODU,STOK.BIRIM'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_STOKLISTESI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MBL_STOKLISTESI]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT STOKID,GRUP,GRUPADI,STOK.KODU,ADI,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SDOVIZ,ALISKDV,SATISKDV,
BIRIM,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,BIRIM5,KATSAYI5,BARKOD,BARKOD2,BARKOD3,BARKOD4,BARKOD5,MALIYET,SFIYAT
FROM  STOK WITH (NOLOCK) 
LEFT JOIN SGRUP WITH (NOLOCK) ON STOK.FIRMAID = SGRUP.FIRMAID AND STOK.GRUP = SGRUP.GRUPKODU
WHERE STOK.TURU=''Hammadde'' AND STOK.FIRMAID='+@FIRMAID+' AND STOK.SUBEID='+@SUBEID+' '+@PARAMETRE+' ORDER BY STOK.KODU'



--SELECT STOKID,GRUP,GRUPADI,STOK.KODU,ADI,STOK.FIRMAID,SALISFIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SDOVIZ,ALISKDV,SATISKDV,BIRIM,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,BIRIM5,KATSAYI5,BARKOD,BARKOD2,BARKOD3,
--BARKOD4,BARKOD5,MALIYET,SFIYAT,FATURABIRIMI,MUHALIS.KODU AS [MUHASEBE ALIS HESAP KODU],MUHALIS.ACIKLAMA AS [MUHASEBE ALIS HESAP ACIKLAMA],MUHALISIADE.KODU AS [MUHASEBE ALIS IADE HESAP KODU],
--MUHALISIADE.ACIKLAMA AS [MUHASEBE ALIS IADE HESAP ACIKLAMA],MUHSATIS.KODU AS [MUHASEBE SATIS HESAP KODU],MUHSATIS.ACIKLAMA AS [MUHASEBE SATIS HESAP ACIKLAMA],
--MUHSATISIADE.KODU AS [MUHASEBE SATIS IADE HESAP KODU],MUHSATISIADE.ACIKLAMA AS [MUHASEBE SATIS IADE HESAP ACIKLAMA]
--FROM  STOK WITH (NOLOCK) 
--LEFT JOIN SGRUP WITH (NOLOCK) ON STOK.FIRMAID = SGRUP.FIRMAID AND STOK.GRUP = SGRUP.GRUPKODU
--LEFT JOIN MUH_HESAP AS MUHALIS WITH (NOLOCK) ON SGRUP.MUHALISHESAPID = MUHALIS.HESAPID AND MUHALIS.FIRMAID = SGRUP.FIRMAID 
--LEFT JOIN MUH_HESAP AS MUHSATIS WITH (NOLOCK) ON SGRUP.MUHSATISHESAPID = MUHSATIS.HESAPID AND MUHSATIS.FIRMAID = SGRUP.FIRMAID
--LEFT JOIN MUH_HESAP AS MUHALISIADE WITH (NOLOCK) ON SGRUP.MUHALISIADEHESAPID = MUHALISIADE.HESAPID AND MUHALISIADE.FIRMAID = SGRUP.FIRMAID 
--LEFT JOIN MUH_HESAP AS MUHSATISIADE WITH (NOLOCK) ON SGRUP.MUHSATISIADEHESAPID = MUHSATISIADE.HESAPID AND MUHSATISIADE.FIRMAID = SGRUP.FIRMAID 
--WHERE STOK.TURU=''Hammadde'' AND STOK.FIRMAID='+@FIRMAID+' AND STOK.SUBEID='+@SUBEID+' '+@PARAMETRE+' ORDER BY STOK.KODU
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MBL_URUNSATISRAPORU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MBL_URUNSATISRAPORU]  @FIRMAID NVARCHAR(20), @SUBEID NVARCHAR(30), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2600)
SET @SQLCUMLE='SELECT TARIH,SB.SUBEADI,
Y.GADI AS KASIYER,G.GADI AS GARSON,
A.TUR,UG.GRUPADI,U.KODU,U.ADI AS URUNADI,
D.KODU AS DEPKODU,D.ADI AS DEPOADI,
SUM(ADET) AS MIKTAR, SUM((ADET*BIRIMFIYAT)/NULLIF(ISNULL(ADET,0),0)) AS BRUTFIYAT,
SUM(ADET*BIRIMFIYAT) AS BRUTTOPLAM, 
SUM((ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0/NULLIF(ISNULL(ADET,0),0)) AS NETFIYAT, 
SUM((ADET*BIRIMFIYAT)*(100-ISNULL(ADS.INDORAN,0))/100.0) AS NETTOPLAM  
FROM ADISYON AS A WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON A.FISCOUNTER=ADS.FISCOUNTER
INNER JOIN STOK AS U WITH (NOLOCK) ON ADS.STOKID=U.STOKID
LEFT JOIN SGRUP AS UG WITH (NOLOCK) ON U.GRUPID=UG.SGRUPID AND U.FIRMAID=UG.FIRMAID
LEFT JOIN DEPART AS D WITH (NOLOCK) ON A.DEPKODU=D.KODU AND A.FIRMAID=D.FIRMAID
LEFT JOIN GARSON AS G WITH (NOLOCK) ON ADS.GARSONKODU=G.GKODU AND G.FIRMAID=A.FIRMAID
LEFT JOIN GARSON AS Y WITH (NOLOCK) ON A.YETKILIKODU=Y.GKODU AND Y.FIRMAID=A.FIRMAID
LEFT JOIN SUBELER AS SB WITH (NOLOCK) ON A.SUBEID=SB.SUBEID AND A.SUBEID=SB.SUBEID
WHERE ISNULL(A.SIL,0)=0 AND A.FIRMAID='+@FIRMAID+' AND A.SUBEID='+@SUBEID+' '+@PARAMETRE+' GROUP BY
TARIH,SUBEADI,Y.GADI,G.GADI,A.TUR,GRUPADI,U.KODU,U.ADI,D.KODU,D.ADI
ORDER BY  MIKTAR DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_ADISYON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_ADISYON]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT FISCOUNTER, MASANO,DEPART.ADI AS DEPARTMAN, ASAATI, KSAATI, ADISYON.TUR,TOPLAM,INDORAN, TOPLAM/100*(100-INDORAN) AS NETTOPLAM,MUSTERIADI,ADISYON.SIL 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART ON ADISYON.DEPID=DEPART.DEPARTMANID 
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+' ORDER BY MASANO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_ADISYON_GARSONOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_ADISYON_GARSONOZET]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT DEPART.ADI AS DEPARTMAN,ADISYON.TUR, GARSON.GADI, SUM(TOPLAM) AS TOPLAM, 
SUM(TOPLAM/100*ISNULL(INDORAN,0)) AS INDTUTAR, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS NETTOPLAM 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART WITH (NOLOCK) ON ADISYON.DEPID=DEPART.DEPARTMANID
INNER JOIN GARSON WITH (NOLOCK) ON ADISYON.GARSONID=GARSON.GARSONID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY DEPART.ADI,ADISYON.TUR,GADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_ADISYON_GRUPSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_ADISYON_GRUPSATIS]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(950)
SET @SQLCUMLE='SELECT 
(CASE WHEN IKRAM=1 THEN ''IKRAM''
	 WHEN IADE=1 THEN ''IADE''
	 WHEN ZAYII=1 THEN ''ZAYII''
	 ELSE ''SATIŞ'' END) AS DURUM,
DEPART.ADI AS DEPARTMAN, SGRUP.GRUPADI, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
INNER JOIN SGRUP  WITH (NOLOCK) ON STOK.GRUPID=SGRUP.SGRUPID 
INNER JOIN DEPART ON ADISYON.DEPID=DEPART.DEPARTMANID
WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY DEPART.ADI,SGRUP.GRUPADI,ADISYON.TUR,ADSSATIR.IKRAM,ADSSATIR.IADE, ADSSATIR.ZAYII
ORDER BY SUM(ADET) DESC, DEPART.ADI, DURUM DESC,ADISYON.TUR DESC,SGRUP.GRUPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_ADISYON_IADEIKRAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_ADISYON_IADEIKRAM]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @SQLCUMLE='SELECT ''İADE'' AS ISLEM, MASANO,SAAT,STOK.ADI AS URUNADI,ADET,TUTAR,GARSON.GADI 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK)  ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER 
INNER JOIN GARSON WITH (NOLOCK)  ON ADSSATIR.GARSONID=GARSON.GARSONID
INNER JOIN STOK WITH (NOLOCK)  ON ADSSATIR.STOKID=STOK.STOKID
WHERE ADSSATIR.ADET<0 AND ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''İKRAM'' AS ISLEM, MASANO,SAAT,STOK.ADI AS URUNADI,ADET,TUTAR,GARSON.GADI 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK)  ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER 
INNER JOIN GARSON WITH (NOLOCK)  ON ADSSATIR.GARSONID=GARSON.GARSONID
INNER JOIN STOK WITH (NOLOCK)  ON ADSSATIR.STOKID=STOK.STOKID
WHERE ADSSATIR.BIRIMFIYAT=0 AND ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_ADISYON_URUNSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_ADISYON_URUNSATIS]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(950)
SET @SQLCUMLE='SELECT 
(CASE WHEN IKRAM=1 THEN ''IKRAM''
	 WHEN IADE=1 THEN ''IADE''
	 WHEN ZAYII=1 THEN ''ZAYII''
	 ELSE ''SATIŞ'' END) AS DURUM,
DEPART.ADI AS DEPARTMAN, ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM,MUSTERIADI AS CARIHESAP  
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID 
AND ADISYON.SUBEID=STOK.SUBEID
INNER JOIN DEPART ON ADISYON.DEPID=DEPART.DEPARTMANID
WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY DEPART.ADI,STOK.ADI,STOK.BIRIM,ADISYON.TUR,ADSSATIR.IKRAM,ADSSATIR.IADE, ADSSATIR.ZAYII,MUSTERIADI
ORDER BY SUM(ADET) DESC,  DEPART.ADI, DURUM DESC,ADISYON.TUR DESC,STOK.ADI '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_FATURASATIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[MOB_FATURASATIR]   @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT STOK.ADI,FADET,FBIRIM,FBFIYAT,FBFIYAT*FADET AS TUTAR,SATIRIND,SATIRIND2 FROM FATISL WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON FATISL.STOKID=STOK.STOKID WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_GUNSONUOZET_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_GUNSONUOZET_MOBIL]  @PARAMETRE NVARCHAR(400)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(3800)
SET @SQLCUMLE='SELECT ''Adisyon Analiz'' as DURUM,''Satış'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''SATIS'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Ödenmez'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''ODENMEZ'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Personel'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''PERSONEL'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Diğer'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''DIGER'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Toplam Ciro'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Açık Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO NOT LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Kapalı Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Oturan Masa'' as ISLEM, COUNT(*) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO NOT LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Hesabı Alınan Masa'' as ISLEM, COUNT(*) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Toplam Masa'' as ISLEM, COUNT(*) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Tahsilat Analiz'' as DURUM,ODEMETURU,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR 
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(ADISYON.SIL,0)=0  AND TUR=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY  ODEMETURU,ODEMETURID
UNION ALL
SELECT ''Kasa Analiz'' AS DURUM, ''Kasadan Ödemeler'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%ÖDEME%'' AND 1=1 '+@PARAMETRE+'
 
UNION ALL
SELECT ''Kasa Analiz'' AS DURUM, ''Kasaya Tahsilatlar'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%TAHSİLAT%'' AND 1=1 '+@PARAMETRE+'
 '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_HESAPBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_HESAPBAKIYE]  @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT MUH_GRUP.GRUPADI AS HESAPGRUBU,HESAPID,HESAPKODU,HESAPADI, SUM(BORC) AS TBORC, SUM(ALACAK) AS TALACAK, 
 SUM(DBORC) AS TDBORC, SUM(DALACAK) AS TDALACAK, 
 SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,''TL'' DOVIZ, 
 SUM(BORC)-SUM(ALACAK) AS BAKIYE, (CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN ''B'' WHEN 
 SUM(BORC)-SUM(ALACAK)<0 THEN ''A'' ELSE '''' END) AS DURUM 
 FROM FNCQ_QMUHMIZAN_FATURA ('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''') 
  AS FNCQ LEFT JOIN MUH_GRUP ON FNCQ.HESAPGRUPID1=MUH_GRUP.GRUPID 
 WHERE HESAPTIPID IN(120,320) AND 1=1 '+@PARAMETRE+'  
 GROUP BY HESAPID,HESAPKODU,HESAPADI,MUH_GRUP.GRUPADI order by HESAPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_HESAPEKSTRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_HESAPEKSTRE]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@IDMI NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @IDMI='EVET'
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY_HESAPID'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
	END
ELSE
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
	END
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		NULL,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_LOGINKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_LOGINKONTROL]   @EMAIL NVARCHAR(100), @SIFRESI NVARCHAR(30)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  * FROM NOVAUSER WITH (NOLOCK) WHERE 1=1 AND ISNULL(SIL,0)=0 
AND  EMAIL='''+@EMAIL+''' AND SIFRESI='''+@SIFRESI+''''
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_GRUPSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_GRUPSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT SGRUP.GRUPKODU, SGRUP.GRUPADI, SUM(FMIKTAR) AS MIKTAR, SUM(FMIKTAR*FBFIYAT) AS BRUTTOPLAM, 
SUM((FMIKTAR*FBFIYAT)/100*(TUKETIMFISISL.INDORAN)) AS INDTUTAR,
SUM((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN)) AS NETTOPLAM
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY SGRUP.GRUPKODU,SGRUP.GRUPADI ORDER BY SUM(FMIKTAR) DESC, SGRUP.GRUPKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_IADE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_IADE]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2800)
SET @SQLCUMLE='SELECT ''İADE'' AS ISLEM, SATISZAMANI, STOK.ADI, FMIKTAR AS MIKTAR, FMIKTAR*FBFIYAT AS TUTAR 
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND FMIKTAR<0 AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''SİL'' AS ISLEM, SATISZAMANI, STOK.ADI, FMIKTAR AS MIKTAR, FMIKTAR*FBFIYAT AS TUTAR 
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=1 AND 1=1 '+@PARAMETRE+'
ORDER BY STOK.ADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_KASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_KASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(SATISODEME.DOVIZ,''TL'') AS DOVIZ  
FROM  SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
WHERE ISNULL(SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY ODEMETURU,ODEMETURID,SATISODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_KASIYERSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_KASIYERSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT SUBELER.SUBEADI, TUKETIMFIS.YETKILI, SUM(TOPLAM) AS TOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, SUM(ACIK) AS ACIK  
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID 
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND  1=1 '+@PARAMETRE+'
GROUP BY SUBELER.SUBEADI,TUKETIMFIS.YETKILI ORDER BY SUBEADI,TUKETIMFIS.YETKILI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_STOKSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_STOKSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT SGRUP.GRUPKODU, SGRUP.GRUPADI, STOK.ADI, SUM(FMIKTAR) AS MIKTAR, SUM(FMIKTAR*FBFIYAT) AS BRUTTOPLAM, 
SUM((FMIKTAR*FBFIYAT)/100*(TUKETIMFISISL.INDORAN)) AS INDTUTAR,
SUM((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN)) AS NETTOPLAM
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY STOK.ADI,SGRUP.GRUPKODU,SGRUP.GRUPADI ORDER BY SUM(FMIKTAR) DESC, SGRUP.GRUPKODU'
EXEC (@SQLCUMLE)
end
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKET_SUBESATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKET_SUBESATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT SUBELER.SUBEADI, SUM(TOPLAM) AS TOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, SUM(ACIK) AS ACIK  
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID 
WHERE ISNULL(TUKETIMFIS.SIL,0)=0  and 1=1 '+@PARAMETRE+'
GROUP BY SUBELER.SUBEADI ORDER BY SUBELER.SUBEADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_MARKETKASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_MARKETKASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(SATISODEME.DOVIZ,''TL'') AS DOVIZ  
FROM  SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
WHERE ISNULL(SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID,SATISODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_POSKASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_POSKASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(ADSODEME.DOVIZ,''TL'') AS DOVIZ  
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(SIL,0)=0 AND TUR=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY ODEMETURU,ODEMETURID,ADSODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_POSSAATSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_POSSAATSATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT CONVERT(NVARCHAR(2), SIPARISSAATI, 108) AS SAAT,SUM(ADET) AS ADET ,SUM(ADET*BIRIMFIYAT) AS BRUTFIYAT,SUM(ADET*NETFIYAT) AS NFIYAT, SUM(INDTUTAR) AS INDIRIM,
COUNT(*) AS MASA FROM  FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE+' GROUP BY CONVERT(NVARCHAR(2), SIPARISSAATI, 108) ORDER BY CONVERT(NVARCHAR(2), SIPARISSAATI, 108),SUM(ADET) DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_POSSAATSATIS_URUN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_POSSAATSATIS_URUN]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT CONVERT(NVARCHAR(2), SIPARISSAATI, 108) AS SAAT, URUNADI,SUM(ADET) AS ADET ,SUM(ADET*BIRIMFIYAT) AS BRUTFIYAT,SUM(ADET*NETFIYAT) AS NFIYAT, SUM(INDTUTAR) AS INDIRIM,
COUNT(*) AS MASA FROM  FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE+' GROUP BY CONVERT(NVARCHAR(2), SIPARISSAATI, 108),URUNADI ORDER BY CONVERT(NVARCHAR(2), SIPARISSAATI, 108), SUM(ADET) DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_STOKALIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_STOKALIS]   @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TARIH,FATID,FATNO,UNVANI,TOPLAM,KDV,GTOPLAM FROM FATURA WHERE ISNULL(SIL,0)=0 AND FISDURUMID>=0  AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_STOKBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[MOB_STOKBAKIYE]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT STOKID,STOKADI,BIRIM,RENKADI,BEDEN,SUM(GCADET) AS KALAN  
FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') AS Q 
LEFT JOIN RENKLER ON Q.RENKID=RENKLER.RENKLERID AND RENKLER.FIRMAID='+@FIRMAID+' LEFT JOIN BEDENLER ON Q.BEDENID=BEDENLER.BEDENLERID 
AND BEDENLER.FIRMAID='+@FIRMAID+' WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID,STOKADI,BIRIM,RENKADI,BEDEN'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOB_STOKSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[MOB_STOKSATIS]   @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TARIH,FATID,FATNO,UNVANI,TOPLAM,KDV,GTOPLAM FROM FATURA WHERE ISNULL(SIL,0)=0 AND FISDURUMID>=0  AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_BARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_BARKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BARKOD WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_BARKOD_GETIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_BARKOD_GETIR]
@FIRMAID INT,
@SUBEID INT,
@ADD_USERID INT
AS
BEGIN
  SET NOCOUNT ON;
  
  DECLARE @SONBARKOD NVARCHAR(30)
  DECLARE @YENIBARKOD NVARCHAR(30)
  DECLARE @SAYI BIGINT
  
  -- Son barkodu oku
  SELECT @SONBARKOD = BARKOD FROM FIRMABARKOD 
  WHERE FIRMAID=@FIRMAID AND TUR='STOK' AND ISNULL(SIL,0)=0
  
  -- Sayisal degere cevir ve 1 artir
  SET @SAYI = CAST(@SONBARKOD AS BIGINT) + 1
  SET @YENIBARKOD = CAST(@SAYI AS NVARCHAR(30))
  
  -- Guncelle
  UPDATE FIRMABARKOD SET BARKOD=@YENIBARKOD, EDIT_DATE=GETDATE(), EDIT_USERID=@ADD_USERID
  WHERE FIRMAID=@FIRMAID AND TUR='STOK' AND ISNULL(SIL,0)=0
  
  -- Yeni barkodu dondur
  SELECT @YENIBARKOD AS BARKOD
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_BARKODADET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE   PROCEDURE [dbo].[MOBIL_BARKODADET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BARKODADET WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_BARKODEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_BARKODEKLE]  @MIKTAR INT, @STOKID INT, @RENKID INT, @BEDENID INT, @SUBEID INT, @DEPOID INT, @FIRMAID INT, @BARKOD NVARCHAR(30),@ACIKLAMA NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE @SAYAC INT=1
	if (ISNULL(@BEDENID,0)<=0) AND (@DEPOID<0) DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	IF @BARKOD=''
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM,SACIKLAMA) 
					SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,BARKOD,SFIYAT1,BIRIM,@ACIKLAMA FROM STOK WITH (NOLOCK) WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
	ELSE
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM,SACIKLAMA) 
					SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,@BARKOD,SFIYAT1,BIRIM,@ACIKLAMA FROM STOK WITH (NOLOCK) WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_BEDENLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_BEDENLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BEDENLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE   PROCEDURE [dbo].[MOBIL_FATISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATISLEEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-- =============================================
-- MOBIL_FATISLEEKLE: Fatura satırı ekler
-- =============================================
CREATE   PROCEDURE [dbo].[MOBIL_FATISLEEKLE]
  @FATID      INT,
  @STOKID     INT,
  @HESAPID    INT,            -- Hizmet satırı için hesap (stok satırında NULL)
  @BARKOD     NVARCHAR(30),
  @ADET       FLOAT,
  @BFIYAT     FLOAT,
  @KDV        FLOAT,          -- KDV oranı (%)
  @FBIRIM     NVARCHAR(50),
  @SATIRIND   FLOAT,          -- Satır indirimi (%)
  @ACIKLAMA   NVARCHAR(200),
  @FATFIRMAID INT
AS
BEGIN
  SET NOCOUNT ON
  DECLARE @ARATOPLAM  FLOAT = @ADET * @BFIYAT
  DECLARE @INDTUTAR   FLOAT = @ARATOPLAM * ISNULL(@SATIRIND,0) / 100
  DECLARE @TOPLAMIND  FLOAT = @ARATOPLAM - @INDTUTAR
  DECLARE @KDVTUTAR   FLOAT = @TOPLAMIND * ISNULL(@KDV,0) / 100
  DECLARE @TOPLAM     FLOAT = @TOPLAMIND + @KDVTUTAR

  INSERT INTO FATISL (
    FATID, STOKID, HESAPID, BARKOD,
    ADET, BFIYAT, FBFIYAT, FADET, FBIRIM,
    KDV, SATIRIND,
    ARATOPLAM, FBTOPLAM, TOPLAM,
    ACIKLAMA, FATFIRMAID
  ) VALUES (
    @FATID,
    NULLIF(@STOKID, 0),
    NULLIF(@HESAPID, 0),
    @BARKOD,
    @ADET, @BFIYAT, @BFIYAT, @ADET, ISNULL(@FBIRIM,'ADET'),
    ISNULL(@KDV,0), ISNULL(@SATIRIND,0),
    @ARATOPLAM, @TOPLAMIND, @TOPLAM,
    @ACIKLAMA, @FATFIRMAID
  )
  SELECT SCOPE_IDENTITY() AS FATISLID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO










CREATE   PROCEDURE [dbo].[MOBIL_FATURA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'FATID','FATURA.FATID')
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATURA.*,EFATNO,EFATTURU,EDEVLETDURUM,EFATURADURUM 
FROM FATURA WITH (NOLOCK) LEFT OUTER JOIN FATURADETAY WITH (NOLOCK) ON FATURA.FATID=FATURADETAY.FATID 
WHERE FISDURUMID IN(0,1,-2) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATURADETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE   PROCEDURE [dbo].[MOBIL_FATURADETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATURADETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATURAEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-- =============================================
-- MOBIL_FATURAEKLE: Fatura başlığı ekler, FATID döner
-- =============================================
CREATE   PROCEDURE [dbo].[MOBIL_FATURAEKLE]
  @FIRMAID    INT,
  @SUBEID     INT,
  @DEPOID     INT,
  @TUR        INT,            -- 1=Alış, -1=Satış
  @FISTURID   INT,
  @FISTURADI  NVARCHAR(30),
  @FISHESAPID INT,
  @UNVANI     NVARCHAR(200),
  @ADRES1     NVARCHAR(200),
  @ADRES2     NVARCHAR(200),
  @VD         NVARCHAR(100),
  @VDNO       NVARCHAR(50),
  @FATNO      NVARCHAR(20),
  @TARIH      DATETIME,
  @VADE       DATETIME,
  @ACIKLAMA   NVARCHAR(100),
  @DOVIZ      NVARCHAR(5),
  @KUR        FLOAT,
  @TOPLAM     FLOAT,          -- KDV hariç
  @KDV        FLOAT,          -- KDV tutarı
  @GTOPLAM    FLOAT,          -- KDV dahil
  @ADD_USERID INT
AS
BEGIN
  SET NOCOUNT ON
  INSERT INTO FATURA (
    FIRMAID, SUBEID, DEPOID, TUR,
    FISTURID, FISTURADI,
    FISHESAPID, HESAPID,
    UNVANI, ADRES1, ADRES2, VD, VDNO,
    FATNO, TARIH, VADE, ACIKLAMA,
    DOVIZ, KUR,
    TOPLAM, KDV, GTOPLAM, DTOPLAM,
    FISDURUMID, ADD_USERID, ADD_DATE
  ) VALUES (
    @FIRMAID, @SUBEID, @DEPOID, @TUR,
    @FISTURID, @FISTURADI,
    @FISHESAPID, @FISHESAPID,
    @UNVANI, @ADRES1, @ADRES2, @VD, @VDNO,
    @FATNO, @TARIH, @VADE, @ACIKLAMA,
    ISNULL(@DOVIZ,'TL'), ISNULL(@KUR,1),
    ISNULL(@TOPLAM,0), ISNULL(@KDV,0), ISNULL(@GTOPLAM,0),
    ISNULL(@TOPLAM,0) * ISNULL(@KUR,1),
    0, @ADD_USERID, GETDATE()
  )
  SELECT SCOPE_IDENTITY() AS FATID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FATURAVERGI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_FATURAVERGI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATURAVERGI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FIS_EKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_FIS_EKLE]
@FIRMAID INT,
@SUBEID INT,
@HESAPID INT,
@FISHESAPID INT,
@FISTURID INT,
@FISTURU NVARCHAR(50),
@TARIH NVARCHAR(10),
@BELGENO NVARCHAR(50),
@ACIKLAMA NVARCHAR(200),
@DOVIZ NVARCHAR(10),
@KUR DECIMAL(18,4),
@TUTAR DECIMAL(18,2),
@DTUTAR DECIMAL(18,2),
@ADD_USERID INT
AS
BEGIN
  SET NOCOUNT ON;
  
  DECLARE @FISNO NVARCHAR(20)
  DECLARE @FISID INT
  DECLARE @BUGUN NVARCHAR(8)
  DECLARE @SIRA INT
  DECLARE @ALANTIPI NVARCHAR(10)
  
  -- FISNO Olustur
  SET @BUGUN = FORMAT(GETDATE(), 'ddMMyy')
  SELECT @SIRA = ISNULL(MAX(CAST(RIGHT(FISNO, 3) AS INT)), 0) + 1
  FROM MUH_FIS WITH (NOLOCK)
  WHERE FIRMAID = @FIRMAID AND FISNO LIKE @BUGUN + '%'
  SET @FISNO = @BUGUN + RIGHT('000' + CAST(@SIRA AS NVARCHAR(3)), 3)

  -- FISTURID e gore alan tipi belirle
  IF @FISTURID IN (1, 3, 6)
    SET @ALANTIPI = 'ALACAK'
  ELSE
    SET @ALANTIPI = 'BORC'

  -- MUH_FIS INSERT
  INSERT INTO MUH_FIS (
    FIRMAID, SUBEID, FISHESAPID, FISTURID, FISTURU,
    TARIH, VADE, FISNO, ACIKLAMA, BELGENO,
    DOVIZ, KUR, TOPLAM, DTOPLAM,
    FISDURUMID, DETAYLIENTEGRE, MODULID, MODULEKRANID, OZELKOD3,
    SIL, ADD_DATE, ADD_USERID
  )
  VALUES (
    @FIRMAID, @SUBEID, @FISHESAPID, @FISTURID, @FISTURU,
    @TARIH, @TARIH, @FISNO, @ACIKLAMA, @BELGENO,
    @DOVIZ, @KUR, @TUTAR, @DTUTAR,
    0, 1, 1, -1, 'HISLEM',
    0, GETDATE(), @ADD_USERID
  )

  SET @FISID = SCOPE_IDENTITY()

  -- MUH_HESAPISL INSERT
  IF @ALANTIPI = 'ALACAK'
  BEGIN
    INSERT INTO MUH_HESAPISL (
      FISID, HESAPID, ACIKLAMA,
      DOVIZ, KUR, TUTAR, DTUTAR,
      BORC, ALACAK, DBORC, DALACAK
    )
    VALUES (
      @FISID, @HESAPID, @ACIKLAMA,
      @DOVIZ, @KUR, @TUTAR, @DTUTAR,
      0, @TUTAR, 0, @DTUTAR
    )
  END
  ELSE
  BEGIN
    INSERT INTO MUH_HESAPISL (
      FISID, HESAPID, ACIKLAMA,
      DOVIZ, KUR, TUTAR, DTUTAR,
      BORC, ALACAK, DBORC, DALACAK
    )
    VALUES (
      @FISID, @HESAPID, @ACIKLAMA,
      @DOVIZ, @KUR, @TUTAR, @DTUTAR,
      @TUTAR, 0, @DTUTAR, 0
    )
  END

  SELECT @FISID AS FISID, @FISNO AS FISNO, 'OK' AS SONUC
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FIS_GETFISNO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_FIS_GETFISNO]
@FIRMAID NVARCHAR(10),
@SUBEID NVARCHAR(10)
AS
BEGIN
  DECLARE @BUGUN NVARCHAR(8)
  DECLARE @SIRA INT
  DECLARE @FISNO NVARCHAR(20)
  
  SET @BUGUN = FORMAT(GETDATE(), 'ddMMyy')
  
  SELECT @SIRA = ISNULL(MAX(CAST(RIGHT(FISNO, 3) AS INT)), 0) + 1
  FROM MUH_FIS WITH (NOLOCK)
  WHERE FIRMAID = @FIRMAID 
  AND FISNO LIKE @BUGUN + '%'
  
  SET @FISNO = @BUGUN + RIGHT('000' + CAST(@SIRA AS NVARCHAR(3)), 3)
  
  SELECT @FISNO AS FISNO
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_FISTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_FISTUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_GELIRGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE   PROCEDURE [dbo].[MOBIL_GELIRGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM GELIRGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_HESAPBAKITYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[MOBIL_HESAPBAKITYE]  @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT HESAPKODU, HESAPADI, SUM(BORC)-SUM(ALACAK) AS BAKIYE, (CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN ''B'' WHEN SUM(BORC)-SUM(ALACAK)<0 THEN ''A'' ELSE '''' END) AS BA 
 FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
 GROUP BY HESAPKODU, HESAPADI
 ORDER BY HESAPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_HESAPBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_HESAPBAKIYE] 
  @TARIH1 NVARCHAR(10), 
  @TARIH2 NVARCHAR(10), 
  @FIRMAID NVARCHAR(10), 
  @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT MUH_HESAP.HESAPID, MUH_HESAP.KODU, MUH_HESAP.ACIKLAMA AS UNVANI, MUH_HESAP.UNVANI AS UNVANI2, MUH_HESAP.ADRES1, MUH_HESAP.VD, MUH_HESAP.VDNO, MUH_HESAP.GSM, MUH_HESAP.HESAPTIPID, GSM AS CEPTEL, SUM(BORC)-SUM(ALACAK) AS BAKIYE, (CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN ''B'' WHEN SUM(BORC)-SUM(ALACAK)<0 THEN ''A'' ELSE '''' END) AS BA 
 FROM MUH_HESAP LEFT JOIN [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''') AS MIZAN ON MUH_HESAP.HESAPID=MIZAN.HESAPID WHERE 1=1 '+@PARAMETRE+'
 GROUP BY MUH_HESAP.HESAPID, MUH_HESAP.KODU, MUH_HESAP.ACIKLAMA, MUH_HESAP.UNVANI, MUH_HESAP.ADRES1, MUH_HESAP.VD, MUH_HESAP.VDNO, MUH_HESAP.GSM, MUH_HESAP.HESAPTIPID, GSM
 ORDER BY MUH_HESAP.ACIKLAMA'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_HESAPHAREKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_HESAPHAREKET]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@HESAPID NVARCHAR(20),
@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@HESAPID+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		NULL,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@HESAPID+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@HESAPID+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_HESAPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_HESAPTIP]
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT HESAPTIPID,HESAPTIPADI FROM QMUH_HESAPTIP WITH (NOLOCK) WHERE 1=1 '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_LKMUH_HESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_LKMUH_HESAP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,TEL1,GSM,SUBEID,HESAPID,KODU,ACIKLAMA, KODU+'' : ''+ACIKLAMA AS KODUADI, DOVIZ,UCHESAP,HESAPTIPID,UNVANI,ADRES1,ADRES2,VD,VDNO,
SEHIR,ILCE,PKODU,EMAIL,STDISLEMGRUBU1,ANLASMAOKU,VADEGUN,SORUNSEBEBI,KAMU,ALTCARIKULLANIR,SOZLESMESIVAR,
ISLEMGRUPID1ZORUNLU,OZELKODIDZORUNLU,PROJEZORUNLU,MMZORUNLU,ENG_HESAPADI,RUS_HESAPADI,STDISLEMGRUBU2,MASMERID
FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_LKSTOK_FATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO









CREATE   PROCEDURE [dbo].[MOBIL_LKSTOK_FATURA]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,RECETEBIRIMI,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SFIYAT1KDV,TURU FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_MARKETKUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_MARKETKUR]   @FIRMAID INT
AS
BEGIN
	SELECT (SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='EURO' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS EURO,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='USD' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS USD,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='GBP' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS GBP,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='RUB' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS RUB,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='TL'  AND  TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS TL
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_MUHDONEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_MUHDONEM] @FIRMAID INT
AS
SELECT TOP 1 FIRMAID,SUBEID,DONEMBASI,DONEMSONU,KAPANDI FROM MUHDONEM WHERE ISNULL(KAPANDI,0)=0 AND ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_GRUPSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_GRUPSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT SGRUP.GRUPKODU, SGRUP.GRUPADI, SUM(FMIKTAR) AS MIKTAR, SUM(FMIKTAR*FBFIYAT) AS BRUTTOPLAM,
SUM((FMIKTAR*FBFIYAT)/100*(TUKETIMFISISL.INDORAN)) AS INDTUTAR,
SUM((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN)) AS NETTOPLAM
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY SGRUP.GRUPKODU,SGRUP.GRUPADI ORDER BY SUM(FMIKTAR) DESC, SGRUP.GRUPKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_IADE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_IADE]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2800)
SET @SQLCUMLE='SELECT ''İADE'' AS ISLEM, SATISZAMANI, STOK.ADI, FMIKTAR AS MIKTAR, FMIKTAR*FBFIYAT AS TUTAR 
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND FMIKTAR<0 AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''SİL'' AS ISLEM, SATISZAMANI, STOK.ADI, FMIKTAR AS MIKTAR, FMIKTAR*FBFIYAT AS TUTAR 
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=1 AND 1=1 '+@PARAMETRE+'
ORDER BY STOK.ADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_KASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_KASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(SATISODEME.DOVIZ,''TL'') AS DOVIZ
FROM  SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
WHERE ISNULL(SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY ODEMETURU,ODEMETURID,SATISODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_KASIYERSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- 2026-07-11 NovaBulut revizyonu: YETKILI'si boş fişler raporda "Belirsiz" görünüyordu —
-- boş YETKILI, USERID üzerinden NOVAUSER.KODU ile çözülür (o da yoksa boş kalır).
CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_KASIYERSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT SUBELER.SUBEADI, ISNULL(NULLIF(LTRIM(RTRIM(TUKETIMFIS.YETKILI)),''''),ISNULL(NU.KODU,'''')) AS YETKILI, SUM(TOPLAM) AS TOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, SUM(ACIK) AS ACIK
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
LEFT JOIN NOVAUSER NU WITH (NOLOCK) ON NU.NOVAUSERID=TUKETIMFIS.USERID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND  1=1 '+@PARAMETRE+'
GROUP BY SUBELER.SUBEADI, ISNULL(NULLIF(LTRIM(RTRIM(TUKETIMFIS.YETKILI)),''''),ISNULL(NU.KODU,''''))
ORDER BY SUBEADI, 2'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_STOKSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_STOKSATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT SGRUP.GRUPKODU, SGRUP.GRUPADI, STOK.ADI, SUM(FMIKTAR) AS MIKTAR, SUM(FMIKTAR*FBFIYAT) AS BRUTTOPLAM,
SUM((FMIKTAR*FBFIYAT)/100*(TUKETIMFISISL.INDORAN)) AS INDTUTAR,
SUM((FMIKTAR*FBFIYAT)/100*(100-TUKETIMFISISL.INDORAN)) AS NETTOPLAM
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID
INNER JOIN STOK WITH (NOLOCK)  ON TUKETIMFISISL.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK)  ON STOK.GRUPID=SGRUP.SGRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISNULL(TUKETIMFISISL.SILINDI,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY STOK.ADI,SGRUP.GRUPKODU,SGRUP.GRUPADI ORDER BY SUM(FMIKTAR) DESC, SGRUP.GRUPKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKET_SUBESATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKET_SUBESATIS]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT SUBELER.SUBEADI, SUM(TOPLAM) AS TOPLAM, SUM(NAKIT) AS NAKIT, SUM(KKARTI) AS KKARTI, SUM(ACIK) AS ACIK
FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 and 1=1 '+@PARAMETRE+'
GROUP BY SUBELER.SUBEADI ORDER BY SUBELER.SUBEADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RAPOR_MARKETKASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_RAPOR_MARKETKASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(SATISODEME.DOVIZ,''TL'') AS DOVIZ  
FROM  SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
WHERE ISNULL(SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID,SATISODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_RENKLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_RENKLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RENKLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SATISKAYDET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-- ============================================================
-- MOBIL_SATISKAYDET
-- Satışı tek transaction'da kaydeder:
--   1) TUKETIMFIS header
--   2) TUKETIMFISISL satırlar (JSON)
--   3) SATISODEME ödeme kaydı
-- Geriye yeni DEPOFISID döner.
--
-- @ISLEMTIPI: 1=Nakit  2=Kredi Kartı  3=Açık Hesap
-- @SATIRLAR : JSON array — her eleman bir satır
-- ============================================================
CREATE   PROCEDURE [dbo].[MOBIL_SATISKAYDET]
  @FIRMAID    INT,
  @SUBEID     INT,
  @USERID     INT,
  @YETKILI    NVARCHAR(15),
  @DEPOID     INT,
  @TOPLAM     FLOAT,        -- net toplam (KDV dahil, indirim sonrası) = sum(TLNETARATOPLAM)
  @KDV        FLOAT,        -- toplam KDV tutarı
  @TTUTAR     FLOAT,        -- brüt toplam (KDV dahil, indirim öncesi) = sum(TLARATOPLAM)
  @ISLEMTIPI  SMALLINT,     -- 1=Nakit  2=Kredi Kartı  3=Açık Hesap
  @CARIID     INT,          -- açık hesap için cari ID (diğerlerinde NULL/0 gönderin)
  @ALINANPARA FLOAT,        -- nakit ödemede alınan para (diğerlerinde 0)
  @DKODU      NVARCHAR(5),  -- döviz kodu ('TL')
  @DKURU      FLOAT,        -- döviz kuru (1)
  @SATIRLAR   NVARCHAR(MAX) -- JSON satır listesi
AS
BEGIN
  SET NOCOUNT ON;
  BEGIN TRANSACTION;
  BEGIN TRY

    DECLARE @DEPOFISID INT;
    DECLARE @ODEMETURU NVARCHAR(20);
    DECLARE @NAKIT     FLOAT = 0;
    DECLARE @KKARTI    FLOAT = 0;
    DECLARE @ACIK      FLOAT = 0;
    DECLARE @PARAUSTU  FLOAT = 0;

    IF @ISLEMTIPI = 1
    BEGIN
      SET @ODEMETURU = 'Nakit';
      SET @NAKIT     = @TTUTAR;
      SET @PARAUSTU  = @ALINANPARA - @TTUTAR;
    END
    ELSE IF @ISLEMTIPI = 2
    BEGIN
      SET @ODEMETURU = 'Kredi Kartı';
      SET @KKARTI    = @TTUTAR;
    END
    ELSE IF @ISLEMTIPI = 3
    BEGIN
      SET @ODEMETURU = 'Açık Hesap';
      SET @ACIK      = @TTUTAR;
    END

    -- 1) TUKETIMFIS header
    INSERT INTO TUKETIMFIS (
      FIRMAID, SUBEID, CSUBEID,
      USERID, YETKILI,
      ISLEM,
      TARIH, SAAT, GERCEKTARIH,
      CDEPOID,
      DKODU, DKURU,
      TOPLAM, KDV, TTUTAR,
      NAKIT, KKARTI, ACIK,
      INDORAN, INDTUTAR,
      CARIID, HESAPID,
      ONAY,
      ADD_DATE, ADD_USERID,
      SIL
    )
    VALUES (
      @FIRMAID, @SUBEID, @SUBEID,
      @USERID, @YETKILI,
      'SATIS',
      CAST(GETDATE() AS DATE), CONVERT(TIME, GETDATE()), GETDATE(),
      @DEPOID,
      @DKODU, @DKURU,
      @TOPLAM, @KDV, @TTUTAR,
      @NAKIT, @KKARTI, @ACIK,
      0, 0,
      CASE WHEN @ISLEMTIPI = 3 THEN @CARIID ELSE NULL END,
      CASE WHEN @ISLEMTIPI = 3 THEN @CARIID ELSE NULL END,
      1,
      GETDATE(), @USERID,
      0
    );

    SET @DEPOFISID = SCOPE_IDENTITY();

    -- 2) TUKETIMFISISL satırlar (JSON)
    INSERT INTO TUKETIMFISISL (
      DEPOFISID, STOKID, ACIKLAMA, BARKOD,
      FBIRIM, MIKTAR, FMIKTAR,
      BFIYAT, FBFIYAT,
      INDORAN, KDVORAN, KDV,
      BMALIYET, FBMALIYET,
      DKURU, DTURU,
      RENKID, BEDENID,
      SATISZAMANI, SILINDI
    )
    SELECT
      @DEPOFISID,
      STOKID, ACIKLAMA, BARKOD,
      FBIRIM, MIKTAR, FMIKTAR,
      BFIYAT, FBFIYAT,
      ISNULL(INDORAN, 0),
      ISNULL(KDVORAN, 0),
      -- KDV tutarı: (netfiyat * miktar) * kdvoran / 100
      ROUND(
        (FBFIYAT * FMIKTAR * (1.0 - ISNULL(INDORAN, 0) / 100.0))
        * ISNULL(KDVORAN, 0) / 100.0
      , 4),
      ISNULL(BMALIYET, 0),
      ISNULL(FBMALIYET, 0),
      -- 2026-07-15: satır JSON'undaki dturu/dkuru satıra işlenir (yoksa fiş başlığı).
      -- BFIYAT/FBFIYAT HER ZAMAN TL'dir; DTURU/DKURU yalnız BİLGİ (döviz rozeti) taşır.
      ISNULL(NULLIF(J_DKURU, 0), @DKURU),
      ISNULL(NULLIF(J_DTURU, ''), @DKODU),
      ISNULL(RENKID, -1),
      ISNULL(BEDENID, -1),
      GETDATE(), 0
    FROM OPENJSON(@SATIRLAR) WITH (
      STOKID    INT           '$.stokid',
      ACIKLAMA  NVARCHAR(200) '$.aciklama',
      BARKOD    NVARCHAR(30)  '$.barkod',
      FBIRIM    NVARCHAR(50)  '$.fbirim',
      MIKTAR    FLOAT         '$.miktar',
      FMIKTAR   FLOAT         '$.fmiktar',
      BFIYAT    FLOAT         '$.bfiyat',
      FBFIYAT   FLOAT         '$.fbfiyat',
      INDORAN   FLOAT         '$.indoran',
      KDVORAN   FLOAT         '$.kdvoran',
      BMALIYET  FLOAT         '$.bmaliyet',
      FBMALIYET FLOAT         '$.fbmaliyet',
      J_DKURU   FLOAT         '$.dkuru',
      J_DTURU   NVARCHAR(5)   '$.dturu',
      RENKID    INT           '$.renkid',
      BEDENID   INT           '$.bedenid'
    );

    -- 3) SATISODEME
    INSERT INTO SATISODEME (
      DEPOFISID, ODEMETURID, ODEMETURU,
      TUTAR, KUR, DOVIZ,
      ALINANPARA, PARAUSTU,
      KASIYER, CARIID,
      ZAMAN, ACIKLAMA,
      YETKILIID, ISLEMTIPI
    )
    VALUES (
      @DEPOFISID, @ISLEMTIPI, @ODEMETURU,
      @TTUTAR, 1, 'TL',
      CASE WHEN @ISLEMTIPI = 1 THEN @ALINANPARA ELSE @TTUTAR END,
      CASE WHEN @ISLEMTIPI = 1 THEN @PARAUSTU    ELSE 0      END,
      @YETKILI,
      CASE WHEN @ISLEMTIPI = 3 THEN @CARIID ELSE NULL END,
      GETDATE(), 'Tahsilat',
      @USERID, @ISLEMTIPI
    );

    COMMIT TRANSACTION;
    SELECT @DEPOFISID AS DEPOFISID;

  END TRY
  BEGIN CATCH
    ROLLBACK TRANSACTION;
    THROW;
  END CATCH
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SATISODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_SATISODEME]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(950)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SATISODEME WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SATISSTOKARAMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- ============================================================
-- MOBIL_SATISSTOKARAMA
-- Stok adı, kodu veya barkod ile metin araması (TOP 50)
-- ============================================================
CREATE   PROCEDURE [dbo].[MOBIL_SATISSTOKARAMA]
  @FIRMAID INT,
  @ARAMA   NVARCHAR(100)
AS
BEGIN
  SET NOCOUNT ON;
  SELECT TOP 50
    S.STOKID,
    S.KODU                          AS SKODU,
    S.ADI                           AS STOKADI,
    ISNULL(S.BARKOD, '')            AS BARKOD,
    ISNULL(S.SFIYAT1, 0)            AS FIYAT,
    ISNULL(S.SATISKDV, 0)           AS SATISKDV,
    ISNULL(S.ALISKDV, 0)            AS ALISKDV,
    ISNULL(S.BIRIM, '')             AS BIRIM,
    ISNULL(S.MALIYET, 0)            AS MALIYET,
    ISNULL(S.SDOVIZ1, 'TL')         AS SDOVIZ1,
    ISNULL(S.SFIYAT1KDV, 0)         AS SFIYAT1KDV,
    ISNULL(S.SALISFIYAT, S.SFIYAT1) AS SALISFBFIYAT
  FROM STOK AS S WITH (NOLOCK)
  WHERE S.FIRMAID = @FIRMAID
    AND ISNULL(S.KKALDIR, 0) = 0
    AND ISNULL(S.SIL, 0) = 0
    AND (
      S.ADI    LIKE '%' + @ARAMA + '%'
      OR S.BARKOD LIKE '%' + @ARAMA + '%'
      OR S.KODU   LIKE '%' + @ARAMA + '%'
      -- EK BARKODLAR: bir stokta birden cok barkod olabilir (BARKOD detay tablosu);
      -- yalniz S.BARKOD'a bakmak ek barkodlu urunu kacirir (kullanici, 2026-07-13).
      -- Alt sorgu KORELASYONSUZ (IN): korelasyonlu EXISTS her STOK satiri icin BARKOD
      -- taramasina dusuyordu (donma); IN ile BARKOD bir kez taranir.
      OR S.STOKID IN (SELECT B.STOKID FROM BARKOD B WITH (NOLOCK)
                      WHERE B.FIRMAID = @FIRMAID
                        AND ISNULL(B.SIL, 0) = 0
                        AND B.BARKOD LIKE '%' + @ARAMA + '%')
    )
  ORDER BY S.ADI;
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SBIRIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_SBIRIM]
@FIRMAID INT
AS
BEGIN
  SELECT BIRIM FROM SBIRIM WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0 ORDER BY BIRIM
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_SGRUP]
@FIRMAID INT
AS
BEGIN
  SELECT SGRUPID, GRUPADI FROM SGRUP WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0 ORDER BY GRUPADI
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SIPARIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE   PROCEDURE [dbo].[MOBIL_SIPARIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SIPARIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SIPARISDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE   PROCEDURE [dbo].[MOBIL_SIPARISDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SIPARISDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SIPARISDETAYEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- MOBIL_SIPARISDETAYEKLE: Sipariş satırı ekler
-- =============================================
CREATE   PROCEDURE [dbo].[MOBIL_SIPARISDETAYEKLE]
  @SIPARISID  INT,
  @STOKID     INT,
  @BARKOD     NVARCHAR(30),
  @MIKTAR     FLOAT,
  @BFIYAT     FLOAT,
  @FBIRIM     NVARCHAR(10),
  @ACIKLAMA   NVARCHAR(50),
  @TOPLAM     FLOAT
AS
BEGIN
  SET NOCOUNT ON
  INSERT INTO SIPARISDETAY (
    SIPARISID,
    STOKID, BARKOD,
    MIKTAR, BFIYAT,
    FMIKTAR, FBFIYAT, FBIRIM,
    TOPLAM, ACIKLAMA
  ) VALUES (
    @SIPARISID,
    NULLIF(@STOKID, 0), @BARKOD,
    @MIKTAR, @BFIYAT,
    @MIKTAR, @BFIYAT, ISNULL(@FBIRIM, 'ADET'),
    @TOPLAM, @ACIKLAMA
  )
  SELECT SCOPE_IDENTITY() AS SIPARISDETAYID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SIPARISEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-- =============================================
-- MOBIL_SIPARISEKLE: Sipariş başlığı ekler, SIPARISID döner
-- =============================================
CREATE   PROCEDURE [dbo].[MOBIL_SIPARISEKLE]
  @FIRMAID     INT,
  @SUBEID      INT,
  @DEPOID      INT,
  @HESAPID     INT,
  @TARIH       DATETIME,
  @ACIKLAMA    NVARCHAR(100),
  @SIPARISTURU NVARCHAR(10),
  @TMIKTAR     FLOAT,
  @TTUTAR      FLOAT,
  @ADD_USERID  INT
AS
BEGIN
  SET NOCOUNT ON
  INSERT INTO SIPARIS (
    FIRMAID, SUBEID, DEPOID,
    HESAPID, TARIH, ACIKLAMA,
    SIPARISTURU, TMIKTAR, TTUTAR,
    ADD_DATE, ADD_USERID
  ) VALUES (
    @FIRMAID, @SUBEID, @DEPOID,
    NULLIF(@HESAPID, 0), @TARIH, @ACIKLAMA,
    @SIPARISTURU, ISNULL(@TMIKTAR, 0), ISNULL(@TTUTAR, 0),
    GETDATE(), @ADD_USERID
  )
  SELECT SCOPE_IDENTITY() AS SIPARISID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE   PROCEDURE [dbo].[MOBIL_STOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK WITH (NOLOCK) WHERE TURU=''Hammadde'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOK_DUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- MOBIL_STOK_DUZELT: SFIYAT2 ve SFIYAT3 parametreleri eklendi (geriye donuk uyumlu - varsayilan NULL,
-- gonderilmezse mevcut deger degismez, diger cagiranlari etkilemez)
CREATE   PROCEDURE [dbo].[MOBIL_STOK_DUZELT]
@STOKID INT,
@GRUPID INT,
@BARKOD NVARCHAR(30),
@ADI NVARCHAR(100),
@SFIYAT1 FLOAT,
@BIRIM NVARCHAR(15),
@SDOVIZ1 NVARCHAR(10),
@SFIYAT1KDV BIT,
@ALISKDV FLOAT,
@SATISKDV FLOAT,
@EDIT_USERID INT,
@SFIYAT2 FLOAT = NULL,
@SFIYAT3 FLOAT = NULL
AS
BEGIN
  SET NOCOUNT ON;

  UPDATE STOK SET
    GRUPID = @GRUPID,
    BARKOD = @BARKOD,
    KODU = @BARKOD,
    ADI = @ADI,
    SFIYAT1 = @SFIYAT1,
    SFIYAT2 = ISNULL(@SFIYAT2, SFIYAT2),
    SFIYAT3 = ISNULL(@SFIYAT3, SFIYAT3),
    BIRIM = @BIRIM,
    FATURABIRIMI = @BIRIM,
    SDOVIZ1 = @SDOVIZ1,
    SFIYAT1KDV = @SFIYAT1KDV,
    ALISKDV = @ALISKDV,
    SATISKDV = @SATISKDV,
    EDIT_DATE = GETDATE(),
    EDIT_USERID = @EDIT_USERID
  WHERE STOKID = @STOKID

  SELECT @STOKID AS STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOK_EKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- MOBIL_STOK_EKLE: SFIYAT2 ve SFIYAT3 parametreleri eklendi (varsayilan 0, gonderilmezse eskisi gibi davranir)
CREATE   PROCEDURE [dbo].[MOBIL_STOK_EKLE]
@FIRMAID INT,
@SUBEID INT,
@GRUPID INT,
@BARKOD NVARCHAR(30),
@ADI NVARCHAR(100),
@SFIYAT1 FLOAT,
@BIRIM NVARCHAR(15),
@SDOVIZ1 NVARCHAR(10),
@SFIYAT1KDV BIT,
@ALISKDV FLOAT,
@SATISKDV FLOAT,
@ADD_USERID INT,
@SFIYAT2 FLOAT = 0,
@SFIYAT3 FLOAT = 0
AS
BEGIN
  SET NOCOUNT ON;

  INSERT INTO STOK (
    FIRMAID, SUBEID, GRUPID,
    BARKOD, KODU, ADI,
    SFIYAT1, BIRIM, FATURABIRIMI,
    SDOVIZ1, SDOVIZ2, SDOVIZ3, SDOVIZ4, SDOVIZ5,
    SFIYAT1KDV, SFIYAT2KDV, SFIYAT3KDV, SFIYAT4KDV,
    ALISKDV, SATISKDV,
    KKALDIR, DSATIS, TURU, STOKTURUID,
    OTV, OIV, SFIYAT2, SFIYAT3,
    INDVERILIR, SATISIND,
    SIL, ADD_DATE, ADD_USERID
  )
  VALUES (
    @FIRMAID, @SUBEID, @GRUPID,
    @BARKOD, @BARKOD, @ADI,
    @SFIYAT1, @BIRIM, @BIRIM,
    @SDOVIZ1, 'TL', 'TL', 'TL', 'TL',
    @SFIYAT1KDV, 1, 1, 1,
    @ALISKDV, @SATISKDV,
    0, 1, 'Hammadde', 1,
    0, 0, @SFIYAT2, @SFIYAT3,
    1, 100,
    0, GETDATE(), @ADD_USERID
  )

  SELECT SCOPE_IDENTITY() AS STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOK_FIYAT_ISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_STOK_FIYAT_ISLEM] @FIRMAID INT, @GRUPID INT, @STOKID INT, @KGFIYATI FLOAT, 
@SALISFIYAT FLOAT, @KARORANI FLOAT,@ISLEMTURU NVARCHAR(20),
@ASGARI FLOAT, @OPTIMAL FLOAT, @FIYAT FLOAT, @KDVORAN INT, @BIRIM NVARCHAR(15), @GGRUP NVARCHAR(10)
AS
BEGIN
DECLARE @SAY INT
DECLARE @KDVDAHIL BIT
BEGIN TRANSACTION
BEGIN TRY
IF @ISLEMTURU='GRUPUPDATE'
BEGIN
	UPDATE STOK SET GRUPID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='ANAGRUPUPDATE'
BEGIN
	UPDATE STOK SET STOKGRUPID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='GRUPSIL'
BEGIN
	UPDATE STOK SET GRUPID=NULL, STOKGRUPID=NULL WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='MARKAUPDATE'
BEGIN
	UPDATE STOK SET MARKAID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='KGALISFIYAT'
	BEGIN
		UPDATE STOK SET KGFIYATI=@KGFIYATI, SALISFIYAT=(@KGFIYATI)*AGIRLIK, 
		SALISBFIYAT=(@KGFIYATI)*AGIRLIK, MALIYET=(@KGFIYATI)*AGIRLIK
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KGALISSATISFIYAT'
	BEGIN
		UPDATE STOK SET KGFIYATI=@KGFIYATI, SALISFIYAT=(@KGFIYATI)*AGIRLIK, 
		SALISBFIYAT=(@KGFIYATI)*AGIRLIK, MALIYET=@KGFIYATI*AGIRLIK,
		SFIYAT1=((@KGFIYATI*AGIRLIK)/100)*(100+@KARORANI)
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KGSATIS'
	BEGIN
		UPDATE STOK SET SFIYAT1=((KGFIYATI*AGIRLIK)/100)*(100+@KARORANI)
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND KGFIYATI>0 AND AGIRLIK>0
	END
ELSE IF @ISLEMTURU='ASGARI'
	BEGIN
		UPDATE STOK SET ASGARI=@ASGARI WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='OPTIMAL'
	BEGIN
		UPDATE STOK SET OPTIMAL=@OPTIMAL WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT1'
	BEGIN
		UPDATE STOK SET SFIYAT1=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID	
	END
ELSE IF @ISLEMTURU='SFIYAT2'
	BEGIN
		UPDATE STOK SET SFIYAT2=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT3'
	BEGIN
		UPDATE STOK SET SFIYAT3=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT4'
	BEGIN
		UPDATE STOK SET SFIYAT4=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT5'
	BEGIN
		UPDATE STOK SET SFIYAT5=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END

ELSE IF @ISLEMTURU='SFIYAT1Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT2Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT2=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT2=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT3Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT3=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT3=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT4Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT4=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT4=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT5Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT5=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT5=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END



ELSE IF @ISLEMTURU='SFIYAT1YS'
	BEGIN
		UPDATE STOK SET SFIYAT1=ROUND(((SFIYAT1/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT1>0
	END
ELSE IF @ISLEMTURU='SFIYAT2YS'
	BEGIN
		UPDATE STOK SET SFIYAT2=ROUND(((SFIYAT2/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT2>0
	END
ELSE IF @ISLEMTURU='SFIYAT3YS'
	BEGIN
		UPDATE STOK SET SFIYAT3=ROUND(((SFIYAT3/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT3>0
	END
ELSE IF @ISLEMTURU='SFIYAT4YS'
	BEGIN
		UPDATE STOK SET SFIYAT4=ROUND(((SFIYAT4/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT4>0
	END
ELSE IF @ISLEMTURU='SFIYAT5YS'
	BEGIN
		UPDATE STOK SET SFIYAT5=ROUND(((SFIYAT5/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT5>0
	END
ELSE IF @ISLEMTURU='SIL'
	BEGIN
		UPDATE STOK SET SIL=-2,DEL_USERID=-2 WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KDV'
	BEGIN
		UPDATE STOK SET ALISKDV=@KDVORAN, SATISKDV=@KDVORAN WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='BIRIM'
	BEGIN
		UPDATE STOK SET BIRIM=@BIRIM WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='GGRUP'
	BEGIN
		UPDATE STOK SET GGRUP=@GGRUP WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='ANLASMAYAGORE'
	BEGIN
		SELECT @SAY=COUNT(*) FROM FNCQ_ANLASMAOZET(@FIRMAID) WHERE STOKID=@STOKID AND NETFIYAT>0
		IF @SAY>0
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((NETFIYAT/100)*(100+@KARORANI),2) FROM STOK INNER JOIN  FNCQ_ANLASMAOZET(@FIRMAID) AS ANLASMA ON STOK.STOKID=ANLASMA.STOKID
				WHERE STOK.FIRMAID=@FIRMAID AND  STOK.STOKID=@STOKID AND ANLASMA.STOKID=@STOKID
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND  STOKID=@STOKID
			END
	END	
COMMIT TRANSACTION
END TRY
BEGIN CATCH
RAISERROR('HATA OLUSTUR',16,1)
ROLLBACK TRANSACTION
END CATCH
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOKBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- MOBIL_STOKBAKIYE: SFIYAT2 ve SFIYAT3 sectime/gruplamaya eklendi (sadece ek kolon, parametre degisikligi yok)
CREATE   PROCEDURE [dbo].[MOBIL_STOKBAKIYE]
  @TARIH1 NVARCHAR(10),
  @TARIH2 NVARCHAR(10),
  @FIRMAID NVARCHAR(10),
  @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT STOK.STOKID, STOK.GRUPID, STOK.BARKOD, STOK.ADI, STOK.SFIYAT1, STOK.SFIYAT2, STOK.SFIYAT3, STOK.SFIYAT1KDV, STOK.SDOVIZ1, STOK.BIRIM, STOK.ALISKDV, STOK.SATISKDV, SUM(GCADET) AS BAKIYE
 FROM STOK LEFT JOIN [FNCQ_STOKBAKIYE2] ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''') AS STOKBAKIYE ON STOK.STOKID=STOKBAKIYE.STOKID
 WHERE 1=1 '+@PARAMETRE+'
 GROUP BY STOK.STOKID, STOK.GRUPID, STOK.BARKOD, STOK.ADI, STOK.SFIYAT1, STOK.SFIYAT2, STOK.SFIYAT3, STOK.SFIYAT1KDV, STOK.SDOVIZ1, STOK.BIRIM, STOK.ALISKDV, STOK.SATISKDV'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOKBARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE   PROCEDURE [dbo].[MOBIL_STOKBARKOD]  
@FIRMAID INT,
@BARKOD NVARCHAR(30)
AS
BEGIN
	SELECT ISNULL(B.BARKOD,S.BARKOD) AS BARKOD, PLUNO, S.STOKID AS STOKID, S.GRUPID, S.GRUP AS GRUP, SG.GRUPADI, ISNULL(S.ETERAZI,0) AS ETERAZI, S.KODU AS SKODU, S.ADI AS STOKADI, 
	R.RENKLERID,BD.BEDENLERID, R.RENKADI AS RENK, BD.BEDEN AS BEDEN, S.ALISKDV, S.SATISKDV, S.SERILOTVAR,S.MALIYET, 
	ISNULL(B.BIRIM,S.BIRIM) AS BIRIM, ISNULL(S.FATURABIRIMI,S.BIRIM) AS FATURABIRIMI, 
	S.BIRIM AS ANABIRIM,S.BIRIM2 AS BIRIM2, ISNULL(S.KATSAYI2,1) AS KATSAYI2, S.BIRIM3 AS BIRIM3, S.BIRIM4,S.BIRIM5, ISNULL(S.KATSAYI3,1) AS KATSAYI3, ISNULL(S.KATSAYI4,1) AS KATSAYI4,
	ISNULL(S.KATSAYI5,1) AS KATSAYI5,
	(case WHEN  B.DMIKTAR=NULL OR B.DMIKTAR=0 THEN 1 ELSE ISNULL(B.DMIKTAR,1) END) AS KATSAYI, S.SFIYAT1 AS ANABIRIMFIYAT,   
	CAST((CASE WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM THEN S.SFIYAT1 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM2 THEN S.SFIYAT2 
	WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM3 THEN S.SFIYAT3 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM4 THEN S.SFIYAT4 ELSE ISNULL(B.FIYATI,S.SFIYAT1) END) AS FLOAT) AS FIYAT, 
	S.SFIYAT1, S.SFIYAT2, S.SFIYAT3, S.SFIYAT4,S.SFIYAT5,
	ISNULL(S.SDOVIZ1,'TL') AS SDOVIZ1, ISNULL(S.SDOVIZ2,'TL') AS SDOVIZ2, ISNULL(S.SDOVIZ3,'TL') AS SDOVIZ3, ISNULL(S.SDOVIZ4,'TL') AS SDOVIZ4, ISNULL(S.SDOVIZ5,'TL') AS SDOVIZ5,S.SALISFIYAT AS SALISFBFIYAT,SFIYAT1KDV 
	FROM STOK AS S WITH (NOLOCK) LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON S.STOKID=B.STOKID AND  B.FIRMAID=@FIRMAID   LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID 
	AND SG.FIRMAID=@FIRMAID  
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID 
	WHERE  S.FIRMAID=@FIRMAID AND ISNULL(KKALDIR,0)=0 AND ISNULL(S.SIL,0)=0 AND ISNULL(B.BARKOD,S.BARKOD)=@BARKOD
	/*AND ISNULL(S.DSATIS,0)=1 */
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOKBARKOD_DEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE   PROCEDURE [dbo].[MOBIL_STOKBARKOD_DEPO]  
@FIRMAID INT,
@DEPOID INT,
@BARKOD NVARCHAR(30)
AS
BEGIN
	SELECT ISNULL(B.BARKOD,STOK.BARKOD) AS BARKOD, PLUNO, STOK.STOKID AS STOKID, STOK.GRUP AS GRUP, SG.GRUPADI, ISNULL(STOK.ETERAZI,0) AS ETERAZI, STOK.KODU AS SKODU, STOK.ADI AS STOKADI, 
	R.RENKLERID,BD.BEDENLERID, R.RENKADI AS RENK, BD.BEDEN AS BEDEN, STOK.ALISKDV, STOK.SATISKDV, STOK.SERILOTVAR, STOK.MALIYET, 
	ISNULL(B.BIRIM,STOK.BIRIM) AS BIRIM, ISNULL(STOK.FATURABIRIMI,STOK.BIRIM) AS FATURABIRIMI, 
	STOK.BIRIM AS ANABIRIM,STOK.BIRIM2 AS BIRIM2, ISNULL(STOK.KATSAYI2,1) AS KATSAYI2, STOK.BIRIM3 AS BIRIM3, ISNULL(STOK.KATSAYI3,1) AS KATSAYI3,
	(case WHEN  B.DMIKTAR=NULL OR B.DMIKTAR=0 THEN 1 ELSE ISNULL(B.DMIKTAR,1) END) AS KATSAYI, SUBEFIYAT.SFIYAT1 AS ANABIRIMFIYAT,   
	CAST((CASE WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM THEN SUBEFIYAT.SFIYAT1 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM2 THEN STOK.SFIYAT2 
	WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM3 THEN SUBEFIYAT.SFIYAT3 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM4 THEN SUBEFIYAT.SFIYAT4 ELSE ISNULL(B.FIYATI,SUBEFIYAT.SFIYAT1) END) AS FLOAT) AS FIYAT, 
	SUBEFIYAT.SFIYAT1, SUBEFIYAT.SFIYAT2, SUBEFIYAT.SFIYAT3, SUBEFIYAT.SFIYAT4,SUBEFIYAT.SFIYAT5,
	ISNULL(SUBEFIYAT.DOVIZ1,'TL') AS SDOVIZ1, ISNULL(SUBEFIYAT.DOVIZ2,'TL') AS SDOVIZ2, ISNULL(SUBEFIYAT.DOVIZ3,'TL') AS SDOVIZ3, ISNULL(SUBEFIYAT.DOVIZ4,'TL') AS SDOVIZ4, ISNULL(SUBEFIYAT.DOVIZ5,'TL') AS SDOVIZ5,STOK.SALISFBFIYAT,SFIYAT1KDV 
	FROM SUBEFIYAT WITH (NOLOCK) 
	INNER JOIN STOK WITH (NOLOCK) ON SUBEFIYAT.STOKID=STOK.STOKID AND STOK.FIRMAID=@FIRMAID
	LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON STOK.STOKID=B.STOKID  AND B.FIRMAID=@FIRMAID
	LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID  AND SG.FIRMAID=@FIRMAID 
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID  AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID
	WHERE SUBEFIYAT.FIRMAID=@FIRMAID and SUBEFIYAT.DEPOID=@DEPOID AND  ISNULL(B.BARKOD,STOK.BARKOD)=@BARKOD 
	--AND ISNULL(S.DSATIS,0)=1
	--ISNULL(KKALDIR,0)=0 AND ISNULL(STOK.SIL,0)=0 AND
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_STOKHAREKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_STOKHAREKET] 
  @TARIH1 NVARCHAR(10), 
  @TARIH2 NVARCHAR(10), 
  @FIRMAID NVARCHAR(10), 
  @STOKID NVARCHAR(10), 
  @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TARIH,DEPOADI,ISLEM, GCADET AS MIKTAR,FBFIYAT,FBMALIYET,CARIUNVANI,KDEPOADI 
FROM [FNCQ_STOKDETAY] ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''')  WHERE 1=1 '+@PARAMETRE
 EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_SUBEFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE   PROCEDURE [dbo].[MOBIL_SUBEFIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SUBEFIYAT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUKETIMFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_TUKETIMFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(950)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUKETIMFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUKETIMFISISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_TUKETIMFISISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(950)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUKETIMFISISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUSGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_TUSGRUP]
  @LIMIT     NVARCHAR(10),
  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
  DECLARE @SQLCUMLE NVARCHAR(500)
  SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
  EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUSGRUPISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



    CREATE   PROCEDURE [dbo].[MOBIL_TUSGRUPISLEM]
      @ISLEM NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10),
      @TUSGRUPID NVARCHAR(10), @TUSGRUPADI NVARCHAR(20), @SIRA NVARCHAR(5)
    AS
    DECLARE @YENITUSGRUPID INT
    IF @ISLEM='YENI'
      BEGIN
        INSERT INTO TUSGRUP (FIRMAID,SUBEID,TUSGRUPADI,SIRA,AKTIF) VALUES(@FIRMAID,@SUBEID,@TUSGRUPADI,99,1)
        SET @YENITUSGRUPID=(SELECT SCOPE_IDENTITY() AS TUSGRUPID)
        DECLARE @SAYAC INT=1
        WHILE @SAYAC<=50
          BEGIN
            INSERT INTO TUSSTOK (TUSGRUPID,AKTIF,SIRA) VALUES(@YENITUSGRUPID,1,@SAYAC)
            SET @SAYAC=@SAYAC+1
          END
      END
    ELSE IF @ISLEM='AD'
      BEGIN
        UPDATE TUSGRUP SET TUSGRUPADI=@TUSGRUPADI WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUSGRUPID=@TUSGRUPID
      END
    ELSE IF @ISLEM='SIRA'
      BEGIN
        UPDATE TUSGRUP SET SIRA=@SIRA WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUSGRUPID=@TUSGRUPID
      END
    ELSE IF @ISLEM='SIL'
      BEGIN
        UPDATE TUSGRUP SET SIL=-2 WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUSGRUPID=@TUSGRUPID
      END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUSSTOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_TUSSTOK]
  @LIMIT     NVARCHAR(10),
  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
  DECLARE @SQLCUMLE NVARCHAR(500)
  SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSSTOK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
  EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[MOBIL_TUSSTOKEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE   PROCEDURE [dbo].[MOBIL_TUSSTOKEKLE]
  @MIKTAR    INT,
  @TUSGRUPID INT
AS
SET NOCOUNT ON
BEGIN
  DECLARE @SAYAC INT=1
  WHILE @SAYAC<=@MIKTAR
    BEGIN
      INSERT INTO TUSSTOK (TUSGRUPID,AKTIF,SIRA) VALUES(@TUSGRUPID,1,@SAYAC)
      SET @SAYAC=@SAYAC+1
    END
END
GO
/****** Object:  StoredProcedure [dbo].[PERSONEL_MASRAF_HESAPLAMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROC  [dbo].[PERSONEL_MASRAF_HESAPLAMA](@FIRMAID INT,@YIL INT,@AY INT,@NET DECIMAL(15,4))
As
Begin
DECLARE @Sayac INT=1--@KGVM @SGKMatrah
DECLARE @KGVM  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @SGKMatrah  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @BRUT  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @GVMATRAH  DECIMAL(15,4)=0
DECLARE @KUMULATIF_GV_MATRAHI DECIMAL(15,4)=0

WHILE (@Sayac<=@AY)
BEGIN 

			IF(@SAYAC=1)
			BEGIN
			SELECT @BRUT= [dbo].[Brut](@NET,0.00,0.00,@YIL,@FIRMAID)
			SELECT @GVMATRAH=[dbo].[GV_MATRAH] (@BRUT,@YIL ,@FIRMAID)
		INSERT INTO [dbo].[PERSONEL]
           ([YIL]
           ,[AY]
           ,[NET]
           ,[BRUT]
           ,[GV_MATRAH]
           ,[KUMULATIF_GV_MATRAHI]
		   ,FIRMAID)
			VALUES
           (@YIL
           ,@Sayac
           ,@NET
           ,@BRUT
		   ,@GVMATRAH
           ,0.00
		   ,@FIRMAID)
			END
		IF(@Sayac>1)
		BEGIN
		SELECT @KUMULATIF_GV_MATRAHI=SUM(GV_MATRAH) FROM PERSONEL WHERE YIL=@YIL AND FIRMAID=@FIRMAID
		SELECT @BRUT= [dbo].[Brut](@NET,@KUMULATIF_GV_MATRAHI,0.00,@YIL,@FIRMAID)
	    SELECT @GVMATRAH=[dbo].[GV_MATRAH](@BRUT,@YIL ,@FIRMAID)
		INSERT INTO [dbo].[PERSONEL]
           ([YIL]
           ,[AY]
           ,[NET]
           ,[BRUT]
           ,[GV_MATRAH]
           ,[KUMULATIF_GV_MATRAHI]
		   ,FIRMAID)
			VALUES
           (@YIL
           ,@Sayac
           ,@NET
           ,@BRUT
		   ,@GVMATRAH
           ,@KUMULATIF_GV_MATRAHI
		   ,@FIRMAID)
		END
			SET @Sayac=@Sayac+1
           
        END
END
GO
/****** Object:  StoredProcedure [dbo].[POS_ANLIKMASALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[POS_ANLIKMASALAR]  
@SALON NVARCHAR(5)
AS
BEGIN
	SELECT M.MASAID, M.STATU, M.MASANO, ISNULL(M.KISIS,0) AS KISIS, ISNULL(A.ASAATI,'01.01.2000 12:12:12') AS ASSATI, A.GARSONKODU, 
	ISNULL(A.TARIH,'01.01.2000') AS TARIH, ISNULL(A.KISI,0) AS KISI,
	 CAST(ISNULL(A.TOPLAM,0) AS FLOAT) AS TOPLAM, ISNULL(A.FISCOUNTER,0) AS FISCOUNTER,
	 (CASE WHEN M.STATU=0 THEN 'BOŞ' WHEN M.STATU=1 THEN 'DOLU' WHEN M.STATU=2 THEN 'KİRLİ'
	 WHEN M.STATU=3 THEN 'REZERVE' WHEN M.STATU=4 THEN 'KAPALI' ELSE '' END) AS MASADURUM,
	 ISNULL(A.ACIKLAMA,M.ACIKLAMA) AS ACIKLAMA
	 FROM MASALAR AS M LEFT JOIN (SELECT * FROM ADISYON
	 WHERE ISNULL(SIL,0)=0 AND TARIH=(SELECT MAX(TARIH) FROM PTARIH))
	 AS A ON M.MASANO = A.MASANO AND M.DEPART=A.DEPKODU
	 UNION ALL
	 SELECT 9999 AS MASAID, 1 AS STATU, A.MASANO, ISNULL(A.KISI,0) AS KISIS, ISNULL(A.ASAATI,'01.01.2000 12:12:12') AS ASSATI,
	 A.GARSONKODU, ISNULL(A.TARIH,'01.01.2000') AS TARIH, ISNULL(A.KISI,0) AS KISI,
	 CAST(ISNULL(A.TOPLAM,0) AS FLOAT) AS TOPLAM, ISNULL(A.FISCOUNTER,0) AS FISCOUNTER, 'DOLU' AS MASADURUM, A.ACIKLAMA FROM ADISYON AS A
	 WHERE ISNULL(SIL,0)=0 AND TARIH=(SELECT MAX(TARIH) FROM PTARIH)
	 AND (MASANO NOT LIKE'Z%' AND MASANO NOT IN(SELECT MASANO FROM MASALAR))
END
GO
/****** Object:  StoredProcedure [dbo].[POS_GARSONANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[POS_GARSONANALIZ]  
@ILKTARIH DATETIME,
@SONTARIH DATETIME
AS
BEGIN
	SELECT SATIRGARSONADI AS GARSON, URUNADI, ISNULL(SUM(ADET),0.00) AS MIKTAR, SUM(ISNULL(SATIRGARSONPRIMI,0.00)) AS PRIM, 
	ISNULL(SUM(TOPLAM),0.00) AS TOPLAM, ISNULL(SUM(INDTUTAR),0.00) AS INDIRIM,  ISNULL(SUM(NETTOPLAM),0.00) AS NETTOPLAM FROM QW_ADISYONANALIZ
	WHERE TARIH BETWEEN @ILKTARIH AND @SONTARIH 
	GROUP BY URUNADI,SATIRGARSONADI
END
GO
/****** Object:  StoredProcedure [dbo].[POS_GRUPSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[POS_GRUPSATIS]  
@ILKTARIH DATETIME,
@SONTARIH DATETIME
AS
BEGIN
	SELECT GRUPADI,ISNULL(SUM(ADET),0.00) AS MIKTAR, ISNULL(SUM(TOPLAM),0.00) AS TOPLAM, ISNULL(SUM(INDTUTAR),0.00) AS INDIRIM, ISNULL(SUM(NETTOPLAM),0.00) AS NETTOPLAM  
	FROM QW_ADISYONANALIZ WHERE TARIH BETWEEN @ILKTARIH AND @SONTARIH GROUP BY GRUPADI
END
GO
/****** Object:  StoredProcedure [dbo].[POS_GRUPURUNSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[POS_GRUPURUNSATIS]  
@ILKTARIH DATETIME,
@SONTARIH DATETIME
AS
BEGIN
	SELECT GRUPADI,URUNADI, ISNULL(SUM(ADET),0.00) AS MIKTAR, ISNULL(SUM(TOPLAM),0.00) AS TOPLAM, ISNULL(SUM(INDTUTAR),0.00) AS INDIRIM, ISNULL(SUM(NETTOPLAM),0.00) AS NETTOPLAM  
	FROM QW_ADISYONANALIZ WHERE TARIH BETWEEN @ILKTARIH AND @SONTARIH GROUP BY GRUPADI,URUNADI
END
GO
/****** Object:  StoredProcedure [dbo].[POS_TAHSILAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[POS_TAHSILAT]  
@ILKTARIH DATETIME,
@SONTARIH DATETIME
AS
BEGIN
	SELECT TARIH, TAHSILATTURU, SUM(NETTOPLAM) AS TAHSILAT FROM QW_ADISYONANALIZ
	WHERE TARIH BETWEEN @ILKTARIH AND @SONTARIH 
	GROUP BY TARIH, TAHSILATTURU
END
GO
/****** Object:  StoredProcedure [dbo].[PR_ACENTAENTEGRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ACENTAENTEGRE]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@GELIRHESAPKODU NVARCHAR(20),
@KDVHESAPKODU NVARCHAR(20),
@MUNFERITHESAPKODU NVARCHAR(20),
@SUBEID INT,
@EKLEYEN INT,
@FATURATURU INT,
@TOPLUENTEGRE INT,
@FATID INT
AS
BEGIN
IF @TOPLUENTEGRE=0
	BEGIN	
			IF @FATURATURU=0
				BEGIN
						DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
						DELETE FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		
						INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1,MERKEZIFC)
						VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Acenta Fatura Ent.',1,'TL',1,@TOPLAM,0.00,'ACENTAMAHSUBU',@FATID)

		
						INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
						SELECT @FISID, H.HESAPID AS HESAPID, FATNO+' Nl Acenta Faturası' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.GTOPLAM AS TUTAR,
						F.DGTOPLAM AS DTUTAR,F.KUR AS KUR, 0.00 AS MIKTAR, F.GTOPLAM AS BORC, 0.00 AS ALACAK, F.DGTOPLAM AS DBORC, 0.00 AS DALACAK, F.TOPLAM AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH AND FATID=@FATID
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@GELIRHESAPKODU), FATNO+' Nl Acenta Faturası gelir' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.TOPLAM AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.TOPLAM AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH AND FATID=@FATID
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@KDVHESAPKODU), FATNO+' Nl Acenta Faturası Kdv' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.KDV AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.KDV AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH AND FATID=@FATID
		
						UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
						UPDATE OTEL_FATURA SET FISDURUMID=1, MUHFC=@FISID WHERE TARIH=@TARIH AND FATID=@FATID
				END
			ELSE IF @FATURATURU=1
				BEGIN
						DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
						DELETE FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		
						INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1,MERKEZIFC)
						VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Acenta Fatura Ent.',1,'TL',1,@TOPLAM,0.00,'ACENTAMAHSUBU',@FATID)

		
						INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
						SELECT @FISID, ISNULL(H.HESAPID,(SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@MUNFERITHESAPKODU)) AS HESAPID, FATNO+' Nl Acenta Faturası' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.GTOPLAM AS TUTAR,
						F.DGTOPLAM AS DTUTAR,F.KUR AS KUR, 0.00 AS MIKTAR, F.GTOPLAM AS BORC, 0.00 AS ALACAK, F.DGTOPLAM AS DBORC, 0.00 AS DALACAK, F.TOPLAM AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH AND FATID=@FATID
						UNION ALL
						SELECT @FISID,(SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@GELIRHESAPKODU), FATNO+' Nl Acenta Faturası gelir' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.TOPLAM AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.TOPLAM AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH AND FATID=@FATID
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@KDVHESAPKODU), FATNO+' Nl Acenta Faturası Kdv' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.KDV AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.KDV AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH AND FATID=@FATID
		
						UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
						UPDATE OTEL_FATURA SET FISDURUMID=1, MUHFC=@FISID WHERE TARIH=@TARIH AND FATID=@FATID
				END
	END
ELSE IF @TOPLUENTEGRE=1
	BEGIN
			IF @FATURATURU=0
				BEGIN
						DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
						DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		
						INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
						VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Acenta Fatura Ent.',1,'TL',1,@TOPLAM,0.00,'ACENTAMAHSUBU')

		
						INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
						SELECT @FISID, H.HESAPID AS HESAPID, FATNO+' Nl Acenta Faturası' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.GTOPLAM AS TUTAR,
						F.DGTOPLAM AS DTUTAR,F.KUR AS KUR, 0.00 AS MIKTAR, F.GTOPLAM AS BORC, 0.00 AS ALACAK, F.DGTOPLAM AS DBORC, 0.00 AS DALACAK, F.TOPLAM AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@GELIRHESAPKODU), FATNO+' Nl Acenta Faturası gelir' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.TOPLAM AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.TOPLAM AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@KDVHESAPKODU), FATNO+' Nl Acenta Faturası Kdv' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.KDV AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.KDV AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH
		
						UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
						UPDATE OTEL_FATURA SET FISDURUMID=1, MUHFC=@FISID WHERE TARIH=@TARIH 
				END
			ELSE IF @FATURATURU=1
				BEGIN
						DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
						DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		
						INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
						VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Acenta Fatura Ent.',1,'TL',1,@TOPLAM,0.00,'ACENTAMAHSUBU')

		
						INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
						SELECT @FISID, ISNULL(H.HESAPID,(SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@MUNFERITHESAPKODU)) AS HESAPID, FATNO+' Nl Acenta Faturası' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.GTOPLAM AS TUTAR,
						F.DGTOPLAM AS DTUTAR,F.KUR AS KUR, 0.00 AS MIKTAR, F.GTOPLAM AS BORC, 0.00 AS ALACAK, F.DGTOPLAM AS DBORC, 0.00 AS DALACAK, F.TOPLAM AS BABSTUTAR 
						FROM OTEL_FATURA AS F left JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH
						UNION ALL
						SELECT @FISID,(SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@GELIRHESAPKODU), FATNO+' Nl Acenta Faturası gelir' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.TOPLAM AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.TOPLAM AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH
						UNION ALL
						SELECT @FISID, (SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@KDVHESAPKODU), FATNO+' Nl Acenta Faturası Kdv' AS ACIKLAMA, F.DOVIZ AS DOVIZ,'ACENTAMAHSUBU' AS OZELKOD1, F.KDV AS TUTAR,
						0.00 AS DTUTAR, 0.00 AS KUR, 0.00 AS MIKTAR, 0.00 AS BORC, F.KDV AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK, 0.00 AS BABSTUTAR 
						FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH
		
						UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
						UPDATE OTEL_FATURA SET FISDURUMID=1, MUHFC=@FISID WHERE TARIH=@TARIH 

				END
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PR_ACENTAENTEGRESIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ACENTAENTEGRESIL]  
@TARIH SMALLDATETIME,
@SUBEID INT,
@TOPLUENTEGRE INT,
@FATID INT
AS
BEGIN
IF @TOPLUENTEGRE=0
	BEGIN		
		DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
		DELETE FROM MUH_FIS WHERE MERKEZIFC=@FATID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		UPDATE OTEL_FATURA SET FISDURUMID=0, MUHFC=0 WHERE SUBEID=@SUBEID AND FATID=@FATID AND TARIH=@TARIH
	END
ELSE IF @TOPLUENTEGRE=1
	BEGIN
		DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU')
		DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='ACENTAMAHSUBU'
		UPDATE OTEL_FATURA SET FISDURUMID=0, MUHFC=0 WHERE SUBEID=@SUBEID AND TARIH=@TARIH
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PR_ACENTAFATURALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ACENTAFATURALAR]  
@TARIH SMALLDATETIME,
@FATURATURU INT,
@MUNFERITHESAPKODU NVARCHAR(20),
@SUBEID INT
AS
BEGIN
	IF @FATURATURU=0
		BEGIN
				SELECT F.SUBEID,FATID, TARIH, FATNO, F.UNVANI, 1 AS FISID, H.HESAPID AS HESAPID, H.KODU AS HESAPKODU, H.ACIKLAMA AS HESAPADI, F.VD, F.VDNO, F.TOPLAM,F.KDV, F.GTOPLAM,F.DOVIZ,F.KUR,F.DGTOPLAM 
				FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.CARIID>0 AND  F.TARIH=@TARIH
				ORDER BY F.UNVANI
		END
	ELSE IF @FATURATURU=1
		BEGIN
				SELECT F.SUBEID,FATID, TARIH, FATNO, F.UNVANI, 1 AS FISID, ISNULL(H.HESAPID,(SELECT TOP 1 HESAPID FROM MUH_HESAP WHERE KODU=@MUNFERITHESAPKODU)) AS HESAPID,ISNULL(H.KODU,@MUNFERITHESAPKODU) AS HESAPKODU, 
				ISNULL(H.ACIKLAMA,(SELECT TOP 1 ACIKLAMA FROM MUH_HESAP WHERE KODU=@MUNFERITHESAPKODU)) AS HESAPADI, F.VD, F.VDNO, F.TOPLAM,F.KDV, F.GTOPLAM,F.DOVIZ,F.KUR,F.DGTOPLAM 
				FROM OTEL_FATURA AS F LEFT JOIN OTEL_ACENTA AS A ON F.CARIID=A.ACENTAID LEFT JOIN MUH_HESAP AS H ON A.MUHKODU=H.KODU WHERE F.TARIH=@TARIH
				ORDER BY F.UNVANI
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_ACILISFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ACILISFISI] (@SUBEID INT,@TARIH SMALLDATETIME, @KAPANISFISID INT, @FISID INT, @EKLEYENID INT, @ALTCARIMI INT, @ACIKLAMA NVARCHAR(100)) AS
BEGIN
IF @ALTCARIMI=0
	BEGIN
		INSERT INTO MUH_FIS (FISID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
		VALUES (@FISID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Mahsup', 41, @ACIKLAMA,@SUBEID,'ACILIS',0, @EKLEYENID,GETDATE(), 0, 0,'R')

		INSERT INTO MUH_HESAPISL(FISID,HESAPID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
		SELECT @FISID,  HESAPID, @ACIKLAMA, TUTAR,DTUTAR,   ALACAK,   BORC, DALACAK,   DBORC, KUR,DOVIZ,0  FROM MUH_HESAPISL WHERE FISID=@KAPANISFISID

		UPDATE MUH_FIS SET FISTURID=49 WHERE FISID=@FISID
		UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID

	END
ELSE IF @ALTCARIMI=1
	BEGIN
		INSERT INTO MUH_FIS (FISID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
		VALUES (@FISID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Mahsup', 41, @ACIKLAMA,@SUBEID,'ACILIS',0, @EKLEYENID,GETDATE(), 0, 0,'R')

		INSERT INTO MUH_HESAPISL(FISID,HESAPID,ALTCARIID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
		SELECT @FISID,  HESAPID,ALTCARIID,@ACIKLAMA, TUTAR,DTUTAR,   ALACAK,   BORC, DALACAK,   DBORC, KUR,DOVIZ,0  FROM MUH_HESAPISL WHERE FISID=@KAPANISFISID
		
		UPDATE MUH_FIS SET FISTURID=49 WHERE FISID=@FISID
		UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_ADISYONGRUPSAL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ADISYONGRUPSAL]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME

AS 
SELECT TARIH,SG.KODU AS GRUP,SG.ADI AS GRUPADI, S.ADI AS URUNADI, SUM(ADET) AS MIKTAR, 
SUM(ADET*ISNULL(NETBFIYAT,BIRIMFIYAT)) AS TOPLAMSATIS, SUM(ADET*ISNULL(S.MALIYET,1)) AS TOPLAMMALIYET 
FROM ADSSATIR AS ADS 
INNER JOIN ADISYON AS AD ON ADS.FISCOUNTER=AD.FISCOUNTER INNER JOIN STOK AS S 
ON ADS.STOKID=S.STOKID INNER JOIN STOKGRUP AS SG ON S.GRUP=SG.KODU
WHERE ISNULL(AD.SIL,0)=0 AND TARIH>=@TARIH AND TARIH<=@TARIH2
GROUP BY TARIH,SG.KODU,SG.ADI,S.ADI
ORDER BY SG.KODU,S.ADI
GO
/****** Object:  StoredProcedure [dbo].[PR_AKTARIMESLESTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_AKTARIMESLESTIR]  
@HESAPID INT,
@SIRANO INT
AS
BEGIN



	UPDATE AKTARIMLAR SET AKTARIMLAR.STOKID=STOK.STOKID, AKTARIMLAR.GRUBU=STOK.GRUP, AKTARIMLAR.BIRIML=STOK.BIRIM 
	FROM AKTARIMLAR INNER JOIN STOK ON AKTARIMLAR.STOKKODU=STOK.KODU
	WHERE ISNULL(STOK.SIL,0)=0 AND ISNULL(STOKADI,'')<>'' AND AKTARIMLAR.STOKID IS NULL AND AKTARIMSIRANO=@SIRANO

	UPDATE AKTARIMLAR SET AKTARIMLAR.RENKID=BARKOD.RENKID, AKTARIMLAR.BEDENID=BARKOD.BEDENID, AKTARIMLAR.BARKODID=BARKOD.BARKODID
	FROM AKTARIMLAR INNER JOIN BARKOD ON AKTARIMLAR.BARKOD=BARKOD.BARKOD AND AKTARIMLAR.STOKID=BARKOD.STOKID
	WHERE ISNULL(STOKADI,'')<>'' AND (AKTARIMLAR.RENKID IS NULL OR AKTARIMLAR.BEDENID IS NULL OR AKTARIMLAR.BARKODID IS NULL) AND AKTARIMSIRANO=@SIRANO

 UPDATE AKTARIMLAR
     SET  
	 
	 STOKID = (SELECT TOP 1 STOKID 
	 FROM AKTARIMLAR X  WHERE HESAPID=@HESAPID AND ISNULL(X.STOKADI,'')<>''
     AND  X.STOKID IS NOT NULL AND CHARINDEX(X.STOKADI,AKTARIMLAR.STOKADI)>0
     ORDER BY AKTARIMLARID DESC),  
	 
	 RENKID=(SELECT TOP 1 RENKID
     FROM AKTARIMLAR X WHERE  HESAPID=@HESAPID AND ISNULL(X.RENK,'')<>''
     AND  X.RENKID IS NOT NULL AND CHARINDEX(X.RENK,AKTARIMLAR.RENK)>0
     ORDER BY AKTARIMLARID DESC ),
     
	 BEDENID=(SELECT TOP 1 BEDENID
     FROM AKTARIMLAR X WHERE  HESAPID=@HESAPID AND ISNULL(X.BEDEN,'')<>''
     AND  X.BEDENID IS NOT NULL AND CHARINDEX(X.BEDEN,AKTARIMLAR.BEDEN)>0
     ORDER BY AKTARIMLARID DESC ),

	 GRUBU=(SELECT TOP 1 GRUBU
     FROM AKTARIMLAR X WHERE  HESAPID=@HESAPID AND  ISNULL(X.STOKGRUBU,'')<>''
     AND  X.GRUBU IS NOT NULL AND CHARINDEX(X.STOKGRUBU,AKTARIMLAR.STOKGRUBU)>0
     ORDER BY AKTARIMLARID DESC ),

	 BIRIML=(SELECT TOP 1 BIRIML
     FROM AKTARIMLAR X WHERE  HESAPID=@HESAPID AND  ISNULL(X.BIRIM,'')<>''
     AND  X.BIRIML IS NOT NULL AND CHARINDEX(X.BIRIM,AKTARIMLAR.BIRIM)>0
     ORDER BY AKTARIMLARID DESC ),

	 BARKODID=(SELECT TOP 1 BARKODID
     FROM AKTARIMLAR X WHERE  HESAPID=@HESAPID AND  ISNULL(X.BARKOD,'')<>''
     AND  X.BARKOD IS NOT NULL AND CHARINDEX(X.BARKOD,AKTARIMLAR.BARKOD)>0
     ORDER BY AKTARIMLARID DESC )

	 WHERE ISNULL(STOKADI,'')<>'' AND STOKID IS NULL AND AKTARIMSIRANO=@SIRANO

END
GO
/****** Object:  StoredProcedure [dbo].[PR_AZURTABLOAKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE PROCEDURE [dbo].[PR_AZURTABLOAKTAR] @FIRMAID NVARCHAR(10)
 AS 
 DECLARE @TableName varchar(255)  
 DECLARE @SQL NVARCHAR(4000)
 DECLARE @HEDEFTABLO NVARCHAr(50)
 DECLARE @COLUMNAME NVARCHAR(50)
 DECLARE @KOLONLAR NVARCHAR(MAX)
 DECLARE TableCursor CURSOR FOR  
 SELECT table_name FROM INFORMATION_SCHEMA.TABLES 
 WHERE table_type = 'base table'  AND table_name like'%'+@FIRMAID
 OPEN TableCursor  
 FETCH NEXT FROM TableCursor INTO @TableName  
 WHILE @@FETCH_STATUS = 0  
 BEGIN
			 SET @HEDEFTABLO=REPLACE(@tableName,@FIRMAID,'')  
			 SET @KOLONLAR=''
			 DECLARE ColumnCursor CURSOR FOR  
 			 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @HEDEFTABLO
			 OPEN ColumnCursor  
			 FETCH NEXT FROM ColumnCursor INTO @COLUMNAME
			 WHILE @@FETCH_STATUS = 0  
				BEGIN
					SET @KOLONLAR=@KOLONLAR+'['+@COLUMNAME+']'+','
					FETCH NEXT FROM ColumnCursor INTO @COLUMNAME  
				 END  
				 CLOSE ColumnCursor  
				 DEALLOCATE ColumnCursor
			SET @KOLONLAR=SUBSTRING(@KOLONLAR,1,LEN(@KOLONLAR)-1)	  
			SET @SQL='
			set identity_insert '+@HEDEFTABLO+' on
			INSERT INTO '+@HEDEFTABLO+' ('+@KOLONLAR+') SELECT '+@KOLONLAR+' FROM '+@TableName+'
			set identity_insert '+@HEDEFTABLO+' off'
			PRINT(@SQL)
 FETCH NEXT FROM TableCursor INTO @TableName  
 END  
 CLOSE TableCursor  
 DEALLOCATE TableCursor 
GO
/****** Object:  StoredProcedure [dbo].[PR_BABS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BABS]  
@SUBEID INT,
@YIL INT,
@AY INT,
@PARAMETRE NVARCHAR(20),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(  SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MAX(UNVANI) AS UNVANI, MAX(EMAIL) AS EMAIL,REPLACE(VDNO,' ','') AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE  ISNULL(FISIVAR,0)=1 AND  ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0) AND (VDNO IS NOT NULL AND LTRIM(VDNO)<>'') AND FISDURUMID>=0   AND SUBEID=@SUBEID   AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), REPLACE(VDNO,' ',''),REPLACE(CASE WHEN VDNO='1111111111' OR VDNO='11111111111' OR VDNO='2222222222' OR VDNO='22222222222' THEN  UNVANI ELSE VDNO END,' ','')  
			   UNION ALL 
			   SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, UNVANI, EMAIL,CASE WHEN TUR = 1 THEN '1111111111' ELSE '2222222222' END AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE   ISNULL(FISIVAR,0)=1 AND   ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0)   AND (VDNO IS NULL OR LTRIM(VDNO)='') AND FISDURUMID>=0    AND SUBEID=@SUBEID  AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), UNVANI,EMAIL  
			  UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, MAX(ISNULL(H.UNVANI,H.ACIKLAMA) ) AS UNVANI, MAX(H.EMAIL) AS EMAIL, REPLACE(H.VDNO,' ','') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
			 FROM (SELECT FISTURID,SUBEID, TARIH, HESAPID, BABSTUTAR,OZELKOD1, BORC+ALACAK AS TOPLAM
		   , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
		   FROM QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		   WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')<>'' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		   GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),REPLACE(VDNO,' ',''),REPLACE(CASE WHEN H.VDNO='1111111111' OR H.VDNO='11111111111' OR H.VDNO='2222222222' OR H.VDNO='22222222222' THEN  H.ACIKLAMA ELSE H.VDNO END,' ',''), F.ALANTIPI
		 UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, ISNULL(H.UNVANI,H.ACIKLAMA)  AS UNVANI, H.EMAIL,ISNULL(H.VDNO,'') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
		 FROM (SELECT FISTURID, SUBEID,TARIH, HESAPID, BABSTUTAR, OZELKOD1,BORC+ALACAK AS TOPLAM
			 , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
			 FROM QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		 WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')='' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		 GROUP BY YEAR(F.TARIH),MONTH(F.TARIH),ISNULL(H.UNVANI,H.ACIKLAMA) ,EMAIL, H.VDNO, F.ALANTIPI
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PR_BABSFATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BABSFATURA]  
@SUBEID INT,
@YIL INT,
@AY INT,
@PARAMETRE NVARCHAR(20),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(  SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MAX(UNVANI) AS UNVANI, MAX(EMAIL) AS EMAIL, REPLACE(VDNO,' ','') AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE  ISNULL(FISIVAR,0)=0 AND  ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0) AND (VDNO IS NOT NULL AND LTRIM(VDNO)<>'') AND FISDURUMID>=0   AND SUBEID=@SUBEID   AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, EMAIL,YEAR(TARIH), MONTH(TARIH), REPLACE(VDNO,' ',''),REPLACE(CASE WHEN VDNO='1111111111' OR VDNO='11111111111' OR VDNO='2222222222' OR VDNO='22222222222' THEN  UNVANI ELSE VDNO END,' ','')  
			   UNION ALL 
			   SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, UNVANI, EMAIL, CASE WHEN TUR = 1 THEN '1111111111' ELSE '2222222222' END AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE   ISNULL(FISIVAR,0)=0 AND   ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0)   AND (VDNO IS NULL OR LTRIM(VDNO)='') AND FISDURUMID>=0    AND SUBEID=@SUBEID  AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), UNVANI,EMAIL  
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PR_BABSMUH]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BABSMUH]  
@SUBEID INT,
@YIL INT,
@AY INT,
@PARAMETRE NVARCHAR(20),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, MAX(ISNULL(H.UNVANI,H.ACIKLAMA) ) AS UNVANI, EMAIL, REPLACE(H.VDNO,' ','') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
			 FROM (SELECT FISTURID,SUBEID, TARIH, HESAPID, BABSTUTAR,OZELKOD1, BORC+ALACAK AS TOPLAM
		   , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
		   FROM QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		   WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')<>'' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		   GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),REPLACE(VDNO,' ',''),REPLACE(CASE WHEN H.VDNO='1111111111' OR H.VDNO='11111111111' OR H.VDNO='2222222222' OR H.VDNO='22222222222' THEN  H.ACIKLAMA ELSE H.VDNO END,' ',''), F.ALANTIPI
		 UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, ISNULL(H.UNVANI,H.ACIKLAMA)  AS UNVANI, EMAIL, ISNULL(H.VDNO,'') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
		 FROM (SELECT FISTURID, SUBEID,TARIH, HESAPID, BABSTUTAR, OZELKOD1,BORC+ALACAK AS TOPLAM
			 , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
			 FROM QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		 WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')='' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		 GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),ISNULL(H.UNVANI,H.ACIKLAMA) , H.VDNO, F.ALANTIPI
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PR_BANKAFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BANKAFISI]  
@TARIH SMALLDATETIME,
@EKLEMETARIH SMALLDATETIME,
@FISID INT,
@BANKAID INT,
@USERID INT,
@SUBEID INT,
@FISTURID INT
AS
BEGIN 
	INSERT INTO MUH_FIS (FISHESAPID,FISID,ALTCARIID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, SUBEID, ENTKAYNAK, ADD_USERID, ADD_DATE, 
	TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE) 
	VALUES (@BANKAID,@FISID,Null,@TARIH,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH), (CASE WHEN @FISTURID=4 THEN 'Bankadan Ödeme' ELSE 'Bankaya Tahsilat' end),@FISTURID,'Günlük Banka İşlemleri','',@SUBEID,'BankaEkstreOku',@USERID,@EKLEMETARIH, 0, 
	0, 0, 0,'TL',1,@FISID,'Muhasebe Fişi','BANKA',-1,1)
END
GO
/****** Object:  StoredProcedure [dbo].[PR_BANKAFISI_OLUSTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BANKAFISI_OLUSTUR]  
@FISUUID uniqueidentifier,
@TARIH SMALLDATETIME,
@EKLEMETARIH SMALLDATETIME,
@FISID INT,
@BANKAID INT,
@USERID INT,
@SUBEID INT,
@FIRMAID INT,
@FISTURID INT,
@BANKAEKSTREID INT,
@DOVIZ NVARCHAR(10),
@HATA INT
AS
BEGIN 

BEGIN TRANSACTION
	INSERT INTO MUH_FIS (FISUUID,FISHESAPID,ALTCARIID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, FIRMAID,SUBEID, ENTKAYNAK, ADD_USERID, ADD_DATE, 
	TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE) 
	VALUES (@FISUUID,@BANKAID,Null,@TARIH,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH), (CASE WHEN @FISTURID=4 THEN 'Bankadan Ödeme' ELSE 'Bankaya Tahsilat' end),@FISTURID,'Günlük Banka İşlemleri','',@FIRMAID,@SUBEID,'BankaEkstreOku',@USERID,@EKLEMETARIH, 0, 
	0, 0, 0,'TL',1,@FISID,'Muhasebe Fişi','BANKA',-1,1)
SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
IF @FISTURID=4
	BEGIN
		INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
		SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
		ABS(TUTAR)*KUR AS BORC, 0.00 AS ALACAK,KUR,@DOVIZ,ABS(TUTAR) AS DBORC,0.00 AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
		MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
		FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
		KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR < 0 
	END

ELSE IF @FISTURID=3
	BEGIN
		INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
		SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
		0.00 AS BORC, ABS(TUTAR)*KUR AS ALACAK,KUR,@DOVIZ,0.00 AS DBORC,ABS(TUTAR) AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
		MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
		FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
		KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR > 0 
	END

UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(TUTAR) FROM MUH_HESAPISL WHERE
ISNULL(SILINDI,0)=0 AND FISID=@FISID),
DTOPLAM=(SELECT SUM(DTUTAR) FROM MUH_HESAPISL WHERE
ISNULL(SILINDI,0)=0 AND FISID=@FISID) WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISID=@FISID


UPDATE MUH_BANKAEKSTRE_DETAY SET FISID=@FISID WHERE SUBEID=@SUBEID AND ID IN
(SELECT BANKAEKSTREDETAYID FROM MUH_HESAPISL WHERE FISID=@FISID)

SET @HATA=@@ERROR
IF @HATA > 0 
	BEGIN
		ROLLBACK TRANSACTION
	END
ELSE
	BEGIN
		COMMIT TRANSACTION
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_BANKAKREDIMAHSUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BANKAKREDIMAHSUP]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@GERIODEMETUTARI FLOAT,
@SUBEID INT,
@EKLEYEN INT,
@BANKAID INT,
@ANAPARAID INT,
@GELECEKGIDERID INT
AS
BEGIN

IF @GELECEKGIDERID<=0
	BEGIN
		DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU')
		DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU'
		
		INSERT INTO MUH_FIS (FISNO,FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
		VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Banka Kredi Ent.',1,'TL',1,@TOPLAM,0.00,'BANKAKREDIMAHSUBU')

		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @BANKAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, @TOPLAM, 0.00, 0.00, 0.00, 0.00)
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @ANAPARAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, 0.00, @TOPLAM, 0.00, 0.00, 0.00)
	END
ELSE
	BEGIN
		DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU')
		DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU'
		
		INSERT INTO MUH_FIS (FISNO,FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
		VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Banka Kredi Ent.',1,'TL',1,@TOPLAM,0.00,'BANKAKREDIMAHSUBU')

		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @BANKAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, @TOPLAM, 0.00, 0.00, 0.00, 0.00)

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @GELECEKGIDERID, 'Gelecek Aylara Ait Gider.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, (@GERIODEMETUTARI-@TOPLAM), 0.00, 0.00, 0.00, 0.00)

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @ANAPARAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, 0.00, @GERIODEMETUTARI, 0.00, 0.00, 0.00)
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PR_BELGEDUZENLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BELGEDUZENLE]  
(@SUBEID INT, @BASTARIH DATETIME,@BITTARIH DATETIME)
AS
BEGIN
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=3 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=4 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=1 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=2 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=42 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=43 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=2, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID>=21 AND FISTURID<=36 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGENO,'')='' AND BELGETURU=1
		 UPDATE MUH_FIS SET BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGENO IS NULL AND BELGETURU IN(-1,5,13,15,16,21)
		 UPDATE MUH_FIS SET BELGETURU=-1, BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGETURU,0)=0
		 

		 UPDATE MUH_FIS SET BELGETURU=11, BELGENO=ISNULL(BELGENO,FISNO)  WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'6%'))
		 UPDATE MUH_FIS SET BELGETURU=13  WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'335%'))
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE BORC>0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'100%'))
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE ALACAK<0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'100%'))

		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE BORC>0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'102%'))
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE ALACAK<0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'102%'))

		 UPDATE MUH_FIS SET BELGETURU=12, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='KREDI KARTI' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'108%'))

		 UPDATE MUH_FIS SET BELGETURU=2, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'101%' OR KODU LIKE'103%'))


		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=MUH_FIS.BELGETURU, MUH_HESAPISL.BELGENO=MUH_FIS.BELGENO, MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH, MUH_HESAPISL.ODEMEYONTEMI=MUH_FIS.ODEMEYONTEMI
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND (MUH_HESAPISL.BELGETURU IS NULL OR MUH_HESAPISL.BELGETURU<>MUH_FIS.BELGETURU)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=-1, MUH_HESAPISL.BELGENO=NULL, MUH_HESAPISL.BELGETARIH=NULL, MUH_HESAPISL.ODEMEYONTEMI=NULL
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND (MUH_HESAPISL.BELGETURU IS NULL AND MUH_FIS.BELGETURU IS NULL)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=1, MUH_HESAPISL.BELGENO=ISNULL(MUH_FIS.BELGENO,MUH_FIS.FISNO), MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND MUH_FIS.BELGETURU=1

		 UPDATE MUH_FIS SET BELGEACIKLAMA=ACIKLAMA WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGEACIKLAMA,'')='' AND MUH_FIS.BELGETURU IN(-1,5,13,15,16,21)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGENO=ISNULL(MUH_FIS.BELGENO,MUH_FIS.FISNO), MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH,MUH_HESAPISL.BELGEACIKLAMA=MUH_FIS.BELGEACIKLAMA
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND MUH_FIS.BELGETURU IN(-1,5,13,15,16,21)

		 UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, OZELKOD3='FIS SATIRI YOK' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND  FISID NOT IN(SELECT DISTINCT FISID FROM MUH_HESAPISL) AND ISNULL(SIL,0)=0

		 UPDATE MUH_FIS SET ACIKLAMA='Muhasebe Fişi' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(ACIKLAMA,'')=''

 END
GO
/****** Object:  StoredProcedure [dbo].[PR_BETONAKTARIMESLESTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_BETONAKTARIMESLESTIR]  
@SIRANO INT
AS
BEGIN
	UPDATE BETONAKTARIMLAR SET BETONAKTARIMLAR.STOKID=STOK.STOKID
	FROM BETONAKTARIMLAR INNER JOIN STOK ON BETONAKTARIMLAR.STOKADI=STOK.ADI
	WHERE ISNULL(STOK.SIL,0)=0 AND ISNULL(STOKADI,'')<>'' AND BETONAKTARIMLAR.STOKID IS NULL AND AKTARIMSIRANO=@SIRANO

	UPDATE BETONAKTARIMLAR SET BETONAKTARIMLAR.HESAPID=MUH_HESAP.HESAPID
	FROM BETONAKTARIMLAR INNER JOIN MUH_HESAP ON BETONAKTARIMLAR.UNVANI=MUH_HESAP.UNVANI
	WHERE ISNULL(BETONAKTARIMLAR.UNVANI,'')<>'' AND BETONAKTARIMLAR.HESAPID IS NULL AND AKTARIMSIRANO=@SIRANO

	UPDATE BETONAKTARIMLAR SET BETONAKTARIMLAR.ALTCARIID=MUH_HESAP_ALTCARI.ALTCARIID
	FROM BETONAKTARIMLAR INNER JOIN MUH_HESAP_ALTCARI ON BETONAKTARIMLAR.ALTCARIUNVANI=MUH_HESAP_ALTCARI.UNVANI
	WHERE ISNULL(BETONAKTARIMLAR.ALTCARIUNVANI,'')<>'' AND BETONAKTARIMLAR.ALTCARIID IS NULL AND AKTARIMSIRANO=@SIRANO

 UPDATE BETONAKTARIMLAR
     SET  
	 
	 STOKID = (SELECT TOP 1 STOKID 
	 FROM BETONAKTARIMLAR X  WHERE ISNULL(X.STOKADI,'')<>''
     AND  X.STOKID IS NOT NULL AND CHARINDEX(X.STOKADI,BETONAKTARIMLAR.STOKADI)>0
     ORDER BY BETONAKTARIMLARID DESC),  
	 
	 HESAPID=(SELECT TOP 1 HESAPID
     FROM BETONAKTARIMLAR X WHERE  ISNULL(X.UNVANI,'')<>''
     AND  X.HESAPID IS NOT NULL AND CHARINDEX(X.UNVANI,BETONAKTARIMLAR.UNVANI)>0
     ORDER BY BETONAKTARIMLARID DESC ),

	 ALTCARIID=(SELECT TOP 1 ALTCARIID
     FROM BETONAKTARIMLAR X WHERE  ISNULL(X.ALTCARIUNVANI,'')<>''
     AND  X.ALTCARIID IS NOT NULL AND CHARINDEX(X.ALTCARIUNVANI,BETONAKTARIMLAR.ALTCARIUNVANI)>0
     ORDER BY BETONAKTARIMLARID DESC ),

	 FIYAT=(SELECT TOP 1 FIYAT
     FROM BETONAKTARIMLAR X WHERE  ISNULL(X.ALTCARIUNVANI,'')<>''
     AND  X.FIYAT IS NOT NULL AND CHARINDEX(X.ALTCARIUNVANI,BETONAKTARIMLAR.ALTCARIUNVANI)>0
     ORDER BY BETONAKTARIMLARID DESC )

	 WHERE ISNULL(STOKADI,'')<>'' AND STOKID IS NULL AND AKTARIMSIRANO=@SIRANO

END
GO
/****** Object:  StoredProcedure [dbo].[PR_DEPOFIS_KOPYALA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_DEPOFIS_KOPYALA] @YENIDEPOFISID INT, @ESKIDEPOFISID INT
AS
INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,BARKOD,RENKID,BEDENID) 
SELECT @YENIDEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,BARKOD,RENKID,BEDENID FROM DEPOFISISL WHERE DEPOFISID=@ESKIDEPOFISID
GO
/****** Object:  StoredProcedure [dbo].[PR_ENVANTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_ENVANTER]  
@SUBEID INT,
@ILKT DATETIME,
@SONT DATETIME
AS
BEGIN
		SELECT SUBEID,SUBEKODU,SUBEADI,MUHNHESAPID AS MUHHESAPID, NMUHKODU AS MUHKODU, NMUHADI AS MUHADI,DEPOID,DEPOKODU,DEPOADI,ANAGRUPKODU,ANAGRUPADI,USTGRUPKODU,USTGRUPADI,ALTGRUPKODU,ALTGRUPADI,SGRUPKODU,
		SGRUPADI,KODU,ADI,SBIRIMI, SUM(DEVIRMIKTAR) AS DEVIRMIKTAR, SUM(DEVIRTUTAR) AS DEVIRTUTAR, SUM(GIRENMIKTAR) AS GIRENMIKTAR,
		SUM(GIRENTUTAR) AS GIRENTUTAR, SUM(ALIMMIKTAR) AS ALIMMIKTAR, SUM(ALIMTUTAR) AS ALIMTTUTAR, SUM(CIKANMIKTAR) AS CIKANMIKTAR, SUM(CIKANTUTAR) AS CIKANTUTAR,
		SUM(KARTOPLAMI) AS KARTOPLAMI, SUM(KALANMIKTAR) AS KALANMIKTAR, SUM(KALANTUTAR) AS KALANTUTAR, SUM(KALANSONTUTAR) AS KALANSONTUTAR, SUM(KALANSATISTUTAR) AS KALANSATISTUTAR,
		AVG(BAKIYE153) AS BAKIYE153,  SUM(STOKKALANTUTAR153) AS STOKKALANTUTAR153, SUM(TOPLAMMALIYET) AS TOPLAMMALIYET, 0.00  AS BIRIMMALIYET FROM 
		(
		 SELECT QS.SUBEID SUBEID, QS.SUBEKODU, QS.SUBEADI, QS.NMUHKODU, QS.MUHNHESAPID,QS.NMUHADI, QS.DEPOID DEPOID, DEPOKODU, DEPOADI, ANAGRUPKODU,
		ANAGRUPADI, USTGRUPKODU, USTGRUPADI, ALTGRUPKODU, ALTGRUPADI, 
		SGRUPKODU, SGRUPADI, KODU,
		ADI,CARIUNVANI, ISLEM,SBIRIMI, SUM(CASE WHEN QS.TARIH < @ILKT THEN GCADET ELSE 0 END) AS DEVIRMIKTAR,
		SUM(CASE WHEN QS.TARIH <@ILKT THEN TOPLAM ELSE 0 END) AS DEVIRTUTAR, 
		SUM(CASE WHEN GCADET > 0 AND QS.TARIH >=@ILKT AND QS.TARIH <=@SONT THEN GCADET ELSE 0 END) AS GIRENMIKTAR, 
		SUM(CASE WHEN GCADET > 0 AND QS.TARIH >=@ILKT AND QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END) AS GIRENTUTAR, 
		SUM(CASE WHEN FISTIPI = 'FATURA' AND ISLEM<>'SATIS' AND QS.TARIH >=@ILKT AND  QS.TARIH <=@SONT THEN GCADET ELSE 0 END) AS ALIMMIKTAR, 
		SUM(CASE WHEN FISTIPI = 'FATURA' AND ISLEM<>'SATIS' AND QS.TARIH >=@ILKT AND  
		QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END) AS ALIMTUTAR, 
		SUM(CASE WHEN GCADET < 0 AND QS.TARIH >=@ILKT AND QS.TARIH <=@SONT THEN GCADET ELSE 0 END) AS CIKANMIKTAR,
		SUM(CASE WHEN GCADET < 0 AND QS.TARIH >=@ILKT AND 
		QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END) AS CIKANTUTAR,
		SUM(CASE WHEN GCADET < 0 AND QS.TARIH >=@ILKT AND 
		QS.TARIH <=@SONT THEN TOPLAMMALIYET ELSE 0 END) AS CIKANMALIYET,
		SUM(CASE WHEN GCADET < 0 AND QS.TARIH >=@ILKT AND 
		QS.TARIH <=@SONT THEN (TOPLAM*-1)-TOPLAMMALIYET ELSE 0 END) AS KARTOPLAMI, 
		SUM(CASE WHEN QS.TARIH <=@SONT THEN GCADET ELSE 0 END) AS KALANMIKTAR, 
		SUM(CASE WHEN QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END) AS KALANTUTAR, 
		SUM(CASE WHEN QS.TARIH <=@SONT THEN GCADET ELSE 0 END)*SALISFIYAT AS KALANSONTUTAR,
		SUM(CASE WHEN QS.TARIH <=@SONT THEN GCADET ELSE 0 END)*SFIYAT1 AS KALANSATISTUTAR,
		(SELECT SUM(BORC)-SUM(ALACAK) FROM QMUH_HESAPISL AS Q WHERE SUBEID=@SUBEID AND Q.TARIH >=@ILKT AND Q.TARIH <=@SONT AND Q.HESAPID=QS.MUHNHESAPID) AS BAKIYE153,
		(SELECT SUM(TOPLAM) FROM QMUH_STOKISLSAYIM AS QSAY WHERE QSAY.TARIH<=@SONT AND QSAY.MUHNHESAPID=QS.MUHNHESAPID) AS STOKKALANTUTAR153, 
		--TOPLAM MALİYET
		NULLIF((SELECT SUM(BORC)-SUM(ALACAK) FROM QMUH_HESAPISL AS Q WHERE SUBEID=@SUBEID AND Q.TARIH >=@ILKT AND Q.TARIH <=@SONT AND Q.HESAPID=QS.MUHNHESAPID),0)/100*
		((NULLIF(SUM(CASE WHEN QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END),0) / NULLIF((SELECT SUM(TOPLAM) FROM QMUH_STOKISLSAYIM AS QSAY WHERE QSAY.TARIH<=@SONT AND QSAY.MUHNHESAPID=QS.MUHNHESAPID),0)*100)) AS TOPLAMMALIYET, 
	
		--BİRİM MALİYET
		NULLIF((SELECT SUM(BORC)-SUM(ALACAK) FROM QMUH_HESAPISL AS Q WHERE SUBEID=@SUBEID AND Q.TARIH >=@ILKT AND Q.TARIH <=@SONT AND Q.HESAPID=QS.MUHNHESAPID),0)/100*
		(NULLIF(SUM(CASE WHEN QS.TARIH <=@SONT THEN TOPLAM ELSE 0 END),0)
		/NULLIF((SELECT SUM(TOPLAM) FROM QMUH_STOKISLSAYIM AS QSAY WHERE QSAY.TARIH<=@SONT AND QSAY.MUHNHESAPID=QS.MUHNHESAPID),0)*100)
		/NULLIF(SUM(CASE WHEN QS.TARIH <=@SONT THEN GCADET ELSE 0 END),0) AS BIRIMMALIYET, 

		ASGARI, OPTIMAL,SKTARIHI FROM dbo.QMUH_STOKISLSAYIM QS LEFT OUTER JOIN SDEPO ON 
		(SDEPO.DEPOID = QS.DEPOID AND SDEPO.STOKID = QS.STOKID AND QS.SUBEID = SDEPO.SUBEID )
		WHERE 1=1 GROUP BY QS.SUBEID, SFIYAT1, QS.SUBEKODU, QS.SUBEADI, QS.MUHNHESAPID, QS.NMUHKODU,QS.NMUHADI, QS.DEPOID, ASGARI,OPTIMAL,DEPOKODU, DEPOADI, ANAGRUPKODU,
		ANAGRUPADI, USTGRUPKODU, USTGRUPADI, ALTGRUPKODU, ALTGRUPADI, SGRUPKODU, 
		SGRUPADI, KODU, ADI,CARIUNVANI, ISLEM, SBIRIMI,SALISFIYAT,SKTARIHI,QS.MUHNHESAPID) TBL WHERE 1=1 AND KALANMIKTAR>0
		GROUP BY
		SUBEID,SUBEKODU,SUBEADI,MUHNHESAPID,NMUHKODU,NMUHADI,DEPOID,DEPOKODU,DEPOADI,ANAGRUPKODU,ANAGRUPADI,USTGRUPKODU,USTGRUPADI,ALTGRUPKODU,ALTGRUPADI,SGRUPKODU,
		SGRUPADI,KODU,ADI,SBIRIMI
END
GO
/****** Object:  StoredProcedure [dbo].[PR_FATURAENTEGRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_FATURAENTEGRE]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@EKLEYEN INT,
@UNVANI NVARCHAR(100),
@FATNO NVARCHAR(20),
@FATURATURU NVARCHAR(30),
@MASMERID INT
AS
BEGIN
DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FISID=@FISID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='FATURAENTEGRE')
DELETE FROM MUH_FIS WHERE FISID=@FISID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='FATURAENTEGRE'

		if @MASMERID>0
			BEGIN
				INSERT INTO MUH_FIS (FISNO,BELGENO,BELGETURU,FISID,SUBEID,MASMERID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
				VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FATNO,1,@FISID,@SUBEID,@MASMERID,41,2,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup',@FATNO+' Nolu '+@UNVANI+' '+@FATURATURU,1,'TL',1,@TOPLAM,0.00,'FATURAENTEGRE')
			END
		ELSE
			BEGIN
				INSERT INTO MUH_FIS (FISNO,BELGENO,BELGETURU,FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
				VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FATNO,1,@FISID,@SUBEID,41,2,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup',@FATNO+' Nolu '+@UNVANI+' '+@FATURATURU,1,'TL',1,@TOPLAM,0.00,'FATURAENTEGRE')
			END
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,MASMERID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR,BELGENO,BELGETURU)
		SELECT FISID, HESAPID, MASMERID, @FATNO+' Nolu '+@UNVANI+' '+@FATURATURU as ACIKLAMA, 'TL' AS DOVIZ, 'FATURAENTEGRE' AS OZELKOD1, 
		(CASE WHEN  BORC>0 THEN BORC ELSE ALACAK END) AS TUTAR, 0.00 AS DTUTAR, 0.00 AS MIKTAR, BORC,  ALACAK, DBORC, DALACAK,BABSTUTAR,BELGENO,1 
		FROM QMUH_HESAPISL WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND FISID=@FISID

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
END
GO
/****** Object:  StoredProcedure [dbo].[PR_FATURAENTSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_FATURAENTSIL]  
@FISID INT,
@TARIH SMALLDATETIME,
@SUBEID INT
AS
BEGIN
	DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FISID=@FISID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='FATURAENTEGRE')
	DELETE FROM MUH_FIS WHERE FISID=@FISID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='FATURAENTEGRE'
END
GO
/****** Object:  StoredProcedure [dbo].[PR_GENELMUAVIN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PR_GENELMUAVIN]  
@TARIH1 SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@MUHTARIH1 SMALLDATETIME,
@MUHTARIH2 SMALLDATETIME,
@ILKKOD NVARCHAR(30),
@SONKOD NVARCHAR(30),
@SUBELER NVARCHAR(30),
@HESAPTIPLERI NVARCHAR(100),
@DEVIRGOSTER NVARCHAR(1)
AS
BEGIN
	IF @ILKKOD='' SET @ILKKOD='0'
	IF @SONKOD='' SET @SONKOD='999999999999999999'
IF @DEVIRGOSTER='E' 
		BEGIN
			SELECT * FROM ( SELECT     HESAPID,ANAHESAPKODU, HESAPTIPADI, HESAPGRUPADI1, HESAPGRUPADI2,
			HESAPKODU, HESAPADI, TARIH, VADE,
			FISTURADI, FISNO, BELGENO, YEVMNO, ACIKLAMA,
			BELGEACIKLAMA, FISID, BIRIM,MIKTAR,BORC, ALACAK, DOVIZ, DBORC, DALACAK,
			BORCBAKIYE HESAPBAKIYE,DBORCBAKIYE DHESAPBAKIYE,
			CASE WHEN BORCBAKIYE>0 THEN BORCBAKIYE ELSE 0 END BORCBAKIYE,
			CASE WHEN DBORCBAKIYE>0 THEN DBORCBAKIYE ELSE 0 END DBORCBAKIYE,
			CASE WHEN BORCBAKIYE<0 THEN -1*BORCBAKIYE ELSE 0 END ALACAKBAKIYE,
			CASE WHEN DBORCBAKIYE<0 THEN -1*DBORCBAKIYE ELSE 0 END DALACAKBAKIYE,
			KUR, SUBEKODU, SUBEADI, ISLEMGRUPADI1, MASMERKODU, ODEMEYONTEMI,
			MASMERADI, ENTKAYNAK,KARSIHESAPKODU FISHESAPKODU, FISTURID, YIL, AY, HAFTA, 
			OZELKOD1, OZELKOD2, OZELKOD3, HESAPADI2, ISLEMGRUPADI2, ISLEMGRUPADI3,
			PROJEKODU, PROJEADI, CEKID, ISLEMID, HESAPKODUveADI,KARSIHESAPKODU,
			KARSIHESAPADI,TFISID, TFISTARIH, TFISNO, TFISACIKLAMA,ALTCARIKODU,ALTCARIID,
			ALTCARIUNVANI,ALTCARIKODUveUNVANI
			FROM dbo.QMUH_HESAPISL WHERE (CHARINDEX(CAST(HESAPTIPID AS NVARCHAR(20)),@HESAPTIPLERI)>0) AND (TARIH BETWEEN @TARIH1 AND @TARIH2)
			AND (TARIH  BETWEEN @TARIH1 AND @TARIH2)
			AND KODU>=@ILKKOD AND KODU<=@SONKOD AND SUBEID IN (SELECT SUBEID FROM SUBELER (NOLOCK) WHERE ( CHARINDEX(CAST(SUBEID AS NVARCHAR(20)),@SUBELER)>0))
			AND FIRMAID IN (SELECT ID FROM SUBEFIRMALAR (NOLOCK) WHERE ID IN (1))
			UNION ALL SELECT HESAPID,ANAHESAPKODU, HESAPTIPADI, HESAPGRUPADI1, HESAPGRUPADI2, HESAPKODU, HESAPADI, @TARIH1 AS TARIH,
			NULL AS VADE, NULL AS FISTURADI, NULL AS FISNO, NULL AS BELGENO, NULL AS YEVMNO,
			'Devir' AS ACIKLAMA,  NULL AS BELGEACIKLAMA, null as FISID,
			MAX(BIRIM) BIRIM, SUM(MIKTAR) AS MIKTAR, sum(BORC) AS BORC, SUM(ALACAK) AS ALACAK, DOVIZ,
			SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL AS HESAPBAKIYE,NULL AS DHESAPBAKIYE,
			NULL AS ALACAKBAKIYE,NULL AS DALACAKBAKIYE, NULL AS BORCBAKIYE, NULL AS DBORCBAKIYE, NULL AS KUR,
			SUBEKODU, SUBEADI, NULL AS ISLEMGRUPADI1, NULL AS MASMERKODU,NULL AS ODEMEYONTEMI,  NULL AS MASMERADI,
			NULL AS ENTKAYNAK, NULL AS FISHESAPKODU, NULL AS FISTURID, NULL AS YIL, NULL AS AY, NULL AS HAFTA,
			NULL AS OZELKOD1, NULL AS OZELKOD2, NULL AS OZELKOD3, HESAPADI2, NULL AS ISLEMGRUPADI2,  NULL AS ISLEMGRUPADI3, NULL AS PROJEKODU,
			NULL AS PROJEADI, NULL AS CEKID, NULL AS ISLEMID, HESAPKODUveADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
			FROM dbo.QMUH_HESAPISL WHERE (CHARINDEX(CAST(HESAPTIPID AS NVARCHAR(20)),@HESAPTIPLERI)>0) AND TARIH < @TARIH1 AND KODU>=@ILKKOD AND KODU<=@SONKOD
			AND SUBEID IN (SELECT SUBEID FROM SUBELER (NOLOCK) WHERE ( CHARINDEX(CAST(SUBEID AS NVARCHAR(20)),@SUBELER)>0))
			AND FIRMAID IN (SELECT ID FROM SUBEFIRMALAR (NOLOCK) WHERE ID IN (1))
			AND (TARIH  BETWEEN @MUHTARIH1 AND @MUHTARIH2)  GROUP BY HESAPID,ANAHESAPKODU,
			HESAPTIPADI, HESAPGRUPADI1, HESAPGRUPADI2, HESAPKODU, HESAPADI,HESAPADI2,SUBEKODU, 
			SUBEADI,HESAPKODUveADI,DOVIZ  )  TBL  ORDER BY HESAPKODU,TARIH,SUBEKODU,FISID
		END
ELSE
	BEGIN
			SELECT * FROM ( SELECT     HESAPID,ANAHESAPKODU, HESAPTIPADI, HESAPGRUPADI1, HESAPGRUPADI2,
			HESAPKODU, HESAPADI, TARIH, VADE,
			FISTURADI, FISNO, BELGENO, YEVMNO, ACIKLAMA,
			BELGEACIKLAMA, FISID, BIRIM,MIKTAR,BORC, ALACAK, DOVIZ, DBORC, DALACAK,
			BORCBAKIYE HESAPBAKIYE,DBORCBAKIYE DHESAPBAKIYE,
			CASE WHEN BORCBAKIYE>0 THEN BORCBAKIYE ELSE 0 END BORCBAKIYE,
			CASE WHEN DBORCBAKIYE>0 THEN DBORCBAKIYE ELSE 0 END DBORCBAKIYE,
			CASE WHEN BORCBAKIYE<0 THEN -1*BORCBAKIYE ELSE 0 END ALACAKBAKIYE,
			CASE WHEN DBORCBAKIYE<0 THEN -1*DBORCBAKIYE ELSE 0 END DALACAKBAKIYE,
			KUR, SUBEKODU, SUBEADI, ISLEMGRUPADI1, MASMERKODU, ODEMEYONTEMI,
			MASMERADI, ENTKAYNAK,KARSIHESAPKODU FISHESAPKODU, FISTURID, YIL, AY, HAFTA, 
			OZELKOD1, OZELKOD2, OZELKOD3, HESAPADI2, ISLEMGRUPADI2, ISLEMGRUPADI3,
			PROJEKODU, PROJEADI, CEKID, ISLEMID, HESAPKODUveADI,KARSIHESAPKODU,
			KARSIHESAPADI,TFISID, TFISTARIH, TFISNO, TFISACIKLAMA,ALTCARIKODU,ALTCARIID,
			ALTCARIUNVANI,ALTCARIKODUveUNVANI
			FROM dbo.QMUH_HESAPISL WHERE (CHARINDEX(CAST(HESAPTIPID AS NVARCHAR(20)),@HESAPTIPLERI)>0) AND (TARIH BETWEEN @TARIH1 AND @TARIH2)
			AND (TARIH  BETWEEN @TARIH1 AND @TARIH2)
			AND KODU>=@ILKKOD AND KODU<=@SONKOD AND SUBEID IN (SELECT SUBEID FROM SUBELER (NOLOCK) WHERE ( CHARINDEX(CAST(SUBEID AS NVARCHAR(20)),@SUBELER)>0))
			AND FIRMAID IN (SELECT ID FROM SUBEFIRMALAR (NOLOCK) WHERE ID IN (1))
			)  TBL  ORDER BY HESAPKODU,TARIH,SUBEKODU,FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_INDIRIMSEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[PR_INDIRIMSEC] (@ORANMI INT, @FISCOUNTER INT,@INDIRIMID INT,@OTOMATIK INT, @TARIHSAAT NVARCHAR(30)) 
AS
IF @ORANMI=1
	BEGIN
		IF @OTOMATIK=0
			BEGIN
				UPDATE TADSSATIR SET 
				INDORAN=ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE  PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0),
				NETBFIYAT=NETBFIYAT/100*(100-ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN)FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE  PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)),
				NETDBFIYAT=NETDBFIYAT/100*(100-ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE  PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)),
				TUTAR=(NETBFIYAT/100*(100-ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE  PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET,
				INDTUTAR=TUTAR-((NETBFIYAT/100*(100-ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET),
				DINDTUTAR=(DBIRIMFIYAT*ADET)-((NETDBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET)
				FROM TADSSATIR WHERE FISCOUNTER=@FISCOUNTER
			END
		ELSE
			BEGIN	
				UPDATE TADSSATIR SET 
				INDORAN=ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND  PD.STOKID=TADSSATIR.STOKID),0),
				NETBFIYAT=NETBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)),
				NETDBFIYAT=NETDBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)),
				TUTAR=(NETBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET,
				INDTUTAR=TUTAR-((NETBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET),
				DINDTUTAR=(DBIRIMFIYAT*ADET)-((NETDBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET)
				FROM TADSSATIR WHERE FISCOUNTER=@FISCOUNTER
			END
	END
ELSE
	BEGIN
		IF @OTOMATIK=0
			BEGIN
				UPDATE TADSSATIR SET 
				INDORAN=ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)/NETBFIYAT*100,
				NETBFIYAT=NETBFIYAT-ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0),
				NETDBFIYAT=NETDBFIYAT-ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0),
				TUTAR=TUTAR-(ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)*ADET),
				INDTUTAR=ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=TADSSATIR.STOKID),0)*ADET,
				DINDTUTAR=(DBIRIMFIYAT*ADET)-((NETDBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET)				
				FROM TADSSATIR WHERE FISCOUNTER=@FISCOUNTER
			END
		ELSE
			BEGIN
				UPDATE TADSSATIR SET 
				INDORAN=ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND  PD.STOKID=TADSSATIR.STOKID),0)/NETBFIYAT*100,
				NETBFIYAT=NETBFIYAT-ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0),
				NETDBFIYAT=NETDBFIYAT-ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0),
				TUTAR=TUTAR-(ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)*ADET),
				INDTUTAR=ISNULL((SELECT TOP 1 ISNULL(PD.INDTUTAR,P.INDTUTAR) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)*ADET,
				DINDTUTAR=(DBIRIMFIYAT*ADET)-((NETDBFIYAT/100*(100-ISNULL((SELECT TOP 1 ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID WHERE BASLANGIC<=@TARIHSAAT AND BITIS>=@TARIHSAAT AND PD.STOKID=TADSSATIR.STOKID),0)))*ADET)				
				FROM TADSSATIR WHERE FISCOUNTER=@FISCOUNTER
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PR_INSERT_T_PROGRAMOTEL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_INSERT_T_PROGRAMOTEL]
(
    @FIRMAID INT
)
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO T_PROGRAMOTEL
    (
        PROGRAMID,
        OTELID,
        FIRMAID,
        SUBEID,
        SIRA,
		SABAHSAAT,
		OGLENSAAT,
		AKSAMSAAT,
        ADD_USERID,
        ADD_DATE
    )
    SELECT 
        P.PROGRAMID,
        O.OTELLERID,   /* kaynak */
        @FIRMAID,      /* hedefe parametre */
        P.SUBEID,
        O.SIRANO AS SIRA,
		O.STDSAAT,
		O.OGLENSAAT,
		O.AKSAMSAAT,
        0,
        GETDATE()
    FROM T_PROGRAMLAR P
    INNER JOIN T_OTELLER O 
        ON O.FIRMAID = P.FIRMAID 
       AND O.SUBEID = P.SUBEID
    WHERE ISNULL(P.SIL,0)=0 AND ISNULL(O.SIL,0)=0 AND
        P.FIRMAID = @FIRMAID
        AND O.FIRMAID = @FIRMAID
        AND NOT EXISTS
        (
            SELECT 1
            FROM T_PROGRAMOTEL PO
            WHERE PO.PROGRAMID = P.PROGRAMID
              AND PO.OTELID = O.OTELLERID
              AND PO.FIRMAID = @FIRMAID
        );
END
GO
/****** Object:  StoredProcedure [dbo].[PR_KAPANISFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_KAPANISFISI] (@SUBEID INT,@TARIH SMALLDATETIME, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME, @FISID INT, @EKLEYENID INT, @ALTCARIMI INT, @ACIKLAMA NVARCHAR(100)) AS
BEGIN
IF @ALTCARIMI=0
	BEGIN
		INSERT INTO MUH_FIS (FISID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
		VALUES (@FISID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Mahsup', 41, @ACIKLAMA,@SUBEID,'KAPANIS',0, @EKLEYENID,GETDATE(), 0, 0,'R')

		INSERT INTO MUH_HESAPISL(FISID,HESAPID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
		SELECT @FISID,  HESAPID, @ACIKLAMA, ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))) AS TUTAR,CASE WHEN  DOVIZ='TL' THEN 0 ELSE ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))) END AS DTUTAR,   
		CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0   THEN 0 ELSE SUM(ISNULL(ALACAK,0))-SUM(ISNULL(BORC,0)) END AS BORC, 
		CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0 THEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)) ELSE 0 END AS ALACAK,   
		CASE WHEN SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0)) END AS DBORC, 
		CASE WHEN SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)) END AS DALACAK,   
		CASE WHEN ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))< 0.01 OR DOVIZ='TL' THEN 0 ELSE   
		ABS((SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))/(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))) END AS KUR,ISNULL(DOVIZ,'TL'),0  
		FROM QMUH_HESAPISL WHERE TARIH BETWEEN @DONEMBASI AND @DONEMSONU AND SUBEID=@SUBEID GROUP BY HESAPID,DOVIZ HAVING ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))>0.009


		UPDATE MUH_FIS SET FISTURID=48 WHERE FISID=@FISID
		UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID

	END
ELSE IF @ALTCARIMI=1
	BEGIN
		INSERT INTO MUH_FIS (FISID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
		VALUES (@FISID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Mahsup', 41, @ACIKLAMA,@SUBEID,'KAPANIS',0, @EKLEYENID,GETDATE(), 0, 0,'R')

		INSERT INTO MUH_HESAPISL(FISID,HESAPID,ALTCARIID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
		SELECT @FISID,  HESAPID,ALTCARIID, @ACIKLAMA, ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))) AS TUTAR,CASE WHEN  DOVIZ='TL' THEN 0 ELSE ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))) END AS DTUTAR,   
		CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0   THEN 0 ELSE SUM(ISNULL(ALACAK,0))-SUM(ISNULL(BORC,0)) END AS BORC, 
		CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0 THEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)) ELSE 0 END AS ALACAK,   
		CASE WHEN SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0)) END AS DBORC, 
		CASE WHEN SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)) END AS DALACAK,   
		CASE WHEN ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))< 0.01 OR DOVIZ='TL' THEN 0 ELSE   ABS((SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))/(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))) END AS KUR,
		ISNULL(DOVIZ,'TL'),0  FROM QMUH_HESAPISL WHERE TARIH BETWEEN @DONEMBASI AND @DONEMSONU AND SUBEID=@SUBEID GROUP BY HESAPID,ALTCARIID,DOVIZ HAVING ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))>0.009

		UPDATE MUH_FIS SET FISTURID=48 WHERE FISID=@FISID
		UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_KASAGIRISCIKIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_KASAGIRISCIKIS] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
DECLARE @SQL NVARCHAR(500)
SET @SQL='SELECT HESAPADI,FISTURADI,ACIKLAMA,BORC AS TUTAR, 
KARSIHESAPADI FROM FNCQ_HESAPDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''',''100'') WHERE FISTURADI LIKE''%Tahs%'' and BORC>0
UNION ALL 
SELECT HESAPADI,FISTURADI,ACIKLAMA,ALACAK*-1 AS TUTAR, 
KARSIHESAPADI FROM FNCQ_HESAPDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''',''100'')  WHERE FISTURADI LIKE''%ödeme%'' and   ALACAK>0'
GO
/****** Object:  StoredProcedure [dbo].[PR_KASAGIRISCIKIS_SATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PR_KASAGIRISCIKIS_SATIS] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
DECLARE @SQL NVARCHAR(MAX)
SET @SQL='SELECT ''01-Nakit Satışlar'' AS ISLEM, ''Nakit'' AS ACIKLAMA, SUM(NAKIT) AS TUTAR FROM TUKETIMFIS WHERE ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+'
AND TARIH BETWEEN '''+@TARIH+''' AND '''+@TARIH2+'''
UNION ALL
SELECT ''02-Kredi Kartı Satışlar'' AS ISLEM, ''Kredi Kartı'' AS ACIKLAMA, SUM(KKARTI) AS TUTAR FROM TUKETIMFIS WHERE ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+' 
AND TARIH BETWEEN '''+@TARIH+''' AND '''+@TARIH2+'''
UNION ALL
SELECT ''03-Açık Hesap Satışlar'' AS ISLEM, FUNVANI AS ACIKLAMA, SUM(ACIK) AS TUTAR FROM TUKETIMFIS WHERE ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+' 
AND TARIH BETWEEN '''+@TARIH+''' AND '''+@TARIH2+''' GROUP BY FUNVANI
UNION ALL
SELECT ''04-Tahsilatlar'' as ISLEM, KARSIHESAPADI+'' : ''+ACIKLAMA AS ACIKLAMA,BORC AS TUTAR 
FROM FNCQ_HESAPDETAY_SATIS ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''',''100'') WHERE FISTURADI LIKE''%Tahs%'' and BORC>0
UNION ALL 
SELECT ''05-Ödemeler'' AS ISLEM,KARSIHESAPADI+'' : ''+ACIKLAMA AS ACIKLAMA,ALACAK*-1 AS TUTAR 
FROM FNCQ_HESAPDETAY_SATIS ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''',''100'')  WHERE FISTURADI LIKE''%ödeme%'' and   ALACAK>0'
EXEC(@SQL)
GO
/****** Object:  StoredProcedure [dbo].[PR_KASAGOSTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PR_KASAGOSTER]  
 @TARIH SMALLDATETIME
 AS 
SELECT DEPART.KODU AS KASAKODU, DEPART.ADI AS KASAADI, DOVIZ.KODU AS DOVIZ, 
(ISNULL((SELECT SUM(ISNULL(ADOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH<@TARIH AND DB.DEPT=DEPART.KODU AND DI.ADOVIZKODU=DOVIZ.KODU),0) 
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASAYA TAHSİLAT' AND DI.DEPT=DEPART.KODU AND DI.TARIH<@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.KDEPT=DEPART.KODU AND DI.TARIH<@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
-
(ISNULL((SELECT SUM(ISNULL(VDOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH<@TARIH AND DB.DEPT=DEPART.KODU AND DI.VDOVIZKODU=DOVIZ.KODU),0) 
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASADAN ÖDEME' AND DI.DEPT=DEPART.KODU AND DI.TARIH<@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.DEPT=DEPART.KODU AND DI.TARIH<@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
AS DDEVIR,
ISNULL((SELECT SUM(ISNULL(ADOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=@TARIH AND DB.DEPT=DEPART.KODU AND DI.ADOVIZKODU=DOVIZ.KODU),0)
AS DOVIZBOZUMALINAN,
ISNULL((SELECT SUM(ISNULL(VDOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=@TARIH AND DB.DEPT=DEPART.KODU AND DI.VDOVIZKODU=DOVIZ.KODU),0)
AS DOVIZBOZUMVERILEN,
(ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASAYA TAHSİLAT' AND DI.DEPT=DEPART.KODU AND DI.TARIH=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.KDEPT=DEPART.KODU AND DI.TARIH=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
AS KASAYATAHSILAT,
(ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASADAN ÖDEME' AND DI.DEPT=DEPART.KODU AND DI.TARIH=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.DEPT=DEPART.KODU AND DI.TARIH=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
AS KASADANODEME,

(ISNULL((SELECT SUM(ISNULL(ADOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH<=@TARIH AND DB.DEPT=DEPART.KODU AND DI.ADOVIZKODU=DOVIZ.KODU),0) 
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASAYA TAHSİLAT' AND DI.DEPT=DEPART.KODU AND DI.TARIH<=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.KDEPT=DEPART.KODU AND DI.TARIH<=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
-
(ISNULL((SELECT SUM(ISNULL(VDOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH<=@TARIH AND DB.DEPT=DEPART.KODU AND DI.VDOVIZKODU=DOVIZ.KODU),0) 
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASADAN ÖDEME' AND DI.DEPT=DEPART.KODU AND DI.TARIH<=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0)
+
ISNULL((SELECT SUM(ISNULL(DOVIZTUTAR,0)) AS DDEVIR FROM KASAMUH AS DI WHERE ISLEMTURU='KASA VİRMAN' AND DI.DEPT=DEPART.KODU AND DI.TARIH<=@TARIH AND DI.DOVIZKODU=DOVIZ.KODU),0))
AS BAKIYE
  
FROM DEPART,DOVIZ WHERE DEPART.KODU IN('90','91')
GO
/****** Object:  StoredProcedure [dbo].[PR_KREDIANAENTEGRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_KREDIANAENTEGRE]  
@BANKAKREDIID INT
AS
BEGIN
		SELECT BANKAKREDIID, BANKAID AS HESAPID, BANKAKODU as HESAPKODU,BANKAADI AS HESAPADI, 'Kredi Ana Para' AS ACIKLAMA, SUM(ANAPARA) AS TUTAR, SUM(ANAPARA) AS BORC, 0.00 AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ   --KREDI ANA TUTAR
		WHERE BANKAKREDIID=@BANKAKREDIID
		GROUP BY BANKAID,BANKAADI,BANKAKODU, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,GELECEKGIDERID,  GELECEKGIDERHESAPKODU, GELECEKGIDERHESABI, 'Kredi Dönem Faizi' as ACIKLAMA, SUM(TFAIZ) AS TUTAR, SUM(TFAIZ) AS BORC, 0.00 AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ  --KREDI BU YIL FAIZI
		WHERE YEAR(TAKSITARIHI)=YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY GELECEKGIDERID, GELECEKGIDERHESABI, GELECEKGIDERHESAPKODU, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,GELECEKGIDERID2, GELECEKGIDERHESAPKODU2, GELECEKGIDERHESABI2, 'Kredi Gelecek dönem faizi' as ACIKLAMA, SUM(TFAIZ) AS TUTAR,  SUM(TFAIZ) AS BORC, 0.00 AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ --KREDI GELECEK YILLAR FAIZI
		WHERE YEAR(TAKSITARIHI)>YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY GELECEKGIDERID2, GELECEKGIDERHESABI2, GELECEKGIDERHESAPKODU2, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,ANAPARAHESAPID, ANAPARAHESAPKODU, ANAPARAHESABI, 'Kredi Dönem Ana Para Taksit Tutarı' as ACIKLAMA, SUM(ANAPARA)  AS TUTAR,  0.00 AS BORC,  SUM(ANAPARA)  AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ --KREDININ BU YIL ANA PARA TAKSITLERI
		WHERE YEAR(TAKSITARIHI)=YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY ANAPARAHESAPID, ANAPARAHESABI, ANAPARAHESAPKODU, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,FAIZHESAPID, FAIZHESAPKODU, FAIZHESABI, 'Kredi Dönem Faiz Tutarı' as ACIKLAMA, SUM(TFAIZ)  AS TUTAR, 0.00 AS BORC, SUM(TFAIZ)  AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ  --KREDININ BU YIL FAIZ TUTARLARI
		WHERE YEAR(TAKSITARIHI)=YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY FAIZHESAPID, FAIZHESABI, FAIZHESAPKODU, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,GELECEKANAPARAHESAPID, GELECEKANAPARAHESAPKODU, GELECEKANAPARAHESABI, 'Kredi Gelecek yıllar ana para' as ACIKLAMA, SUM(ANAPARA)  AS TUTAR,  0.00 AS BORC, SUM(ANAPARA)  AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ  --KREDININ GELECEK YILLAR ANA PARA TUTARI
		WHERE YEAR(TAKSITARIHI)>YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY GELECEKANAPARAHESAPID, GELECEKANAPARAHESABI, GELECEKANAPARAHESAPKODU, MUHFISID_KREDI,BANKAKREDIID
		UNION ALL
		SELECT BANKAKREDIID,FAIZHESAPID2, FAIZHESAPKODU2, FAIZHESABI2, 'Kredi Gelecek dönem Faiz Tutar' AS ACIKLAMA, SUM(TFAIZ)  AS TUTAR, 0.00 AS BORC, SUM(TFAIZ)  AS ALACAK, MUHFISID_KREDI FROM FU_KREDIANALIZ  --KREDININ GELECEK YILLAR FAIZ TUTARI
		WHERE YEAR(TAKSITARIHI)>YEAR(GETDATE()) AND BANKAKREDIID=@BANKAKREDIID
		GROUP BY FAIZHESAPID2, FAIZHESABI2, FAIZHESAPKODU2, MUHFISID_KREDI,BANKAKREDIID
END
GO
/****** Object:  StoredProcedure [dbo].[PR_KREDIHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_KREDIHESAPLA] (@BANKAKREDIID INT,@KREDITARIHI SMALLDATETIME,@KREDITUTAR FLOAT,@TAKSITSAYISI INT,@FAIZORAN FLOAT,@KKDFORAN FLOAT,@BSMVORAN FLOAT) AS
BEGIN
DECLARE 
@TAKSITTUTAR FLOAT,
@ANAPARATUTAR FLOAT,
@FAIZTUTAR FLOAT,
@KKDFTUTAR FLOAT,
@BSMVTUTAR FLOAT,
@KALANANAPARA FLOAT,
@TAKSITTARIH SMALLDATETIME,
@FAIZTOPLAMORAN FLOAT,
@SAYAC INT																					
																							
SET @SAYAC=1
SET @FAIZTOPLAMORAN=(@FAIZORAN+(@FAIZORAN*@KKDFORAN)+(@FAIZORAN*@BSMVORAN))/100
while @SAYAC<@TAKSITSAYISI+1
	BEGIN
		 
		SET @TAKSITTUTAR =  @KREDITUTAR * (@FAIZTOPLAMORAN*POWER((1+@FAIZTOPLAMORAN),@TAKSITSAYISI))  / (POWER((1+@FAIZTOPLAMORAN),@TAKSITSAYISI)-1);
		IF @SAYAC=1 SET @FAIZTUTAR = (@KREDITUTAR *@FAIZORAN*1)/100
		IF @SAYAC=1 SET @KKDFTUTAR = (@FAIZTUTAR * @KKDFORAN)
		IF @SAYAC=1 SET @BSMVTUTAR = (@FAIZTUTAR * @BSMVORAN)
		IF @SAYAC=1 SET @ANAPARATUTAR = @TAKSITTUTAR-(@FAIZTUTAR+@KKDFTUTAR+@BSMVTUTAR)
		
		IF @SAYAC=1 SET @KALANANAPARA = @KREDITUTAR-@ANAPARATUTAR


		IF @SAYAC<>1 SET @FAIZTUTAR = (@KALANANAPARA *@FAIZORAN*1)/100
		IF @SAYAC<>1 SET @KKDFTUTAR = (@FAIZTUTAR * @KKDFORAN)
		IF @SAYAC<>1 SET @BSMVTUTAR = (@FAIZTUTAR * @BSMVORAN)
		IF @SAYAC<>1 SET @ANAPARATUTAR = @TAKSITTUTAR-(@FAIZTUTAR+@KKDFTUTAR+@BSMVTUTAR)
		
		IF @SAYAC<>1 SET @KALANANAPARA = @KALANANAPARA-@ANAPARATUTAR

		SET @TAKSITTARIH=DATEADD(MONTH,+@SAYAC,@KREDITARIHI)
		INSERT INTO BANKAKREDIDETAY (BANKAKREDIID,TAKSITNO, TARIH, TAKSITTUTARI,FAIZ,KKDF,BSMV,ANAPARA,KALANANAPARA) SELECT @BANKAKREDIID AS BANKAKREDIID,@SAYAC AS TAKSIT, @TAKSITTARIH AS TARIH, @TAKSITTUTAR AS TAKSITTUTAR, @FAIZTUTAR AS FAIZTUTAR, @KKDFTUTAR AS KKDFTUTAR, @BSMVTUTAR AS BSMVTUTAR, @ANAPARATUTAR AS ANAPARATUTRA, @KALANANAPARA AS KALANANAPARA

		SET @SAYAC = @SAYAC + 1
	END
--UPDATE BANKAKREDIDETAY SET TAKSITTUTARI=(SELECT @KREDITUTAR+SUM(FAIZ)+SUM(KKDF)+SUM(BSMV) FROM BANKAKREDIDETAY WHERE BANKAKREDIID=@BANKAKREDIID)/@TAKSITSAYISI WHERE BANKAKREDIID=@BANKAKREDIID		
END
GO
/****** Object:  StoredProcedure [dbo].[PR_KURFARKI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PR_KURFARKI]  
 @TARIH SMALLDATETIME
 AS 
SELECT D.KODU AS KASAKODU, D.ADI AS KASADI,DV.KODU AS DOVIZ, 
ISNULL((SELECT AVG(KUR) FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND ADOVIZTUTAR>0 AND DB.DEPT=D.KODU AND DI.ADOVIZKODU=DV.KODU),0)
AS ALISKURORTLAMASI,
ISNULL((SELECT AVG(VKUR) FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID  WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND VDOVIZTUTAR>0 AND DB.DEPT=D.KODU AND DI.VDOVIZKODU=DV.KODU),0)
AS SATISKURORTLAMASI,
ISNULL((SELECT SUM(ISNULL(ADOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND DB.DEPT=D.KODU AND DI.ADOVIZKODU=DV.KODU),0) 
AS GIRENDVZ,
ISNULL((SELECT SUM(ISNULL(VDOVIZTUTAR,0)) AS DDEVIR FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND DB.DEPT=D.KODU AND DI.VDOVIZKODU=DV.KODU),0)
AS CIKANDVZ,
ISNULL((SELECT AVG(VKUR) FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND VDOVIZTUTAR>0 AND DB.DEPT=D.KODU AND DI.VDOVIZKODU=DV.KODU),0)
-
ISNULL((SELECT AVG(KUR) FROM DOVIZBOZISL AS DI INNER JOIN DOVIZBOZ AS DB ON DI.DOVIZBOZID=DB.DOVIZBOZID  WHERE ISNULL(DB.SIL,0)=0 AND DB.TARIH=TAKVIM.TARIH AND ADOVIZTUTAR>0 AND DB.DEPT=D.KODU AND DI.ADOVIZKODU=DV.KODU),0)
AS KURFARKI
FROM DEPART AS D, DOVIZ AS DV, TAKVIM
WHERE D.KODU='90' AND DV.KODU IN('EURO','USD','GBP') AND TARIH=@TARIH
GO
/****** Object:  StoredProcedure [dbo].[PR_LOGINKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_LOGINKONTROL]  @FIRMAKODU NVARCHAR(20), @KULLANICIKODU NVARCHAR(30), @SIFRESI NVARCHAR(30)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(200)
IF @KULLANICIKODU='XXX***'
	BEGIN
		SET @SQLCUMLE='SELECT  * FROM NOVAUSER WITH (NOLOCK) WHERE 1=1 AND ISNULL(SIL,0)=0 
		AND FIRMAID=(SELECT FIRMAID FROM FIRMALAR WHERE FIRMAKODU='''+@FIRMAKODU+''')'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT  * FROM NOVAUSER WITH (NOLOCK) WHERE 1=1 AND ISNULL(SIL,0)=0 
		AND FIRMAID=(SELECT FIRMAID FROM FIRMALAR WHERE FIRMAKODU='''+@FIRMAKODU+''') AND KODU='''+@KULLANICIKODU+''' AND SIFRESI='''+@SIFRESI+''''
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_MALIYETHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_MALIYETHESAPLA]  
@FISID INT,
@TABLOADI NVARCHAR(20)
AS
BEGIN

IF @TABLOADI='FATURA'
	BEGIN
		
		IF (SELECT FISTURID FROM FATURA WHERE FATID=@FISID)=51
			BEGIN
				 UPDATE STOK
				 SET STOK.KARY=100-(( (STOK.SFIYAT1/(100+SATISKDV)*100)/ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT))*100),
				 STOK.SALISFIYAT  = ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT),
				 STOK.SALISBFIYAT = QMUH_STOKSONALIS.BFIYAT,
				 STOK.SONALISF    = QMUH_STOKSONALIS.BFIYAT,
				 STOK.MALIYET     = QMUH_STOKSONALIS.NFIYAT/100*(100+SONKDV),
				 STOK.SALISFBIRIM = QMUH_STOKSONALIS.SONABIRIM,
				 STOK.SALISFBFIYAT = QMUH_STOKSONALIS.NFBFIYAT,
				 STOK.SSATICI     = QMUH_STOKSONALIS.CARIID,
				 STOK.SFATTARIHI       = QMUH_STOKSONALIS.TARIH,
				 STOK.SFATURANO       = QMUH_STOKSONALIS.FATNO
				 FROM STOK INNER JOIN QMUH_STOKSONALIS ON
				 STOK.STOKID = QMUH_STOKSONALIS.STOKID WHERE 
				 QMUH_STOKSONALIS.STOKID IN(SELECT DISTINCT STOKID FROM FATISL WHERE FATID=@FISID) AND
				 CARIUNVANI<>'SAYIM' AND QMUH_STOKSONALIS.NFIYAT>0
			END

		UPDATE FATISL SET FATISL.BMALIYET=STOK.SALISFIYAT, FATISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		FATISL.BKATSAYI=(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		FATISL.ADET=FADET*(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		FATISL.BFIYAT=FBFIYAT/(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM FATISL INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID WHERE FATISL.FATID=@FISID

	END
ELSE IF @TABLOADI='DEPOFIS'
	BEGIN
		UPDATE DEPOFISISL SET DEPOFISISL.BMALIYET=STOK.SALISFIYAT, DEPOFISISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		DEPOFISISL.BKATSAYI=(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		DEPOFISISL.MIKTAR=FMIKTAR*(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		DEPOFISISL.BFIYAT=FBFIYAT/(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID WHERE DEPOFISISL.DEPOFISID=@FISID
	END
ELSE IF @TABLOADI='TUKETIMFIS'
	BEGIN
		UPDATE TUKETIMFISISL SET TUKETIMFISISL.BMALIYET=STOK.SALISFIYAT, TUKETIMFISISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		TUKETIMFISISL.BKATSAYI=(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		TUKETIMFISISL.MIKTAR=FMIKTAR*(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		TUKETIMFISISL.BFIYAT=FBFIYAT/(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID WHERE TUKETIMFISISL.DEPOFISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_MALIYETHESAPLA_STOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_MALIYETHESAPLA_STOK]  
@FISID INT,
@STOKID INT,
@FBIRIM NVARCHAR(20),
@KATSAYI FLOAT,
@TABLOADI NVARCHAR(20)
AS
BEGIN

IF @TABLOADI='FATURA'
	BEGIN
		
		IF (SELECT FISTURID FROM FATURA WHERE FATID=@FISID)=51
			BEGIN
				 UPDATE STOK
				 SET STOK.KARY=100-(( (STOK.SFIYAT1/(100+SATISKDV)*100)/ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT))*100),
				 STOK.SALISFIYAT  = ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT),
				 STOK.SALISBFIYAT = QMUH_STOKSONALIS.BFIYAT,
				 STOK.SONALISF    = QMUH_STOKSONALIS.BFIYAT,
				 STOK.MALIYET     = QMUH_STOKSONALIS.NFIYAT/100*(100+SONKDV),
				 STOK.SALISFBIRIM = QMUH_STOKSONALIS.SONABIRIM,
				 STOK.SALISFBFIYAT = QMUH_STOKSONALIS.NFBFIYAT,
				 STOK.SSATICI     = QMUH_STOKSONALIS.CARIID,
				 STOK.SFATTARIHI       = QMUH_STOKSONALIS.TARIH,
				 STOK.SFATURANO       = QMUH_STOKSONALIS.FATNO
				 FROM STOK INNER JOIN QMUH_STOKSONALIS ON
				 STOK.STOKID = QMUH_STOKSONALIS.STOKID WHERE 
				 QMUH_STOKSONALIS.STOKID IN(SELECT DISTINCT STOKID FROM FATISL WHERE FATID=@FISID AND STOKID=@STOKID) AND
				 CARIUNVANI<>'SAYIM' AND QMUH_STOKSONALIS.NFIYAT>0
			END

		UPDATE FATISL SET FATISL.BMALIYET=STOK.SALISFIYAT, FATISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		FATISL.BKATSAYI=@KATSAYI,
		
		FATISL.ADET=FADET*@KATSAYI,
		
		FATISL.BFIYAT=FBFIYAT/@KATSAYI,
		
		FATISL.FBIRIM=@FBIRIM
		
		FROM FATISL INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID WHERE FATISL.FATID=@FISID AND  FATISL.STOKID=@STOKID

	END
ELSE IF @TABLOADI='DEPOFIS'
	BEGIN
		UPDATE DEPOFISISL SET DEPOFISISL.BMALIYET=STOK.SALISFIYAT, DEPOFISISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		DEPOFISISL.BKATSAYI=@KATSAYI,
		
		DEPOFISISL.MIKTAR=FMIKTAR*@KATSAYI,
		
		DEPOFISISL.BFIYAT=FBFIYAT/@KATSAYI,
		
		DEPOFISISL.FBIRIM=@FBIRIM
				
		FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID WHERE DEPOFISISL.DEPOFISID=@FISID AND DEPOFISISL.STOKID=@STOKID
	END
ELSE IF @TABLOADI='TUKETIMFIS'
	BEGIN
		UPDATE TUKETIMFISISL SET TUKETIMFISISL.BMALIYET=STOK.SALISFIYAT, TUKETIMFISISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		TUKETIMFISISL.BKATSAYI=@KATSAYI,
		
		TUKETIMFISISL.MIKTAR=FMIKTAR*@KATSAYI,
		
		TUKETIMFISISL.BFIYAT=FBFIYAT/@KATSAYI,

		TUKETIMFISISL.FBIRIM=@FBIRIM
		
		
		FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID WHERE TUKETIMFISISL.DEPOFISID=@FISID AND TUKETIMFISISL.STOKID=@STOKID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_MARKETAKTARIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_MARKETAKTARIM] AS
GO
/****** Object:  StoredProcedure [dbo].[PR_MUTABAKAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_MUTABAKAT]  
@ILKTARIH SMALLDATETIME,
@SONTARIH SMALLDATETIME
AS
BEGIN
SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEM, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEMSONU, 

 SUM(CASE WHEN TARIH>@SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS SONRAKIDONEM, 

 SUM(BORC-ALACAK) AS SONBAKIYE, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END) AS DONCEKIDONEM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN DBORC-DALACAK ELSE 0 END) AS DDONEM, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DDONEMSONU, 

 SUM(CASE WHEN TARIH>@SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DSONRAKIDONEM, 

 SUM(DBORC-DALACAK) AS DSONBAKIYE, 

  

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
 FROM QMUH_HESAPISL2        
 INNER JOIN 
 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
       AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
	   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
	   WHERE 1=1  AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
END
GO
/****** Object:  StoredProcedure [dbo].[PR_NOVABMS_YEVMIYENOVER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_NOVABMS_YEVMIYENOVER]  
(@SUBEID INT, @ESKIYEVMNOSIL BIT,@USERID INT,@DONEMBASI DATETIME,@DONEMSONU DATETIME,@BASTARIH DATETIME,@BITTARIH DATETIME)
AS
BEGIN


  IF @DONEMBASI=NULL
  BEGIN
   RAISERROR('Dönem Bilgileri Olmadan Yevmiye No Verilemez',16,1)
   RETURN 1
  END

  -- Bu işi Try içinde transaction ile yapalım ne olur ne olmaz
  BEGIN TRY  

  DECLARE @Trans VARCHAR(20);  
  SELECT @Trans = 'YevmiyeNoVerelim';  

  BEGIN TRANSACTION @Trans

  IF ISNULL(@ESKIYEVMNOSIL,0)=1
  BEGIN
   UPDATE MUH_FIS SET FISDURUMID=ISNULL(ESKIFISDURUMID,1), -- eski fişdurumu zaten tutmustuk yoksa 1 muhasebeleştiye alıyoruz
   YEVMNO=NULL,YEVMTARIH=NULL,YEVMACIKLAMA=NULL ,YEVSATIRSIRANO=NULL
   WHERE ISNULL(SIL,0)=0 AND  ISNULL(FISDURUMID,0)>-1 AND YEVMNO IS NOT NULL AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID IN (SELECT SUBEID FROM SUBELER WHERE SUBEID=@SUBEID)

   UPDATE MUH_HESAPISL
   SET YEVSATIRSIRANO=NULL
   WHERE FISID IN 
   (
   SELECT FISID FROM MUH_FIS WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID IN (SELECT SUBEID FROM SUBELER WHERE SUBEID=@SUBEID)
   )
  END

  -- O dönem içindeki en son yevmiyenoyu bir bulalım not edelim 
  DECLARE @SONYEVMNO INT  
  SELECT @SONYEVMNO = MAX(ISNULL(CONVERT(INT,YEVMNO),0)) FROM MUH_FIS 
  WHERE ISNULL(SIL,0)=0 AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  AND SUBEID IN (SELECT SUBEID FROM SUBELER WHERE SUBEID=@SUBEID)

  -- hadi artık no verelim 
   UPDATE MUH_FIS 
   SET  
   MUH_FIS.EDIT_USERID  =  @USERID,
   MUH_FIS.EDIT_DATE    =  GetDate(),
   MUH_FIS.YEVMNO       = TBLYEV.YEVMNO, 
   MUH_FIS.ESKIFISDURUMID   =  TBLYEV.FISDURUMID,
   MUH_FIS.FISDURUMID   =  3,
   MUH_FIS.YEVMTARIH    = TBLYEV.TARIH, 
   MUH_FIS.YEVMACIKLAMA = TBLYEV.ACIKLAMA 
   FROM MUH_FIS INNER JOIN 
   (
	 SELECT (ROW_NUMBER() OVER (ORDER BY TARIH,SIRA,FISTURID,FISID))+@SONYEVMNO AS YEVMNO,FISTURU, 
	 TARIH,ACIKLAMA,FISID,FISTURID,SUBEID,FISDURUMID FROM 
	 (
	  -- Açılış Fişi ilk önce olmalı 
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU,-1 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS  
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (49) -- Varsa diğer şartlar
	  -- Dönem Fişlerini ekleyelim
	  UNION ALL 
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU,0 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS 
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
	   AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID NOT IN (48,49)
	  -- Kapanış Fişi en Sonra olmalı
	  UNION ALL
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU, 1 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS  
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (48) -- Varsa diğer şartlar
	 ) TBL
   ) TBLYEV  ON MUH_FIS.FISID=TBLYEV.FISID
  WHERE ISNULL(MUH_FIS.SIL,0)=0 AND  MUH_FIS.SUBEID=@SUBEID AND MUH_FIS.TARIH BETWEEN @DONEMBASI AND @DONEMSONU AND ISNULL(MUH_FIS.YEVMNO,0)=0 AND MUH_FIS.TARIH<=@BITTARIH  
 
  COMMIT TRANSACTION @Trans
 
  DECLARE @SATIRYEVMNO INT
 
  
 --EVE VERELİM Mİ NUMARA DÜŞÜNÜYORUM SIRALI OLMAYACAK BU COZER AMA SIRA OLMAZ
  DECLARE @CFISID INT
  DECLARE @CTARIH DATETIME
  DECLARE FIS_CURSOR CURSOR FOR 
  SELECT FISID,TARIH  FROM 
  (
    -- Açılış Fişi ilk önce olmalı 
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU,-1 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS  
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (49) -- Varsa diğer şartlar
	  -- Dönem Fişlerini ekleyelim
	  UNION ALL 
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU,0 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS 
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
	   AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID NOT IN (48,49)
	  -- Kapanış Fişi en Sonra olmalı
	  UNION ALL
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURADI,FISTURU, 1 AS SIRA,SUBEID,FISDURUMID FROM QMUH_FIS  
	  WHERE  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (48) -- Varsa diğer şartlar
  ) TBLFIS 
  ORDER BY YEVMNO --,TARIH  --SIRA
  OPEN FIS_CURSOR 
  FETCH NEXT FROM FIS_CURSOR INTO @CFISID,@CTARIH   

  WHILE (@@FETCH_STATUS=0 )
  BEGIN
    -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
    SELECT @SATIRYEVMNO=ISNULL(MAX(YEVSATIRSIRANO),0) FROM QMUH_HESAPISL2  
    WHERE  SUBEID=@SUBEID AND TARIH<=@CTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  

	  -- hadi satırlarada numara verelim
	  UPDATE MUH_HESAPISL SET YEVSATIRSIRANO=SATIRNO FROM MUH_HESAPISL 
	  INNER JOIN 
	  (
	   SELECT ISLEMID,(ROW_NUMBER() OVER (ORDER BY CASE WHEN MUH_HESAPISL.ALACAK>0 THEN 1 ELSE 0 END,MUH_HESAP.KODU,ISLEMID))+@SATIRYEVMNO AS SATIRNO  FROM MUH_HESAPISL 
	   INNER JOIN MUH_HESAP ON MUH_HESAP.HESAPID=MUH_HESAPISL.HESAPID 
	   WHERE MUH_HESAPISL.FISID=@CFISID AND abs(FISID)>0 AND ISNULL(MUH_HESAPISL.SILINDI,0)=0) TBL 
	   ON MUH_HESAPISL.ISLEMID=TBL.ISLEMID

	  -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
	 -- SELECT @SATIRYEVMNO=MAX(YEVSATIRSIRANO) FROM QMUH_HESAPISL2  
	 -- WHERE  SUBEID=@SUBEID AND TARIH<@BASTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  
	  -- hadi başlıklara numara verelim
    -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
     SELECT @SATIRYEVMNO=ISNULL(MAX(YEVSATIRSIRANO),0) FROM QMUH_HESAPISL2  
     WHERE  SUBEID=@SUBEID AND TARIH<=@CTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  
	 UPDATE MUH_FIS SET YEVSATIRSIRANO=SATIRNO FROM MUH_FIS
	  INNER JOIN 
	  (
	   SELECT FISID,(ROW_NUMBER() OVER (ORDER BY CASE WHEN QMUH_HESAPISL2.ALACAK>0 THEN 1 ELSE 0 END,MUH_HESAP.KODU,ISLEMID))+@SATIRYEVMNO AS SATIRNO  FROM QMUH_HESAPISL2  
	   INNER JOIN MUH_HESAP ON MUH_HESAP.HESAPID=QMUH_HESAPISL2.HESAPID 
	   WHERE ISNULL(SIL,0)=0 AND FISID=@CFISID AND abs(FISID)>0 AND FISHESAPID IS NOT NULL
	  ) AS TBL2 ON MUH_FIS.FISID=TBL2.FISID

  FETCH NEXT FROM FIS_CURSOR INTO @CFISID ,@CTARIH
  END 

  CLOSE FIS_CURSOR 
  DEALLOCATE FIS_CURSOR 
 
  SELECT 0 HataNo,'' HataMesaji
  END TRY 
  BEGIN CATCH  
    -- Execute error retrieval routine.
	
    CLOSE FIS_CURSOR 
    DEALLOCATE FIS_CURSOR 
    
    ROLLBACK TRANSACTION @Trans
    SELECT  
     ERROR_NUMBER() AS HataNo
    ,ERROR_MESSAGE() AS HataMesaji  
 END CATCH;   


 END
GO
/****** Object:  StoredProcedure [dbo].[PR_OKCFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PR_OKCFIS]  
@DEPOFISID INT
AS
BEGIN
		SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
		WHERE ISNULL(SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID GROUP BY
		TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
END
GO
/****** Object:  StoredProcedure [dbo].[PR_OKCFIS_2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PR_OKCFIS_2]  
@DEPOFISID INT,
@MARKA NVARCHAR(15),
@SATISMODUL NVARCHAR(20)
AS
BEGIN
IF (@SATISMODUL='SATIS') and (@MARKA='HUGIN')
	BEGIN	
		SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
		WHERE DEPOFISID=@DEPOFISID GROUP BY
		TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
	END
IF (@SATISMODUL='SATIS') and (@MARKA='BEKO')
	BEGIN	
		SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
		SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
		WHERE DEPOFISID=@DEPOFISID GROUP BY
		TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
	END
IF (@SATISMODUL='POSSATIS') AND (@MARKA='HUGIN')
	BEGIN
		SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
		WHERE TI.FISCOUNTER=@DEPOFISID GROUP BY
		TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
	END
IF (@SATISMODUL='POSSATIS_PARCALI') AND (@MARKA='HUGIN')
	BEGIN
		SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN STOKGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGURUBU=GG2.KODU 
		WHERE TI.FISCOUNTER=@DEPOFISID GROUP BY
		TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
	END
IF (@SATISMODUL='POSSATIS') AND (@MARKA='BEKO')
	BEGIN
		SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
		ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN)))  AS BFIYAT,  
		SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN)))  AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
		INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
		LEFT JOIN STOKGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
		LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
		LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGURUBU=GG2.KODU 
		WHERE DEPOFISID=@DEPOFISID GROUP BY
		TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_POSENTEGRASYON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_POSENTEGRASYON]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@EKLEYEN INT,
@KASAHESAPID INT,
@BANKAHESAPID INT,
@KDVDAHILMI INT
AS
BEGIN
DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSENTEGRE')
DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSENTEGRE'
if (SELECT ISNULL(COUNT(*),0) FROM QMUH_ADISYONISLEM WHERE ISNULL(MUHGHESAPID,0)=0 AND TARIH=@TARIH)>0
	BEGIN
		RAISERROR('ÜRÜN GRUP GELİR HESABI TANIMLI DEĞİL',1,16)
	END
ELSE
	BEGIN
		INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
		VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Günlük Pos Satış Entegrasyonu',1,'TL',1,@TOPLAM,0.00,'POSENTEGRE')
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
		SELECT @FISID, @KASAHESAPID AS  HESAPID, 'Günlük Nakit Satış' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(NAKITODEME) AS TUTAR,
		0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, SUM(NAKITODEME) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_ADISYONISLEM WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ'
		UNION ALL
		SELECT @FISID, @BANKAHESAPID AS  HESAPID, 'Günlük Kredi Kartı Satış' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(KKODEME) AS TUTAR,
		0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, SUM(KKODEME) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_ADISYONISLEM WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ'
		UNION ALL
		SELECT @FISID, CARIHESAPID AS  HESAPID, 'Günlük Açık Hesap Satış' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(ACIKODEME) AS TUTAR,
		0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, SUM(ACIKODEME) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_ADISYONISLEM WHERE ISNULL(CARIHESAPID,0)<>0 AND SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ' GROUP BY CARIHESAPID
		IF @KDVDAHILMI=1
			BEGIN
				INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
				SELECT @FISID, MUHGHESAPID AS  HESAPID, 'Günlük Satış Geliri' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(TSATIS) AS TUTAR,
				0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, 0.00 AS BORC, SUM(TSATIS) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
				FROM QMUH_ADISYONISLEM WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ' GROUP BY MUHGHESAPID
			END
		ELSE IF @KDVDAHILMI=0
			BEGIN
				INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
				SELECT @FISID, MUHGHESAPID AS  HESAPID, 'Günlük Satış Geliri' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(TSATIS)/100+ISNULL(STOKKDVORANI,0)*100 AS TUTAR,
				0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, 0.00 AS BORC, SUM(TSATIS)/(100+ISNULL(STOKKDVORANI,0))*100 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
				FROM QMUH_ADISYONISLEM WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ' GROUP BY MUHGHESAPID,STOKKDVORANI
				UNION ALL
				SELECT @FISID, SATISHESAPID AS  HESAPID, 'Günlük Kdv Tutarı' AS ACIKLAMA, 'TL' AS DOVIZ, 'POSENTEGRE' AS OZELKOD1, SUM(TSATIS)/100+ISNULL(STOKKDVORANI,0)*ISNULL(STOKKDVORANI,0) AS TUTAR,
				0.00 AS DTUTAR, SUM(ADET) AS MIKTAR, 0.00 AS BORC, SUM(TSATIS)/(100+ISNULL(STOKKDVORANI,0))*ISNULL(STOKKDVORANI,0) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
				FROM QMUH_ADISYONISLEM WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  TUR<>'ODENMEZ' GROUP BY SATISHESAPID,STOKKDVORANI
			END

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_POSENTEGRASYONSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_POSENTEGRASYONSIL]  
@TARIH SMALLDATETIME,
@SUBEID INT
AS
BEGIN
	DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSENTEGRE')
	DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSENTEGRE'
END
GO
/****** Object:  StoredProcedure [dbo].[PR_RECETEMALIYET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_RECETEMALIYET]  
@KULLANICI NVARCHAR(2)
AS
BEGIN
--1
--3
UPDATE STOK   SET MALIYET=0     , SONMALIYET =0    
WHERE TURU <> 'Hammadde' AND STOKID IN(SELECT DISTINCT URUNID FROM RECETE)
--3
UPDATE STOK   SET SONMALIYET=MALIYET    
WHERE TURU <> 'Hammadde' AND STOKID NOT IN(SELECT DISTINCT URUNID FROM RECETE)
--4
UPDATE STOK   SET RECETEKATSAYISI=1 WHERE RECETEKATSAYISI=0 OR RECETEKATSAYISI IS NULL 
--5
UPDATE STOK   SET KISISAYISI=1      WHERE KISISAYISI=0 OR KISISAYISI IS NULL  
--6
UPDATE RECETE SET RECETE.RECETEKATSAYISI=STOK.RECETEKATSAYISI FROM STOK INNER JOIN RECETE ON STOK.STOKID=RECETE.STOKID 
--7
UPDATE RECETE SET RECETEKATSAYISI=1 WHERE RECETEKATSAYISI=0 OR RECETEKATSAYISI IS NULL   
--8
UPDATE RECETE  SET RECETE.BMALIYET    = ISNULL(TBL.ORTFIYAT,RECETE.BMALIYET) FROM RECETE INNER JOIN 
 (SELECT STOKID,ROUND(SUM(NFIYAT*GCADET)/SUM(GCADET),5) AS ORTFIYAT 
  FROM QMUH_STOKISLSAYIM 
  WHERE (FISTIPI IN('FATURA','SAYIM') OR ISLEM='ÜRETİM') AND GCADET>0 
  AND TURU='Hammadde' 
  GROUP BY STOKID,ALISKDV  
  HAVING SUM(GCADET)<>0 ) AS TBL  
 ON RECETE.STOKID = TBL.STOKID 
--9
UPDATE RECETE 
 SET RECETE.BMALIYET    = ISNULL(TBL.ORTFIYAT,RECETE.BMALIYET) 
 FROM RECETE INNER JOIN 
 (SELECT STOKID,ROUND(SUM(NFIYAT*GCADET)/SUM(GCADET),5) AS ORTFIYAT 
  FROM QMUH_STOKISL 
  WHERE (FISTIPI IN('FATURA','SAYIM') OR ISLEM='ÜRETİM') AND GCADET>0 
  AND TURU='Hammadde' 
  GROUP BY STOKID,ALISKDV  
  HAVING SUM(GCADET)<>0 ) AS TBL  
 ON RECETE.STOKID = TBL.STOKID WHERE ISNULL(RECETE.BMALIYET,0)=0
--10
UPDATE RECETE SET RECETE.SONBMALIYET=ISNULL(STOK.SALISFIYAT,RECETE.SONBMALIYET) 
 FROM RECETE INNER JOIN STOK ON RECETE.STOKID = STOK.STOKID AND STOK.TURU='Hammadde' 
--11
UPDATE RECETE SET RECETE.SONBMALIYET=ISNULL((STOK.SONMALIYET* (1/STOK.RECETEKATSAYISI)/KISISAYISI),RECETE.SONBMALIYET), 
RECETE.BMALIYET=ISNULL((STOK.MALIYET * (1/STOK.RECETEKATSAYISI)/KISISAYISI),RECETE.SONBMALIYET) 
 FROM RECETE INNER JOIN STOK ON RECETE.STOKID = STOK.STOKID AND STOK.TURU<>'Hammadde' 
UPDATE STOK SET 
 MALIYET    =(SELECT SUM( ORAN * BMALIYET    * (1/S.RECETEKATSAYISI)   ) 
              FROM RECETE LEFT OUTER JOIN STOK S ON S.STOKID=RECETE.STOKID        
                          LEFT OUTER JOIN STOK U ON U.STOKID=RECETE.URUNID        
              WHERE RECETE.URUNID=STOK.STOKID ),                                  
 SONMALIYET =(SELECT SUM( ORAN * SONBMALIYET * (1/S.RECETEKATSAYISI)   ) 
              FROM RECETE LEFT OUTER JOIN STOK S ON S.STOKID=RECETE.STOKID        
                          LEFT OUTER JOIN STOK U ON U.STOKID=RECETE.URUNID        
              WHERE RECETE.URUNID=STOK.STOKID )                                   
WHERE TURU <>'Hammadde' AND STOKID IN(SELECT DISTINCT URUNID FROM RECETE)
 END
GO
/****** Object:  StoredProcedure [dbo].[PR_SATISENTEGRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_SATISENTEGRE]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@MASMERID INT,
@DEPOID INT,
@EKLEYEN INT
AS
BEGIN
	IF (SELECT ISNULL(SUM(TOPLAM),0) FROM FU_TUKETIMANALIZ WHERE (ACIKLAMA LIKE'%NAKİT' OR ACIKLAMA LIKE'%KARTI%') AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID)>0
		BEGIN	
				DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE ISLEMGRUPID3=@DEPOID AND SUBEID=@SUBEID AND MASMERID=@MASMERID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SATISMAHSUBU')
				DELETE FROM MUH_FIS WHERE ISLEMGRUPID3=@DEPOID AND SUBEID=@SUBEID AND MASMERID=@MASMERID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SATISMAHSUBU'
		
				INSERT INTO MUH_FIS (FISNO,BELGETURU,BELGEACIKLAMA,ODEMEYONTEMI,FISID,SUBEID,MASMERID,ISLEMGRUPID3,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
				SELECT (SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO) AS FISNO,5,'Z Raporu','NAKİT', @FISID,@SUBEID,@MASMERID,@DEPOID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Günlük Satış Entegrasyonu',1,'TL',1,SUM(TOPLAM),0.00,'SATISMAHSUBU'
				FROM FU_TUKETIMANALIZ WHERE (ACIKLAMA LIKE'%NAKİT' OR ACIKLAMA LIKE'%KARTI%') AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID
				GROUP BY 
				SUBEID,DEPOID,TARIH,MASMERID

				INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,DBORC,ALACAK,DALACAK,BABSTUTAR,BELGETURU,BELGEACIKLAMA,ODEMEYONTEMI)
				
				SELECT @FISID, NSATISHESAPID AS HESAPID, 'Günlük Nakit Satış Tahsilatı' AS ACIKLAMA, 'TL','SATISMAHSUBU',SUM(TOPLAM) AS TUTAR, 0.00 AS DTUTAR, 1,0, SUM(TOPLAM) AS BORC, 0.00 AS DBORC, 0.00 AS ALACAK, 0.00 AS DALACAK, SUM(MATRAH) AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%NAKİT' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(TOPLAM)>0
				GROUP BY NSATISHESAPID,NAKITHESAPKODU, NAKITHESAPADI
				UNION ALL
				SELECT @FISID, GELIRHESAPID, 'Günlük Nakit Satış Geliri' AS ACIKLAMA,  'TL','SATISMAHSUBU',SUM(MATRAH) AS TUTAR, 0.00 AS DTUTAR, 1,0, 0.00 AS BORC, 0.00 AS DBORC, SUM(MATRAH) AS ALACAK, 0.00 AS DALACAK, 0.00 AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%NAKİT' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(MATRAH)>0
				GROUP BY GELIRHESAPID,GELIRHESAPKODU,GELIRHESAPADI
				UNION ALL
				SELECT @FISID, SATISKDVHESAPID, 'Günlük Nakit Satış Gelir Kdv' AS ACIKLAMA, 'TL','SATISMAHSUBU',SUM(KDVTUTAR) AS TUTAR, 0.00 AS DTUTAR, 1,0,   0.00 AS BORC, 0.00 AS DBORC, SUM(KDVTUTAR) AS ALACAK, 0.00 AS DALACAK, 0.00 AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%NAKİT' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(KDVTUTAR)>0
				GROUP BY SATISKDVHESAPID,SATISKDVHESAPKODU, SATISKDVHESAPADI
				
				UNION ALL
				
				SELECT @FISID, KKSATISHESAPID AS HESAPID, 'Günlük Kredi Kartı Satış Tahsilatı' AS ACIKLAMA, 'TL','SATISMAHSUBU',SUM(TOPLAM) AS TUTAR, 0.00 AS DTUTAR, 1,0,  SUM(TOPLAM) AS BORC, 0.00 AS DBORC, 0.00 AS ALACAK, 0.00 AS DALACAK, SUM(MATRAH) AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%KARTI%' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(TOPLAM)>0
				GROUP BY KKSATISHESAPID,KKHESAPKODU, KKHESAPADI
				UNION ALL
				SELECT @FISID, GELIRHESAPID, 'Günlük Kredi Kartı Satış Geliri' AS ACIKLAMA, 'TL','SATISMAHSUBU',SUM(MATRAH) AS TUTAR, 0.00 AS DTUTAR, 1,0,   0.00 AS BORC, 0.00 AS DBORC, SUM(MATRAH) AS ALACAK, 0.00 AS DALACAK, 0.00 AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%KARTI%' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(MATRAH)>0
				GROUP BY GELIRHESAPID,GELIRHESAPKODU,GELIRHESAPADI
				UNION ALL
				SELECT @FISID, SATISKDVHESAPID, 'Günlük Kredi Kartı Satış Gelir Kdv' AS ACIKLAMA, 'TL','SATISMAHSUBU',SUM(KDVTUTAR) AS TUTAR, 0.00 AS DTUTAR, 1,0,   0.00 AS BORC, 0.00 AS DBORC, SUM(KDVTUTAR) AS ALACAK, 0.00 AS DALACAK, 0.00 AS BABSTUTAR,5,'Z Raporu','NAKİT' 
				FROM FU_TUKETIMANALIZ WHERE ACIKLAMA LIKE'%KARTI%' AND TARIH=@TARIH AND SUBEID=@SUBEID AND DEPOID=@DEPOID AND ABS(KDVTUTAR)>0
				GROUP BY SATISKDVHESAPID,SATISKDVHESAPKODU, SATISKDVHESAPADI

				UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_SATISENTEGRESIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_SATISENTEGRESIL]  
@TARIH SMALLDATETIME
AS
BEGIN
				DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SATISMAHSUBU')
				DELETE FROM MUH_FIS WHERE FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SATISMAHSUBU'
END
GO
/****** Object:  StoredProcedure [dbo].[PR_SAYIMMAHSUBU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_SAYIMMAHSUBU]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@EKLEYEN INT
AS
BEGIN
DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SAYIMMAHSUBU')
DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SAYIMMAHSUBU'
if (SELECT ISNULL(COUNT(*),0) FROM QMUH_SAYIM2 WHERE ISNULL(ALISHESAPID,0)<>0 AND ISNULL(SARFHESAPID,0)<>0 AND TARIH=@TARIH)>0
	BEGIN
		INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
		VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Sayım Mahsubu',1,'TL',1,@TOPLAM,0.00,'SAYIMMAHSUBU')
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
		SELECT @FISID, ALISHESAPID AS HESAPID, 'Sayım Maliyeti' as ACIKLAMA, 'TL' AS DOVIZ, 'SAYIMMAHSUBU' AS OZELKOD1, SUM(ABS(TUKETILENTUTAR)-ABS(CIKANTUTAR)) AS TUTAR, 0.00 AS DTUTAR,SUM(ABS(TUKETILENMIKTAR)-ABS(CIKANMIKTAR)) AS MIKTAR, 0.00 AS BORC,  SUM(ABS(TUKETILENTUTAR)-ABS(CIKANTUTAR)) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_SAYIM2 WHERE SUBEID=@SUBEID AND TARIH=@TARIH GROUP BY TARIH,ALISHESAPID
		UNION ALL
		SELECT @FISID, SARFHESAPID AS HESAPID, 'Sayım Maliyeti' as ACIKLAMA, 'TL' AS DOVIZ, 'SAYIMMAHSUBU' AS OZELKOD1, SUM(ABS(TUKETILENTUTAR)-ABS(CIKANTUTAR)) AS TUTAR, 0.00 AS DTUTAR,SUM(ABS(TUKETILENMIKTAR)-ABS(CIKANMIKTAR)) AS MIKTAR, SUM(ABS(TUKETILENTUTAR)-ABS(CIKANTUTAR))  AS BORC,  0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_SAYIM2 WHERE SUBEID=@SUBEID AND TARIH=@TARIH GROUP BY TARIH, SARFHESAPID

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_SAYIMMAHSUBUSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_SAYIMMAHSUBUSIL]  
@TARIH SMALLDATETIME,
@SUBEID INT
AS
BEGIN
	DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SAYIMMAHSUBU')
	DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='SAYIMMAHSUBU'
END
GO
/****** Object:  StoredProcedure [dbo].[PR_STOKBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_STOKBAKIYE]  
@TARIH DATETIME,
@STOKID INT,
@DEPOID INT,
@SUBEID INT,
@DEPOFISID INT
AS
BEGIN
	SELECT STOKID,SBIRIMI,BIRIM2,BIRIM3,BIRIM4,KATSAYI2,KATSAYI3,KATSAYI4,TURU,
	SUM(CASE WHEN DEPOID=0 THEN GCADET ELSE 0 END) AS GDBAKIYE,
	SUM(CASE WHEN DEPOID=0 THEN (CASE WHEN ISNULL(GCADET,0)=0 AND 
	FISTIPI='FATURA' AND ISLEMDETAY='-1' THEN -1 WHEN ISNULL(GCADET,0)=0 AND 
	FISTIPI='FATURA' THEN 1 ELSE GCADET END)*NFIYAT ELSE 0 END) AS GDBAKIYETUTAR,
	SUM(CASE WHEN DEPOID=@DEPOID THEN GCADET ELSE 0 END) AS CDBAKIYE,
	SUM(CASE WHEN DEPOID=@DEPOID THEN (CASE WHEN ISNULL(GCADET,0)=0 AND FISTIPI='FATURA'
	 AND ISLEMDETAY='-1' THEN -1 WHEN ISNULL(GCADET,0)=0 AND FISTIPI='FATURA' 
	THEN 1 ELSE GCADET END)*NFIYAT ELSE 0 END) AS CDBAKIYETUTAR,
	SUM(CASE WHEN (DEPOID=0) AND ISNULL(KATSAYI2,0)<>0 THEN GCADET/KATSAYI2 ELSE 0 END) AS GDBAKIYE2,
	SUM(CASE WHEN DEPOID=0 AND ISNULL(KATSAYI2,0)<>0 THEN (CASE WHEN ISNULL(GCADET,0)=0 AND FISTIPI='FATURA'
	AND ISLEMDETAY='-1' THEN -1 WHEN ISNULL(GCADET,0)=0 AND FISTIPI='FATURA' 
	THEN 1 ELSE GCADET END)*NFIYAT/KATSAYI2 ELSE 0 END) AS GDBAKIYETUTAR2,
	SUM(CASE WHEN DEPOID=@DEPOID AND ISNULL(KATSAYI2,0)<>0  THEN GCADET/KATSAYI2 ELSE 0 END) AS CDBAKIYE2,
	SUM(CASE WHEN DEPOID=@DEPOID AND ISNULL(KATSAYI2,0)<>0  THEN (CASE WHEN ISNULL(GCADET,0)=0 AND 
	FISTIPI='FATURA' AND ISLEMDETAY='-1'  THEN 1 WHEN ISNULL(GCADET,0)=0 AND FISTIPI='FATURA' 
	THEN 1 ELSE GCADET END)*NFIYAT/KATSAYI2 ELSE 0 END) AS CDBAKIYETUTAR2 
	 FROM QMUH_STOKISLSAYIM
	WHERE SUBEID=@SUBEID AND TARIH<=@TARIH AND NOT (FISTIPI='TUKETIMFIS' AND FATID=@DEPOFISID) 
	AND STOKID=@STOKID
	 GROUP BY STOKID,SBIRIMI,BIRIM2,BIRIM3,BIRIM4,KATSAYI2,KATSAYI3,KATSAYI4,TURU
END
GO
/****** Object:  StoredProcedure [dbo].[PR_STOKLIST]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PR_STOKLIST]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PR_TABLOYENILE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_TABLOYENILE]
AS
SELECT * INTO CONFIG_TMP FROM CONFIG
SELECT * INTO Raporlar_TMP FROM Raporlar
SELECT * INTO UserGrid_TMP FROM UserGrid
TRUNCATE TABLE CONFIG
TRUNCATE TABLE Raporlar
TRUNCATE TABLE UserGrid
INSERT INTO CONFIG (PROGNAME,SECTIONSTR,KEYNAME,VALUESTR,[TYPES],ALTERNATIVES,SIL) SELECT PROGNAME,SECTIONSTR,KEYNAME,VALUESTR,[TYPES],ALTERNATIVES,SIL FROM CONFIG_TMP
INSERT INTO Raporlar (Bolum,RaporAdi,[XML],Durum,Olusturma,Silme,XML2) SELECT Bolum,RaporAdi,[XML],Durum,Olusturma,Silme,XML2 FROM Raporlar_TMP
INSERT INTO UserGrid (UserId,FormAdi,TabloAdi,Tasarim,AlanAdi,AlanEtiketi,Aktif) SELECT UserId,FormAdi,TabloAdi,Tasarim,AlanAdi,AlanEtiketi,Aktif FROM UserGrid_TMP
DROP TABLE CONFIG_TMP
DROP TABLE Raporlar_TMP
DROP TABLE UserGrid_TMP
GO
/****** Object:  StoredProcedure [dbo].[PR_URETILECEKLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_URETILECEKLER]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT
AS
SELECT TOP 1000 SUBEID,DEPOFISID,ISLEM,TARIH,GDEPO,CDEPO,YETKILI,EVRAKNO,ACIKLAMA,TTUTAR  

 	FROM ( 

 		SELECT SUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,TUKETIMFIS.ACIKLAMA,TTUTAR  

 		 FROM TUKETIMFIS  

 		 WHERE (SUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1  AND ISNULL(URETILDI,0)=0  

 			   AND DEPOFISID IN ( 

 								 SELECT DEPOFISID  

 								  FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID  

 								  WHERE STOK.TURU IN ('Mamul','Yarı Mamul') 

 								 )   

 		UNION ALL   

 		SELECT SUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,DEPOFIS.YETKILI,ENO AS EVRAKNO,DEPOFIS.ACIKLAMA,TTUTAR  

 		 FROM DEPOFIS  

 		 WHERE (SUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1  AND ISNULL(URETILDI,0)=0 

 			   AND DEPOFISID IN ( 

 								 SELECT DEPOFISID  

 								  FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID  

 								  WHERE STOK.TURU IN ('Mamul','Yarı Mamul'))   

 		) TBL  

 WHERE  1=1  AND (SUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PR_URETILENLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_URETILENLER]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT
AS
SELECT TOP 1000 SUBEID,DEPOFISID,ISLEM,TARIH,GDEPO,CDEPO,YETKILI,EVRAKNO,ACIKLAMA,TTUTAR  

 	FROM ( 

 		SELECT SUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,TUKETIMFIS.ACIKLAMA,TTUTAR  

 		 FROM TUKETIMFIS  

 		 WHERE ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1 AND ISNULL(URETILDI,0)=1  

 			   AND DEPOFISID IN ( 

 								 SELECT DEPOFISID  

 								  FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID  

 								  WHERE STOK.TURU IN ('Mamul','Yarı Mamul') 

 								 )   

 		UNION ALL   

 		SELECT SUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,DEPOFIS.YETKILI,ENO AS EVRAKNO,DEPOFIS.ACIKLAMA,TTUTAR  

 		 FROM DEPOFIS  

 		 WHERE ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1  AND ISNULL(URETILDI,0)=1 

 			   AND DEPOFISID IN ( 

 								 SELECT DEPOFISID  

 								  FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID  

 								  WHERE STOK.TURU IN ('Mamul','Yarı Mamul'))   

 		) TBL  

 WHERE  1=1  AND (SUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PR_URETIMMAHSUBU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_URETIMMAHSUBU]  
@FISID INT,
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@EKLEYEN INT
AS
BEGIN
DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSURETIM')
DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSURETIM'
if (SELECT ISNULL(COUNT(*),0) FROM QMUH_STOKISL WHERE ISNULL(MUHNHESAPID,0)<>0 AND ISNULL(MUHSHESAPID,0)<>0 AND TARIH=@TARIH AND ISLEM='TÜKETİM')>0
	BEGIN
		INSERT INTO MUH_FIS (FISID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
		VALUES(@FISID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Üretim Mahsubu',1,'TL',1,@TOPLAM,0.00,'POSURETIM')
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
		SELECT @FISID, MUHNHESAPID AS HESAPID, 'Üretim Giderleri' as ACIKLAMA, 'TL' AS DOVIZ, 'POSURETIM' AS OZELKOD1, SUM(FADET*FBFIYAT) AS TUTAR, 0.00 AS DTUTAR,ABS(SUM(FADET)) AS MIKTAR, 0.00 AS BORC,  SUM(FADET*FBFIYAT) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM QMUH_STOKISL WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  ISLEM='TÜKETİM' GROUP BY TARIH,MUHNHESAPID
		UNION ALL
		SELECT @FISID, MUHSHESAPID AS HESAPID, 'Üretim Giderleri' as ACIKLAMA, 'TL' AS DOVIZ, 'POSURETIM' AS OZELKOD1, SUM(FADET*FBFIYAT) AS TUTAR, 0.00 AS DTUTAR,ABS(SUM(FADET)) AS MIKTAR,  SUM(FADET*FBFIYAT) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK
		FROM QMUH_STOKISL WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND ISLEM='TÜKETİM' GROUP BY TARIH,MUHSHESAPID

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_URETIMMAHSUBUSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_URETIMMAHSUBUSIL]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT
AS
BEGIN
	DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH BETWEEN @TARIH AND @TARIH2 AND OZELKOD1='POSURETIM')
	DELETE FROM MUH_FIS WHERE SUBEID=@SUBEID AND FISTURID=41 AND TARIH BETWEEN @TARIH AND @TARIH2 AND OZELKOD1='POSURETIM'
END
GO
/****** Object:  StoredProcedure [dbo].[PR_URETIMSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_URETIMSIL]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT
AS
DELETE FROM TUKETIMFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WHERE SUBEID=@SUBEID AND ISNULL(URUNFISID,0)<>0    AND TARIH BETWEEN @TARIH AND @TARIH2)
--5
DELETE FROM TUKETIMFIS WHERE SUBEID=@SUBEID AND   ISNULL(URUNFISID,0)<>0    AND TARIH BETWEEN @TARIH AND @TARIH2
--4
UPDATE TUKETIMFIS SET URETILDI=0 WHERE SUBEID=@SUBEID AND  1=1  AND TARIH BETWEEN @TARIH AND @TARIH2
--3
DELETE FROM DEPOFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WHERE SUBEID=@SUBEID AND ISNULL(URUNFISID,0)<>0    AND TARIH BETWEEN @TARIH AND @TARIH2)
--2
DELETE FROM DEPOFIS WHERE SUBEID=@SUBEID AND   ISNULL(URUNFISID,0)<>0    AND TARIH BETWEEN @TARIH AND @TARIH2
--1
UPDATE DEPOFIS SET URETILDI=0 WHERE SUBEID=@SUBEID AND  1=1  AND TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA]  
 (@HESAPID INT, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@BORC	FLOAT,
	@ALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMBORC FLOAT,
	@TOPLAMALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT

	SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
	SELECT @TOPLAMBORC=(SELECT SUM(BORC) FROM QMUH_HESAPISL WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)
	SELECT @TOPLAMALACAK=(SELECT SUM(ALACAK) FROM QMUH_HESAPISL WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)

	IF @HESAPTIPID=120
		BEGIN 
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM QMUH_HESAPISL WITH (NOLOCK) WHERE BORC>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,ISLEMID

			OPEN ODENMEYEN_HESAPLA
		END
	ELSE
		BEGIN
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM QMUH_HESAPISL WITH (NOLOCK) WHERE ALACAK>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,ISLEMID

			OPEN ODENMEYEN_HESAPLA		
		END

	FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@BORC,@ALACAK

	WHILE @@FETCH_STATUS=0
		BEGIN
			IF @HESAPTIPID=120
				BEGIN
					SET @BORC=(SELECT TOP 1 ISNULL(BORC,0) FROM QMUH_HESAPISL WITH (NOLOCK) WHERE HESAPID=@HESAPID AND ISLEMID=@ISLEMID)
					SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM QMUH_HESAPISL WITH (NOLOCK) WHERE HESAPID=@HESAPID AND ISLEMID=@ISLEMID)

					IF @TOPLAMALACAK-@BORC>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMALACAK-@BORC<0 SET @ODENMEYEN=(@TOPLAMALACAK-@BORC)*-1
					IF @TOPLAMALACAK<0 SET @ODENMEYEN=@BORC
					
					if @HESAPID<>@FISHESAPID 
						BEGIN
							UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
						END
					ELSE
						BEGIN
							UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
						END
					SET @TOPLAMALACAK=@TOPLAMALACAK-@BORC
				END
			ELSE
				BEGIN
					SET @ALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM QMUH_HESAPISL WITH (NOLOCK) WHERE HESAPID=@HESAPID AND ISLEMID=@ISLEMID)
					SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM QMUH_HESAPISL WITH (NOLOCK) WHERE HESAPID=@HESAPID AND ISLEMID=@ISLEMID)

					IF @TOPLAMBORC-@ALACAK>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMBORC-@ALACAK<0 SET @ODENMEYEN=(@TOPLAMBORC-@ALACAK)
					IF @TOPLAMBORC<0 SET @ODENMEYEN=@ALACAK*-1
					
					if @HESAPID<>@FISHESAPID 
						BEGIN
							UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
						END
					ELSE
						BEGIN
							UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
						END
					SET @TOPLAMBORC=@TOPLAMBORC-@ALACAK
				END
			
			FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@BORC,@ALACAK		
		END
	CLOSE ODENMEYEN_HESAPLA
	DEALLOCATE ODENMEYEN_HESAPLA
END
--TOP 1 EKLEDİK AYNI ID DENK GELİYOR
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_2]  
 (@HESAPID INT, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@BORC	FLOAT,
	@ALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMBORC FLOAT,
	@TOPLAMALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISID INT

	SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
	SELECT @TOPLAMBORC=(SELECT SUM(BORC) FROM YASLANDIRMA WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)
	SELECT @TOPLAMALACAK=(SELECT SUM(ALACAK) FROM YASLANDIRMA WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)

	IF @HESAPTIPID=120
		BEGIN 
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM YASLANDIRMA WHERE BORC>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,YASLANDIRMAID

			OPEN ODENMEYEN_HESAPLA
		END
	ELSE
		BEGIN
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM YASLANDIRMA WHERE ALACAK>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,YASLANDIRMAID

			OPEN ODENMEYEN_HESAPLA		
		END

	FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @ISLEMID,@BORC,@ALACAK,@ODENMEYEN

	WHILE @@FETCH_STATUS=0
		BEGIN
			IF @HESAPTIPID=120
				BEGIN
					SET @BORC=(SELECT TOP 1 ISNULL(BORC,0) FROM YASLANDIRMA WHERE HESAPID=@HESAPID AND YASLANDIRMAID=@ISLEMID)
					
					IF @TOPLAMALACAK-@BORC>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMALACAK-@BORC<0 SET @ODENMEYEN=(@TOPLAMALACAK-@BORC)*-1
					IF @TOPLAMALACAK<0 SET @ODENMEYEN=@BORC
					
		
					UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID

					SET @TOPLAMALACAK=@TOPLAMALACAK-@BORC
				END
			ELSE
				BEGIN
					SET @ALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM YASLANDIRMA WHERE HESAPID=@HESAPID AND YASLANDIRMAID=@ISLEMID)
					
					IF @TOPLAMBORC-@ALACAK>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMBORC-@ALACAK<0 SET @ODENMEYEN=(@TOPLAMBORC-@ALACAK)
					IF @TOPLAMBORC<0 SET @ODENMEYEN=@ALACAK*-1
					
					UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
					SET @TOPLAMBORC=@TOPLAMBORC-@ALACAK
				END
			
			FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @ISLEMID,@BORC,@ALACAK,@ODENMEYEN		
		END
	CLOSE ODENMEYEN_HESAPLA
	DEALLOCATE ODENMEYEN_HESAPLA
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_ALICI_DVZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_ALICI_DVZ]  
 (@FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5)

	
	UPDATE MUH_HESAPISL SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0

	DECLARE HESAPLAR CURSOR FOR
	SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
	OPEN HESAPLAR
	
	
	FETCH NEXT FROM HESAPLAR INTO @HESAPID

	WHILE @@FETCH_STATUS=0
		BEGIN
			
			
			DECLARE DOVIZLER CURSOR FOR
			SELECT DISTINCT DOVIZ FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
			OPEN DOVIZLER
	
	
			FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

			WHILE @@FETCH_STATUS=0
				BEGIN				
				
								SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
								SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
								SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

								IF @HESAPTIPID=120
									BEGIN 
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA
									END
								ELSE
									BEGIN
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA		
									END

								FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

								WHILE @@FETCH_STATUS=0
									BEGIN
										IF @HESAPTIPID=120
											BEGIN
												SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

												IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
												IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
											END
										ELSE
											BEGIN
												SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

												IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
												IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
											END
			
										FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
									END
								CLOSE ODENMEYEN_HESAPLA
								DEALLOCATE ODENMEYEN_HESAPLA


					  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
					END
				CLOSE DOVIZLER
				DEALLOCATE DOVIZLER

		  FETCH NEXT FROM HESAPLAR INTO @HESAPID
		END
	CLOSE HESAPLAR
	DEALLOCATE HESAPLAR
END
--TOP 1 EKLEDİK AYNI ID DENK GELİYOR
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_DVZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_DVZ]  
 (@FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5)

	
	UPDATE MUH_HESAPISL SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
	UPDATE MUH_FIS SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FIRMAID=@FIRMAID

	DECLARE HESAPLAR CURSOR FOR
	SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID IN(120,320)
	OPEN HESAPLAR
	
	
	FETCH NEXT FROM HESAPLAR INTO @HESAPID

	WHILE @@FETCH_STATUS=0
		BEGIN
			
			
			DECLARE DOVIZLER CURSOR FOR
			SELECT DISTINCT DOVIZ FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
			OPEN DOVIZLER
	
	
			FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

			WHILE @@FETCH_STATUS=0
				BEGIN				
				
								SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
								SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
								SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

								IF @HESAPTIPID=120
									BEGIN 
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA
									END
								ELSE
									BEGIN
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA		
									END

								FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

								WHILE @@FETCH_STATUS=0
									BEGIN
										IF @HESAPTIPID=120
											BEGIN
												SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

												IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
												IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
											END
										ELSE
											BEGIN
												SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

												IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
												IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
											END
			
										FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
									END
								CLOSE ODENMEYEN_HESAPLA
								DEALLOCATE ODENMEYEN_HESAPLA


					  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
					END
				CLOSE DOVIZLER
				DEALLOCATE DOVIZLER

		  FETCH NEXT FROM HESAPLAR INTO @HESAPID
		END
	CLOSE HESAPLAR
	DEALLOCATE HESAPLAR
END
--TOP 1 EKLEDİK AYNI ID DENK GELİYOR
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL]  
 (@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5)


if @DOVIZLI='HAYIR' 
	BEGIN
					UPDATE MUH_HESAPISL SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
					UPDATE MUH_FIS SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FIRMAID=@FIRMAID

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID IN(120)
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,ISLEMID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,ISLEMID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  ISLEMID=@ISLEMID)
																SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE ISLEMID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																if @HESAPID<>@FISHESAPID 
																	BEGIN
																		UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
																	END
																ELSE
																	BEGIN
																		UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
																	END
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  ISLEMID=@ISLEMID)
																SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE ISLEMID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																if @HESAPID<>@FISHESAPID 
																	BEGIN
																		UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
																	END
																ELSE
																	BEGIN
																		UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
																	END
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN
				UPDATE MUH_HESAPISL SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
					UPDATE MUH_FIS SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FIRMAID=@FIRMAID

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID IN(120)
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY TARIH,ISLEMID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT FISHESAPID,FISID,ISLEMID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY TARIH,ISLEMID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
																SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																if @HESAPID<>@FISHESAPID 
																	BEGIN
																		UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
																	END
																ELSE
																	BEGIN
																		UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
																	END
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)
																SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND ISLEMID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																if @HESAPID<>@FISHESAPID 
																	BEGIN
																		UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
																	END
																ELSE
																	BEGIN
																		UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
																	END
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
		END
END
--TOP 1 EKLEDİK AYNI ID DENK GELİYOR
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL2]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700)
	

	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID
    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF @PROJEID<>''
		BEGIN
			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943 */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL3]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700)
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL4]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL4]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100), @ALTCARI NVARCHAR(5)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700),
	@ALTCARIID INT
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN
		IF @ALTCARI='HAYIR'
			BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
			END
		ELSE
			BEGIN
			/*ALTCARIYE GORE */
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR

			END
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

			IF @ALTCARI='HAYIR'
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE
				BEGIN
				/*ALTCARI */
					DECLARE ALTHESAPLAR CURSOR FOR
					SELECT HESAPID,ALTCARIID FROM MUH_HESAP_ALTCARI WITH (NOLOCK)  WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120) ORDER BY HESAPID,ALTCARIID
					OPEN ALTHESAPLAR
	
	
					FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID
						END
					CLOSE ALTHESAPLAR
					DEALLOCATE ALTHESAPLAR
				END
		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL5]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL5]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100), 
@ALTCARI NVARCHAR(5), @DAIRE NVARCHAR(5)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700),
	@ALTCARIID INT,
	@DAIREID INT
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN
		IF @ALTCARI='HAYIR'
			BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
			END
		ELSE
			BEGIN
			/*ALTCARIYE GORE */
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR

			END
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

			IF @ALTCARI='HAYIR'
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE
				BEGIN
				/*ALTCARI */
					DECLARE ALTHESAPLAR CURSOR FOR
					SELECT HESAPID,ALTCARIID FROM MUH_HESAP_ALTCARI WITH (NOLOCK)  WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120) ORDER BY HESAPID,ALTCARIID
					OPEN ALTHESAPLAR
	
	
					FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID
						END
					CLOSE ALTHESAPLAR
					DEALLOCATE ALTHESAPLAR
				END

/*DAIRE HAYIR */

			IF @DAIRE='HAYIR'
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE
				BEGIN
				/*DAIREYE GORE */
					DECLARE DAIRELER CURSOR FOR
					SELECT HESAPID,OZELKODID FROM [FNCQ_QMUHMIZAN] (@DONEMBASI, @DONEMSONU, @FIRMAID) WHERE  HESAPTIPID=120 GROUP BY HESAPID,OZELKODID ORDER BY HESAPID,OZELKODID
					OPEN DAIRELER
	
	
					FETCH NEXT FROM DAIRELER INTO @HESAPID, @DAIREID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM DAIRELER INTO @HESAPID, @DAIREID
						END
					CLOSE DAIRELER
					DEALLOCATE DAIRELER
				END




		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_GENEL6]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_GENEL6]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100), 
@ALTCARI NVARCHAR(5), @DAIRE NVARCHAR(5), @ISLEMGRUP NVARCHAR(5)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700),
	@ALTCARIID INT,
	@DAIREID INT,
	@ISLEMGRUPID INT
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,ISLEMGRUPID1,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,ISLEMGRUPID1,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,ISLEMGRUPID1,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,ISLEMGRUPID1,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,ISLEMGRUPID1,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN
		IF @ALTCARI='HAYIR'
			BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
			END
		ELSE
			BEGIN
			/*ALTCARIYE GORE */
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR

			END
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

			IF (@ALTCARI='HAYIR') AND (@ISLEMGRUP='HAYIR')
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE IF (@ALTCARI='EVET') AND (@ISLEMGRUP='HAYIR')
				BEGIN
				/*ALTCARI EVET */
					DECLARE ALTHESAPLAR CURSOR FOR
					SELECT HESAPID,ALTCARIID FROM MUH_HESAP_ALTCARI WITH (NOLOCK)  WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120) ORDER BY HESAPID,ALTCARIID
					OPEN ALTHESAPLAR
	
	
					FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID
						END
					CLOSE ALTHESAPLAR
					DEALLOCATE ALTHESAPLAR
				END
			ELSE IF (@ALTCARI='HAYIR') AND (@DAIRE='EVET') AND (@ISLEMGRUP='EVET')
				BEGIN
				/*ISLEMGRUBUNA GORE GORE */
					DECLARE ISLEMGRUBU CURSOR FOR
					SELECT HESAPID,ISLEMGRUPID1 FROM [FNCQ_QMUHMIZAN] (@DONEMBASI, @DONEMSONU, @FIRMAID) WHERE  HESAPTIPID=120 GROUP BY HESAPID,ISLEMGRUPID1 ORDER BY HESAPID,ISLEMGRUPID1
					OPEN ISLEMGRUBU
	
	
					FETCH NEXT FROM ISLEMGRUBU INTO @HESAPID, @ISLEMGRUPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			

		
											DECLARE DOVIZLER CURSOR FOR
											SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1 (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)
											OPEN DOVIZLER
	
	
											FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

											WHILE @@FETCH_STATUS=0
												BEGIN				
				
																SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
																SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ)
																SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE  DOVIZ=@HDOVIZ)

																IF @HESAPTIPID=120
																	BEGIN 
																		DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
																		SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

																		OPEN ODENMEYEN_HESAPLA
																	END
																ELSE
																	BEGIN
																		DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
																		SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

																		OPEN ODENMEYEN_HESAPLA		
																	END

																FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

																WHILE @@FETCH_STATUS=0
																	BEGIN
																		IF @HESAPTIPID=120
																			BEGIN
																				SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																				IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																				IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																				IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																				UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																				SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
																			END
																		ELSE
																			BEGIN
																				SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																				IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																				IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																				IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																				UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																				SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
																			END
			
																		FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
																	END
																CLOSE ODENMEYEN_HESAPLA
																DEALLOCATE ODENMEYEN_HESAPLA


													  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
													END
												CLOSE DOVIZLER
												DEALLOCATE DOVIZLER


						  FETCH NEXT FROM ISLEMGRUBU INTO @HESAPID, @ISLEMGRUPID
						END
					CLOSE ISLEMGRUBU
					DEALLOCATE ISLEMGRUBU
				END
/*DAIRE HAYIR ISLEMGRUP HAYIR */

			IF (@DAIRE='HAYIR') AND (@ISLEMGRUP='HAYIR')
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE IF (@DAIRE='EVET') AND (@ISLEMGRUP='HAYIR')
				BEGIN
				/*DAIREYE GORE */
					DECLARE DAIRELER CURSOR FOR
					SELECT HESAPID,OZELKODID FROM [FNCQ_QMUHMIZAN] (@DONEMBASI, @DONEMSONU, @FIRMAID) WHERE  HESAPTIPID=120 GROUP BY HESAPID,OZELKODID ORDER BY HESAPID,OZELKODID
					OPEN DAIRELER
	
	
					FETCH NEXT FROM DAIRELER INTO @HESAPID, @DAIREID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_DAIRE  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@DAIREID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM DAIRELER INTO @HESAPID, @DAIREID
						END
					CLOSE DAIRELER
					DEALLOCATE DAIRELER
				END

			ELSE IF (@DAIRE='EVET') AND (@ISLEMGRUP='EVET') AND (@ALTCARI='EVET')
				BEGIN
				/*ISLEMGRUBUNA GORE GORE */
					
					DECLARE ISLEMGRUBU CURSOR FOR
					SELECT HESAPID,ISLEMGRUPID1 FROM [FNCQ_QMUHMIZAN] (@DONEMBASI, @DONEMSONU, @FIRMAID) WHERE  HESAPTIPID=120 GROUP BY HESAPID,ISLEMGRUPID1 ORDER BY HESAPID,ISLEMGRUPID1
					OPEN ISLEMGRUBU
	
	
					FETCH NEXT FROM ISLEMGRUBU INTO @HESAPID, @ISLEMGRUPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			

		
											DECLARE DOVIZLER CURSOR FOR
											SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1 (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)
											OPEN DOVIZLER
	
	
											FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

											WHILE @@FETCH_STATUS=0
												BEGIN				
				
																SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
																SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ)
																SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE  DOVIZ=@HDOVIZ)

																IF @HESAPTIPID=120
																	BEGIN 
																		DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
																		SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

																		OPEN ODENMEYEN_HESAPLA
																	END
																ELSE
																	BEGIN
																		DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
																		SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

																		OPEN ODENMEYEN_HESAPLA		
																	END

																FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

																WHILE @@FETCH_STATUS=0
																	BEGIN
																		IF @HESAPTIPID=120
																			BEGIN
																				SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																				IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																				IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																				IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																				UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																				SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
																			END
																		ELSE
																			BEGIN
																				SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ISLEMGRUPID1  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ISLEMGRUPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																				IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																				IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																				IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																				UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																				SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
																			END
			
																		FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
																	END
																CLOSE ODENMEYEN_HESAPLA
																DEALLOCATE ODENMEYEN_HESAPLA


													  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
													END
												CLOSE DOVIZLER
												DEALLOCATE DOVIZLER


						  FETCH NEXT FROM ISLEMGRUBU INTO @HESAPID, @ISLEMGRUPID
						END
					CLOSE ISLEMGRUBU
					DEALLOCATE ISLEMGRUBU
				END

				


		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_SECILI_CARI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_SECILI_CARI]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100), @ALTCARI NVARCHAR(5), @SECHESAPID NVARCHAR(10)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700),
	@ALTCARIID INT
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID AND HESAPID=@SECHESAPID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPID='+@SECHESAPID+' AND HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY HESAPID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,BORC,ALACAK,DBORC,DALACAK,DOVIZ
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120 AND HESAPID=@SECHESAPID
			ORDER BY HESAPID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN
		IF @ALTCARI='HAYIR'
			BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120 AND HESAPID=@SECHESAPID
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
			END
		ELSE
			BEGIN
			/*ALTCARIYE GORE */
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120 AND HESAPID=@SECHESAPID
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR

			END
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN

			IF @ALTCARI='HAYIR'
				BEGIN
					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120  AND HESAPID=@SECHESAPID
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) 
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
				END
			ELSE
				BEGIN
				/*ALTCARI */
					DECLARE ALTHESAPLAR CURSOR FOR
					SELECT HESAPID,ALTCARIID FROM MUH_HESAP_ALTCARI WITH (NOLOCK)  WHERE HESAPID=@SECHESAPID ORDER BY HESAPID,ALTCARIID
					OPEN ALTHESAPLAR
	
	
					FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK)  WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE  DOVIZ=@HDOVIZ)

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID)  WHERE DOVIZ=@HDOVIZ AND DALACAK>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(DALACAK,0) FROM FNCQ_YASLANDIRMA_ALTCARI  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID,@ALTCARIID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
						
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
				
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM ALTHESAPLAR INTO @HESAPID, @ALTCARIID
						END
					CLOSE ALTHESAPLAR
					DEALLOCATE ALTHESAPLAR
				END
		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE  MUH_HESAPISL.HESAPID=@SECHESAPID AND YASLANDIRMA.HESAPID=@SECHESAPID AND YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_SOZLESME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_SOZLESME]  
(@DOVIZLI NVARCHAR(5), @FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @PROJEID NVARCHAR(100), @SUBEID NVARCHAR(100)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5),
	@SQLCUMLE NVARCHAR(700),
	@ALTCARIID INT,
	@DAIREID INT,
	@SOZLESMEID INT
	
	DELETE FROM YASLANDIRMA WHERE FIRMAID=@FIRMAID

    UPDATE MUH_HESAPISL SET VADE=NULL WHERE VADE<='2000-01-01' AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
    IF (@PROJEID<>'') OR (@SUBEID<>'')
		BEGIN
			SET @SQLCUMLE='SELECT * INTO ##YASLANDIRMA'+@FIRMAID+' FROM (SELECT FISID,ISLEMID,SUBEID,'+@FIRMAID+' AS FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ,SOZLESMEID
			FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+'
			) AS TBL ORDER BY SOZLESMEID,VADE,FISID'
			EXEC(@SQLCUMLE)

			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,BORC,ALACAK,DBORC,DALACAK,DOVIZ,SOZLESMEID)
			SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ,SOZLESMEID
			FROM ##YASLANDIRMA'+@FIRMAID+' WHERE 1=1 '+@SUBEID+'
			ORDER BY SOZLESMEID,VADE,FISID'
			EXEC(@SQLCUMLE)
			
			SET @SQLCUMLE='DROP TABLE ##YASLANDIRMA'+@FIRMAID
			EXEC (@SQLCUMLE)

/*			SET @SQLCUMLE='INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ) */
	/*		SELECT FISID,ISLEMID, '+@FIRMAID+',TARIH,VADE,HESAPTIPID,HESAPID,BORC,ALACAK,DBORC,DALACAK,DOVIZ */
		/*	FROM FNCQ_QMUHMIZAN_FATURA ('''+@DONEMBASI+''','''+@DONEMSONU+''','''+@FIRMAID+''') WHERE HESAPTIPID=120 AND 1=1 '+@PROJEID+@SUBEID+' */
			/*ORDER BY HESAPID,VADE,FISID' */
		/*	EXEC(@SQLCUMLE) */
		END
	ELSE
		BEGIN
			INSERT INTO YASLANDIRMA (FISID,ISLEMID,FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,DAIREID,BORC,ALACAK,DBORC,DALACAK,DOVIZ,SOZLESMEID)
			SELECT FISID,ISLEMID, @FIRMAID,TARIH,VADE,HESAPTIPID,HESAPID,ALTCARIID,OZELKODID,BORC,ALACAK,DBORC,DALACAK,DOVIZ,SOZLESMEID
			FROM FNCQ_QMUHMIZAN_FATURA (@DONEMBASI,@DONEMSONU,@FIRMAID) WHERE HESAPTIPID=120
			ORDER BY SOZLESMEID,VADE,FISID
		END
	
	/*SELECT * FROM YASLANDIRMA WHERE HESAPID=126943    **** ŞUBE SEÇİMİ KOYMALIYIZ. */

	/*FNCQ_QMUH_HESAPISL2 ENTEGRE OLMAYANLAR GELMİYOR */
if @DOVIZLI='HAYIR' 
	BEGIN

					DECLARE HESAPLAR CURSOR FOR
					SELECT HESAPID FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID=120
					OPEN HESAPLAR
	
	
					FETCH NEXT FROM HESAPLAR INTO @HESAPID

					WHILE @@FETCH_STATUS=0
						BEGIN
				
				
												SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPID=@HESAPID
												SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
												SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

												IF @HESAPTIPID=120
													BEGIN 
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
													END
												ELSE
													BEGIN
														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT HESAPID,YASLANDIRMAID,BORC,ALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA		
													END

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

												WHILE @@FETCH_STATUS=0
													BEGIN
														IF @HESAPTIPID=120
															BEGIN
																SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
															END
														ELSE
															BEGIN
																SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_YASLANDIRMA  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
																IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
															END
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA

						  FETCH NEXT FROM HESAPLAR INTO @HESAPID
						END
					CLOSE HESAPLAR
					DEALLOCATE HESAPLAR
	END
	ELSE IF @DOVIZLI='EVET'
		BEGIN
					DECLARE SOZLESMELER CURSOR FOR
					SELECT EMLAKSATISID FROM EMLAKSATIS WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID
					OPEN SOZLESMELER
	
	
					FETCH NEXT FROM SOZLESMELER INTO @SOZLESMEID

					WHILE @@FETCH_STATUS=0
						BEGIN
			
			
							DECLARE DOVIZLER CURSOR FOR
							SELECT DISTINCT DOVIZ FROM FNCQ_YASLANDIRMA_SOZLESME (@DONEMBASI,@DONEMSONU,@FIRMAID,@SOZLESMEID)
							OPEN DOVIZLER
	
	
							FETCH NEXT FROM DOVIZLER INTO @HDOVIZ

							WHILE @@FETCH_STATUS=0
								BEGIN				
				
												SELECT @TOPLAMDBORC=(SELECT SUM(DBORC) FROM FNCQ_YASLANDIRMA_SOZLESME  (@DONEMBASI,@DONEMSONU,@FIRMAID,@SOZLESMEID) WHERE DOVIZ=@HDOVIZ)
												SELECT @TOPLAMDALACAK=(SELECT SUM(DALACAK) FROM FNCQ_YASLANDIRMA_SOZLESME  (@DONEMBASI,@DONEMSONU,@FIRMAID,@SOZLESMEID) WHERE  DOVIZ=@HDOVIZ)

														DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
														SELECT SOZLESMEID,YASLANDIRMAID,DBORC,DALACAK,ODENMEYEN FROM FNCQ_YASLANDIRMA_SOZLESME  (@DONEMBASI,@DONEMSONU,@FIRMAID,@SOZLESMEID)  WHERE DOVIZ=@HDOVIZ AND DBORC>0 ORDER BY VADE,YASLANDIRMAID

														OPEN ODENMEYEN_HESAPLA
		

												FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN

												WHILE @@FETCH_STATUS=0
													BEGIN

																SET @DBORC=(SELECT TOP 1 ISNULL(DBORC,0) FROM FNCQ_YASLANDIRMA_SOZLESME  (@DONEMBASI,@DONEMSONU,@FIRMAID,@SOZLESMEID) WHERE DOVIZ=@HDOVIZ AND YASLANDIRMAID=@ISLEMID)

																IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
																IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
																IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
				
																UPDATE YASLANDIRMA SET ODENMEYEN=@ODENMEYEN WHERE YASLANDIRMAID=@ISLEMID
																SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
			
														FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@ISLEMID,@DBORC,@DALACAK,@ODENMEYEN		
													END
												CLOSE ODENMEYEN_HESAPLA
												DEALLOCATE ODENMEYEN_HESAPLA


									  FETCH NEXT FROM DOVIZLER INTO @HDOVIZ
									END
								CLOSE DOVIZLER
								DEALLOCATE DOVIZLER

						  FETCH NEXT FROM SOZLESMELER INTO @SOZLESMEID
						END
					CLOSE SOZLESMELER
					DEALLOCATE SOZLESMELER
		END
	UPDATE MUH_HESAPISL SET MUH_HESAPISL.ODENMEYEN=YASLANDIRMA.ODENMEYEN FROM MUH_HESAPISL INNER JOIN YASLANDIRMA ON MUH_HESAPISL.FISID=YASLANDIRMA.FISID AND MUH_HESAPISL.ISLEMID=YASLANDIRMA.ISLEMID WHERE YASLANDIRMA.FIRMAID=@FIRMAID
END
/*TOP 1 EKLEDİK AYNI ID DENK GELİYOR */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMA_TL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PR_YASLANDIRMA_TL]  
 (@FIRMAID NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10)) AS 
BEGIN 
	DECLARE 
	@ISLEMID INT,
	@DBORC	FLOAT,
	@DALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMDBORC FLOAT,
	@TOPLAMDALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT,
	@FISHESAPID INT,
	@FISID INT,
	@HESAPID INT,
	@HDOVIZ NVARCHAR(5)

	
	UPDATE MUH_HESAPISL SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
	UPDATE MUH_FIS SET ODENMEYEN=0 WHERE ABS(ODENMEYEN)>0 AND FIRMAID=@FIRMAID

	DECLARE HESAPLAR CURSOR FOR
	SELECT HESAPID FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND HESAPTIPID IN(120,320)
	OPEN HESAPLAR
	
	
	FETCH NEXT FROM HESAPLAR INTO @HESAPID

	WHILE @@FETCH_STATUS=0
		BEGIN
				
				
								SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
								SELECT @TOPLAMDBORC=(SELECT SUM(BORC) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )
								SELECT @TOPLAMDALACAK=(SELECT SUM(ALACAK) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) )

								IF @HESAPTIPID=120
									BEGIN 
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE BORC>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA
									END
								ELSE
									BEGIN
										DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
										SELECT FISHESAPID,FISID,ISLEMID,BORC,ALACAK,ODENMEYEN FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID)  WHERE ALACAK>0 ORDER BY TARIH,ISLEMID

										OPEN ODENMEYEN_HESAPLA		
									END

								FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK

								WHILE @@FETCH_STATUS=0
									BEGIN
										IF @HESAPTIPID=120
											BEGIN
												SET @DBORC=(SELECT TOP 1 ISNULL(BORC,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE ISLEMID=@ISLEMID)

												IF @TOPLAMDALACAK-@DBORC>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDALACAK-@DBORC<0 SET @ODENMEYEN=(@TOPLAMDALACAK-@DBORC)*-1
												IF @TOPLAMDALACAK<0 SET @ODENMEYEN=@DBORC
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDALACAK=@TOPLAMDALACAK-@DBORC
											END
										ELSE
											BEGIN
												SET @DALACAK=(SELECT TOP 1 ISNULL(ALACAK,0) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE  ISLEMID=@ISLEMID)
												SET @FISHESAPID=(SELECT TOP 1 ISNULL(FISHESAPID,99999999) FROM FNCQ_QMUH_HESAPISL2_HESAPID  (@DONEMBASI,@DONEMSONU,@FIRMAID,@HESAPID) WHERE ISLEMID=@ISLEMID)

												IF @TOPLAMDBORC-@DALACAK>=0 SET @ODENMEYEN=0.00
												IF @TOPLAMDBORC-@DALACAK<0 SET @ODENMEYEN=(@TOPLAMDBORC-@DALACAK)
												IF @TOPLAMDBORC<0 SET @ODENMEYEN=@DALACAK*-1
					
												if @HESAPID<>@FISHESAPID 
													BEGIN
														UPDATE MUH_HESAPISL SET ODENMEYEN=@ODENMEYEN WHERE ISLEMID=@ISLEMID
													END
												ELSE
													BEGIN
														UPDATE MUH_FIS SET ODENMEYEN=@ODENMEYEN WHERE FISID=@FISID
													END
												SET @TOPLAMDBORC=@TOPLAMDBORC-@DALACAK
											END
			
										FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @FISHESAPID,@FISID,@ISLEMID,@ODENMEYEN,@DBORC,@DALACAK		
									END
								CLOSE ODENMEYEN_HESAPLA
								DEALLOCATE ODENMEYEN_HESAPLA

		  FETCH NEXT FROM HESAPLAR INTO @HESAPID
		END
	CLOSE HESAPLAR
	DEALLOCATE HESAPLAR
END
--TOP 1 EKLEDİK AYNI ID DENK GELİYOR
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGOSTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGOSTER]  
 (@VADEYEGORE NVARCHAR(5),@TARIH nvarchar(10), @DONEMBASI nvarchar(10), @DONEMSONU nvarchar(10), @FIRMAID NVARCHAR(10), @DONEM1 INT, @DONEM2 INT, @DONEM3 INT, @DONEM4 INT, @DONEM5 INT) AS 
BEGIN
IF @VADEYEGORE='HAYIR'
	BEGIN
		SELECT * FROM (SELECT HESAPTIPID, HESAPTIPADI, 
		   HESAPID,HESAPKODU,HESAPADI,  'TL' AS DOVIZ,1 as SUBEID,'MERKEZ' AS SUBEADI,0 AS MASMERID,'Tumu' AS MASMERADI,VADEGUN,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN BORC ELSE BORC END ) TOPLAMBORC, 
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN ALACAK ELSE ALACAK END ) TOPLAMALACAK,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN BORC ELSE BORC END)-SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN ALACAK ELSE ALACAK END ) AS BAKIYE,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DBORC ELSE BORC END ) DTOPLAMBORC, 
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DALACAK ELSE ALACAK END ) DTOPLAMALACAK,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DBORC ELSE BORC END)-SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DALACAK ELSE ALACAK END ) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(OPSTARIH AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN OPSTARIH<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN OPSTARIH<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN OPSTARIH<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(OPSTARIH AS INTEGER))/SUM(CASE WHEN OPSTARIH<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN OPSTARIH>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN OPSTARIH>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN OPSTARIH>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(OPSTARIH AS INTEGER))/SUM(CASE WHEN OPSTARIH>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,OPSTARIH,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 HESAPOZELKOD1, HESAPOZELKOD2 
		 FROM FNCQ_QMUH_HESAPISL2 (@DONEMBASI,@DONEMSONU,@FIRMAID)  AS QMUH_HESAPISL  
		 WHERE OPSTARIH>=@DONEMBASI  AND  HESAPTIPID IN (120,320)   AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,VADEGUN, HESAPOZELKOD1, HESAPOZELKOD2,HESAPTIPID, HESAPTIPADI
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ
	END
ELSE
	BEGIN
		SELECT * FROM (SELECT HESAPTIPID, HESAPTIPADI, 
		   HESAPID,HESAPKODU,HESAPADI,  'TL' AS DOVIZ,1 as SUBEID,'MERKEZ' AS SUBEADI,0 AS MASMERID,'Tumu' AS MASMERADI,VADEGUN,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN BORC ELSE BORC END ) TOPLAMBORC, 
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN ALACAK ELSE ALACAK END ) TOPLAMALACAK,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN BORC ELSE BORC END)-SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN ALACAK ELSE ALACAK END ) AS BAKIYE,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DBORC ELSE BORC END ) DTOPLAMBORC, 
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DALACAK ELSE ALACAK END ) DTOPLAMALACAK,
		   SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DBORC ELSE BORC END)-SUM(CASE WHEN HESAPDOVIZ<>'TL' THEN DALACAK ELSE ALACAK END ) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 HESAPOZELKOD1, HESAPOZELKOD2 
		 FROM FNCQ_QMUH_HESAPISL2 (@DONEMBASI,@DONEMSONU,@FIRMAID)  AS QMUH_HESAPISL  
		 WHERE VADE>=@DONEMBASI  AND  HESAPTIPID IN (120,320)   AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,VADEGUN, HESAPOZELKOD1, HESAPOZELKOD2,HESAPTIPID, HESAPTIPADI
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ
	END
END
--SUBEID,SUBEADI NI KALDIRDIK TÜMÜNÜ BİRADA GÖSTERSİN
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGOSTER_2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGOSTER_2]  
 (@VADEYEGORE NVARCHAR(5),@TARIH nvarchar(10), @DONEMBASI nvarchar(10), @DONEMSONU nvarchar(10), @FIRMAID NVARCHAR(10), @DONEM1 INT, @DONEM2 INT, @DONEM3 INT, @DONEM4 INT, @DONEM5 INT) AS 
BEGIN
IF @VADEYEGORE='HAYIR'
	BEGIN
		SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
		   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
		   SUM(BORC) TOPLAMBORC, 
		   SUM(ALACAK) TOPLAMALACAK,
		   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
		   SUM(DBORC) DTOPLAMBORC, 
		   SUM(DALACAK) DTOPLAMALACAK,
		   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST( DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
		 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
		 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
		 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
		 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
		 WHERE GY.FIRMAID=@FIRMAID AND  DATEADD(DAY,VADEGUN,TARIH)>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ		
	END
ELSE
	BEGIN
		SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
		   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
		   SUM(BORC) TOPLAMBORC, 
		   SUM(ALACAK) TOPLAMALACAK,
		   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
		   SUM(DBORC) DTOPLAMBORC, 
		   SUM(DALACAK) DTOPLAMALACAK,
		   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
		 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
		 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
		 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
		 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
		 WHERE GY.FIRMAID=@FIRMAID AND VADE>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ	
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGOSTER_3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGOSTER_3]  
 (@VADEYEGORE NVARCHAR(5),@DAIREGOSTER NVARCHAR(5), @TARIH nvarchar(10), @DONEMBASI nvarchar(10), @DONEMSONU nvarchar(10), @FIRMAID NVARCHAR(10), @DONEM1 INT, @DONEM2 INT, @DONEM3 INT, @DONEM4 INT, @DONEM5 INT) AS 
BEGIN
IF @DAIREGOSTER='HAYIR'
	BEGIN
		IF @VADEYEGORE='HAYIR'
			BEGIN
				SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
				   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, S.ADSOYAD AS TEMSILCIADI, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
				   SUM(BORC) TOPLAMBORC, 
				   SUM(ALACAK) TOPLAMALACAK,
				   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
				   SUM(DBORC) DTOPLAMBORC, 
				   SUM(DALACAK) DTOPLAMALACAK,
				   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
				   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
				   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
					 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
				  SUM(CASE WHEN DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
					 CAST(CAST(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST( DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
				  SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
					  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
				 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
				 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
				 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
				 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
				 LEFT JOIN SATISTEMSILCI AS S WITH (NOLOCK) ON H.YETKIID=S.SATISTEMSILCIID
				 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
				 WHERE GY.FIRMAID=@FIRMAID AND  DATEADD(DAY,VADEGUN,TARIH)>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
				  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, S.ADSOYAD, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
				 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
				 ORDER BY  HESAPADI,DOVIZ		
			END
		ELSE
			BEGIN
				SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
				   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, S.ADSOYAD AS TEMSILCIADI, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
				   SUM(BORC) TOPLAMBORC, 
				   SUM(ALACAK) TOPLAMALACAK,
				   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
				   SUM(DBORC) DTOPLAMBORC, 
				   SUM(DALACAK) DTOPLAMALACAK,
				   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
				   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
				   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
					 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
				  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
					 CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
				  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
					  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
				 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
				 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
				 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
				 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
				 LEFT JOIN SATISTEMSILCI AS S WITH (NOLOCK) ON H.YETKIID=S.SATISTEMSILCIID
				 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
				 WHERE GY.FIRMAID=@FIRMAID AND VADE>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
				  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, S.ADSOYAD, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
				 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
				 ORDER BY  HESAPADI,DOVIZ	
			END
	END
ELSE
	BEGIN
		IF @VADEYEGORE='HAYIR'
			BEGIN
				SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
				   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, GRUP3.GRUPADI AS HESAPADI2, S.ADSOYAD AS TEMSILCIADI, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
				   SUM(BORC) TOPLAMBORC, 
				   SUM(ALACAK) TOPLAMALACAK,
				   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
				   SUM(DBORC) DTOPLAMBORC, 
				   SUM(DALACAK) DTOPLAMALACAK,
				   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
				   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
				   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
					 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
				  SUM(CASE WHEN DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
					 CAST(CAST(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST( DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
				  SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
					  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(DATEADD(DAY,VADEGUN,TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),TARIH),@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
				 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
				 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
				 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
				 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
				 LEFT JOIN MUH_GRUP AS GRUP3 WITH (NOLOCK) ON GY.DAIREID=GRUP3.GRUPID AND GRUP3.TIPID=8
				 LEFT JOIN SATISTEMSILCI AS S WITH (NOLOCK) ON H.YETKIID=S.SATISTEMSILCIID
				 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
				 WHERE GY.FIRMAID=@FIRMAID AND  DATEADD(DAY,VADEGUN,TARIH)>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
				  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,GRUP3.GRUPADI,H.DOVIZ,H.HESAPTIPID, S.ADSOYAD, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
				 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
				 ORDER BY  HESAPADI,DOVIZ		
			END
		ELSE
			BEGIN
				SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
				   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, GRUP3.GRUPADI AS HESAPADI2, S.ADSOYAD AS TEMSILCIADI, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
				   SUM(BORC) TOPLAMBORC, 
				   SUM(ALACAK) TOPLAMALACAK,
				   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
				   SUM(DBORC) DTOPLAMBORC, 
				   SUM(DALACAK) DTOPLAMALACAK,
				   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
				   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
				   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
					 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
				  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
					 CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
				  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
				  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
					  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
				 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
				 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
				 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
				 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
				 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
				 LEFT JOIN MUH_GRUP AS GRUP3 WITH (NOLOCK) ON GY.DAIREID=GRUP3.GRUPID AND GRUP3.TIPID=8
				 LEFT JOIN SATISTEMSILCI AS S WITH (NOLOCK) ON H.YETKIID=S.SATISTEMSILCIID
				 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
				 WHERE GY.FIRMAID=@FIRMAID AND VADE>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
				  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,GRUP3.GRUPADI,H.DOVIZ,H.HESAPTIPID, S.ADSOYAD, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
				 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
				 ORDER BY  HESAPADI,DOVIZ	
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGOSTER_SOZLESME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGOSTER_SOZLESME]  
 (@VADEYEGORE NVARCHAR(5),@TARIH nvarchar(10), @DONEMBASI nvarchar(10), @DONEMSONU nvarchar(10), @FIRMAID NVARCHAR(10), @DONEM1 INT, @DONEM2 INT, @DONEM3 INT, @DONEM4 INT, @DONEM5 INT) AS 
BEGIN
IF @VADEYEGORE='HAYIR'
	BEGIN
		SELECT * FROM (SELECT GY.SOZLESMEID, H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
		   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
		   SUM(BORC) TOPLAMBORC, 
		   SUM(ALACAK) TOPLAMALACAK,
		   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
		   SUM(DBORC) DTOPLAMBORC, 
		   SUM(DALACAK) DTOPLAMALACAK,
		   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(DATEADD(DAY,VADEGUN,GY.TARIH) AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN DATEADD(DAY,VADEGUN,GY.TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,GY.TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN  DATEADD(DAY,VADEGUN,GY.TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST( DATEADD(DAY,VADEGUN,GY.TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,GY.TARIH)<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN  DATEADD(DAY,VADEGUN,GY.TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(DATEADD(DAY,VADEGUN,GY.TARIH) AS INTEGER))/SUM(CASE WHEN  DATEADD(DAY,VADEGUN,GY.TARIH)>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,DATEADD(DAY,ISNULL(VADEGUN,0),GY.TARIH),@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
		 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
		 LEFT JOIN EMLAKSATIS AS EM WITH (NOLOCK) ON GY.SOZLESMEID=EM.EMLAKSATISID
		 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
		 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
		 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
		 WHERE GY.FIRMAID=@FIRMAID AND  DATEADD(DAY,VADEGUN,GY.TARIH)>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (GY.TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (GY.TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY GY.SOZLESMEID,GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ		
	END
ELSE
	BEGIN
		SELECT * FROM (SELECT GY.SOZLESMEID, H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
		   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, H.YETKIID, H.ACIKLAMA2 AS HESAPADI2, H.DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,ISNULL(VADEGUN,0) AS VADEGUN,
		   SUM(BORC) TOPLAMBORC, 
		   SUM(ALACAK) TOPLAMALACAK,
		   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
		   SUM(DBORC) DTOPLAMBORC, 
		   SUM(DALACAK) DTOPLAMALACAK,
		   SUM(DBORC)-SUM(DALACAK) AS DBAKIYE,
		   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
		   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
			 CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
		  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
			 CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
		  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
		  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
			  CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
		 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
		 '' AS HESAPOZELKOD1, '' AS HESAPOZELKOD2 
		 FROM YASLANDIRMA AS GY WITH (NOLOCK) INNER JOIN MUH_HESAP AS H WITH (NOLOCK) ON GY.HESAPID=H.HESAPID
		 LEFT JOIN EMLAKSATIS AS EM  WITH (NOLOCK) ON GY.SOZLESMEID=EM.EMLAKSATISID
		 LEFT JOIN MUH_GRUP AS GRUP1 WITH (NOLOCK) ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
		 LEFT JOIN MUH_GRUP AS GRUP2 WITH (NOLOCK) ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
		 LEFT JOIN QMUH_HESAPTIP AS TIP  ON H.HESAPTIPID=TIP.HESAPTIPID  
		 WHERE GY.FIRMAID=@FIRMAID AND VADE>=@DONEMBASI  AND  H.HESAPTIPID=120  AND  (GY.TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (GY.TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
		  GROUP BY GY.SOZLESMEID,GY.HESAPID,H.KODU,H.ACIKLAMA,H.YETKIID,H.ACIKLAMA2,H.DOVIZ,H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI,VADEGUN   
		 HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
		 ORDER BY  HESAPADI,DOVIZ	
	END
END
/*SUBEID,SUBEADI NI KALDIRDIK TÜMÜNÜ BİRADA GÖSTERSİN */
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGOSTERGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGOSTERGRUP]  
 (@TARIH SMALLDATETIME, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME, @DONEM1 INT, @DONEM2 INT, @DONEM3 INT, @DONEM4 INT, @DONEM5 INT) AS 
BEGIN 
SELECT * FROM (SELECT H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI AS HESAPGRUPADI1, GRUP2.GRUPADI AS HESAPGRUPADI2,
   GY.HESAPID,H.KODU AS HESAPKODU,H.ACIKLAMA AS HESAPADI, 'TL' AS DOVIZ, 1 AS SUBEID,'MERKEZ' AS SUBEADI, 0 AS MASMERID,'Tumu' AS MASMERADI,0 AS VADEGUN,
   SUM(BORC) TOPLAMBORC, 
   SUM(ALACAK) TOPLAMALACAK,
   SUM(BORC)-SUM(ALACAK) AS BAKIYE,
   SUM(ISNULL(ODENMEYEN,0)) AS TOPLAMTUTAR ,
   CASE WHEN ABS(SUM(ISNULL(ODENMEYEN,0)))>0.01 THEN 
     CAST(CAST(SUM(ISNULL(ODENMEYEN,0)*CAST(VADE AS INTEGER))/SUM(ISNULL(ODENMEYEN,0)) AS INT) AS DATETIME) ELSE NULL END  AS TOPLAMVADE ,
  SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMISTUTAR,
  CASE WHEN ABS(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)) >0.01 THEN 
     CAST(CAST(SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE<=@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME)  ELSE NULL END GECMISVADE,
  SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END)  GELECEKTUTAR,
  CASE WHEN ABS(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END))>0.01 THEN  
      CAST(CAST(SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END*CAST(VADE AS INTEGER))/SUM(CASE WHEN VADE>@TARIH THEN ISNULL(ODENMEYEN,0) ELSE 0 END) AS INT) AS DATETIME) ELSE NULL END GELECEKVADE,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM1 AND      -1  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM1,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM2 AND -(@DONEM1+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM2,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM3 AND -(@DONEM2+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM3,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM4 AND -(@DONEM3+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM4,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  -@DONEM5 AND -(@DONEM4+1) THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM5,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)                 <=-(@DONEM5+1)  THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GELECEK_DONEM6,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN        0  AND  @DONEM1 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM1,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM1+1)  AND  @DONEM2 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM2,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM2+1)  AND  @DONEM3 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM3,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM3+1)  AND  @DONEM4 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM4,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH) BETWEEN  (@DONEM4+1)  AND  @DONEM5 THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM5,
 SUM(CASE WHEN DATEDIFF(DAY,VADE,@TARIH)         >=(@DONEM5+1)           THEN ISNULL(ODENMEYEN,0) ELSE 0 END) GECMIS_DONEM6, 
 NULL AS HESAPOZELKOD1, NULL AS HESAPOZELKOD2 
 FROM GRUPYASLAN AS GY INNER JOIN MUH_HESAP AS H ON GY.HESAPID=H.HESAPID
 LEFT JOIN MUH_GRUP AS GRUP1 ON H.HESAPGRUPID1=GRUP1.GRUPID AND GRUP1.TIPID=1
 LEFT JOIN MUH_GRUP AS GRUP2 ON H.HESAPGRUPID2=GRUP2.GRUPID AND GRUP2.TIPID=2
 LEFT JOIN QMUH_HESAPTIP AS TIP ON H.HESAPTIPID=TIP.HESAPTIPID 
 WHERE VADE>=@DONEMBASI  AND  H.HESAPTIPID IN (120,320)   AND  (TARIH BETWEEN @DONEMBASI AND @DONEMSONU)  AND (TARIH  BETWEEN @DONEMBASI AND @DONEMSONU)
  GROUP BY GY.HESAPID,H.KODU,H.ACIKLAMA,H.HESAPTIPID, TIP.HESAPTIPADI, GRUP1.GRUPADI, GRUP2.GRUPADI
    HAVING ABS(SUM(BORC)-SUM(ALACAK))>0.4) TBL 
 ORDER BY  HESAPADI
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YASLANDIRMAGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YASLANDIRMAGRUP]  
 (@HESAPID INT, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@GRUPYASLANID INT,
	@BORC	FLOAT,
	@ALACAK	FLOAT,
	@ODENMEYEN FLOAT,
	@TOPLAMBORC FLOAT,
	@TOPLAMALACAK FLOAT,
	@KALAN FLOAT,
	@HESAPTIPID INT

	SELECT @HESAPTIPID=HESAPTIPID FROM MUH_HESAP WHERE HESAPID=@HESAPID
	SELECT @TOPLAMBORC=(SELECT SUM(BORC) FROM GRUPYASLAN WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)
	SELECT @TOPLAMALACAK=(SELECT SUM(ALACAK) FROM GRUPYASLAN WHERE HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU)

	IF @HESAPTIPID=120
		BEGIN 
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT GRUPYASLANID,BORC,ALACAK,ODENMEYEN FROM GRUPYASLAN WHERE BORC>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,GRUPYASLANID

			OPEN ODENMEYEN_HESAPLA
		END
	ELSE
		BEGIN
			DECLARE ODENMEYEN_HESAPLA CURSOR FOR
					
			SELECT GRUPYASLANID,BORC,ALACAK,ODENMEYEN FROM GRUPYASLAN WHERE ALACAK>0 AND HESAPID=@HESAPID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU ORDER BY TARIH,GRUPYASLANID

			OPEN ODENMEYEN_HESAPLA		
		END

	FETCH NEXT FROM ODENMEYEN_HESAPLA INTO @GRUPYASLANID,@ODENMEYEN,@BORC,@ALACAK

	WHILE @@FETCH_STATUS=0
		BEGIN
			IF @HESAPTIPID=120
				BEGIN
					SET @BORC=(SELECT ISNULL(BORC,0) FROM GRUPYASLAN WHERE HESAPID=@HESAPID AND GRUPYASLANID=@GRUPYASLANID)

					IF @TOPLAMALACAK-@BORC>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMALACAK-@BORC<0 SET @ODENMEYEN=(@TOPLAMALACAK-@BORC)*-1
					IF @TOPLAMALACAK<0 SET @ODENMEYEN=@BORC
					
					UPDATE GRUPYASLAN SET ODENMEYEN=@ODENMEYEN WHERE GRUPYASLANID=@GRUPYASLANID
					SET @TOPLAMALACAK=@TOPLAMALACAK-@BORC
				END
			ELSE
				BEGIN
					SET @ALACAK=(SELECT ISNULL(ALACAK,0) FROM GRUPYASLAN WHERE HESAPID=@HESAPID AND GRUPYASLANID=@GRUPYASLANID)

					IF @TOPLAMBORC-@ALACAK>=0 SET @ODENMEYEN=0.00
					IF @TOPLAMBORC-@ALACAK<0 SET @ODENMEYEN=(@TOPLAMBORC-@ALACAK)
					IF @TOPLAMBORC<0 SET @ODENMEYEN=@ALACAK*-1
					
					UPDATE GRUPYASLAN SET ODENMEYEN=@ODENMEYEN WHERE GRUPYASLANID=@GRUPYASLANID
					SET @TOPLAMBORC=@TOPLAMBORC-@ALACAK
				END
			
			FETCH NEXT FROM ODENMEYEN_HESAPLA  INTO @GRUPYASLANID,@ODENMEYEN,@BORC,@ALACAK		
		END
	CLOSE ODENMEYEN_HESAPLA
	DEALLOCATE ODENMEYEN_HESAPLA
END
GO
/****** Object:  StoredProcedure [dbo].[PR_YEVMIYESIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PR_YEVMIYESIL]  
(@SUBEID INT, @DONEMBASI DATETIME,@DONEMSONU DATETIME,@BASTARIH DATETIME,@BITTARIH DATETIME)
AS
BEGIN
  IF @DONEMBASI=NULL
  BEGIN
   RAISERROR('Dönem Bilgileri Olmadan Yevmiye No Silinemez',16,1)
   RETURN 1
  END
   UPDATE MUH_FIS SET FISDURUMID=ISNULL(ESKIFISDURUMID,1), -- eski fişdurumu zaten tutmustuk yoksa 1 muhasebeleştiye alıyoruz
   YEVMNO=NULL,YEVMTARIH=NULL,YEVMACIKLAMA=NULL, YEVSATIRSIRANO=NULL 
   WHERE ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID=@SUBEID

   UPDATE MUH_HESAPISL SET  YEVSATIRSIRANO=NULL   WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID=@SUBEID)

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_ACIKMASATASI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_ACIKMASATASI]  @YENITARIH NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE ADISYON SET TARIH='''+@YENITARIH+''' WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_ACIKMASATASI2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_ACIKMASATASI2]  @YENITARIH NVARCHAR(10),@PARAMETRE NVARCHAR(350), @ASAATI NVARCHAR(40)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
IF @ASAATI='' SET @SQLCUMLE='UPDATE ADISYON SET TARIH='''+@YENITARIH+''' WHERE 1=1 '+@PARAMETRE
IF @ASAATI<>'' SET @SQLCUMLE='UPDATE ADISYON SET TARIH='''+@YENITARIH+''', ASAATI='''+@ASAATI+' 10:10:10.00'' WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_ADISYONODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_ADISYONODEME]  @FISCOUNTER NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1000)
SET @SQLCUMLE='UPDATE ADISYON SET ONAKIT=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM ADSODEME WHERE ODEMETURID=1 AND FISCOUNTER='+@FISCOUNTER+'),0),
OKK=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=2 AND FISCOUNTER='+@FISCOUNTER+'),0),
OACIK=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=3 AND FISCOUNTER='+@FISCOUNTER+'),0),
OTICKET=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=4 AND FISCOUNTER='+@FISCOUNTER+'),0),
OTICKET2=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=5 AND FISCOUNTER='+@FISCOUNTER+'),0),
OTICKET3=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=6 AND FISCOUNTER='+@FISCOUNTER+'),0),
OTICKET4=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=7 AND FISCOUNTER='+@FISCOUNTER+'),0),
OTICKET5=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM ADSODEME WHERE ODEMETURID=8 AND FISCOUNTER='+@FISCOUNTER+'),0)
WHERE FISCOUNTER='+@FISCOUNTER
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_AYLIKVARDIYA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROC  [dbo].[PRE_AYLIKVARDIYA] (@FIRMAID NVARCHAR(10),@SUBEID NVARCHAR(10), @YIL NVARCHAR(4),@AY NVARCHAR(2), @DEPARTMANID NVARCHAR(10), @TUR NVARCHAR(5))
As
Begin
DECLARE @Sayac INT=1
DECLARE @GUN INT=31
DECLARE @XYIL INT
DECLARE @XAY INT
DECLARE @XFIRMAID INT
DECLARE @XSUBEID INT
DECLARE @XDEPARTMANID INT
DECLARE @XPSICILID INT
DECLARE @XIKVARDIYATANIMID INT
DECLARE @XVARDIYAKODU NVARCHAR(10)
DECLARE @IKVARDIYATANIMID INT
DECLARE @VARDIYAKODU NVARCHAR(10)
DECLARE @VGUN INT
DECLARE @IDLER NVARCHAR(500)
DECLARE @KODLAR NVARCHAR(800)
DECLARE @IDALANLAR NVARCHAR(300)
DECLARE @VALANLAR NVARCHAR(300)
DECLARE @SQLCUMLE NVARCHAR(MAX)
DECLARE @MESAI INT
DECLARE @DIGER INT

IF @TUR='OZEL'
	BEGIN
			DELETE FROM IKVARDIYAAYLIK WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID AND YIL=@YIL AND AY=@AY AND DEPARTMANID=@DEPARTMANID

			DECLARE AYLIK_CURSOR CURSOR FOR 
			--BURAYI DUZELTECEĞİZ. SADECE O DEPARTMANIN O AY İÇİNDE PUANTAJI OLANLARI GEİTRELİM
			--SELECT YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,IKVARDIYATANIMID,VARDIYAKODU FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID ORDER BY PSICILID,GUN
			SELECT DEPARTMANID,PSICILID FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE SUBEID=@SUBEID AND DEPARTMANID=@DEPARTMANID GROUP BY DEPARTMANID,PSICILID ORDER BY PSICILID
			OPEN AYLIK_CURSOR
  
			FETCH NEXT FROM AYLIK_CURSOR INTO @XDEPARTMANID,@XPSICILID
 
			  WHILE (@@FETCH_STATUS=0 )
			  BEGIN
					DECLARE V_CURSOR CURSOR FOR 
					SELECT IKVARDIYATANIMID, OZELKOD,GUN FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID AND PSICILID=@XPSICILID ORDER BY GUN

					SET @MESAI=0
					SET @DIGER=0
					SET @IDLER=''
					SET @KODLAR=''
					SET @IDALANLAR=''
					SET @VALANLAR=''

					OPEN V_CURSOR

					FETCH NEXT FROM V_CURSOR INTO @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
			
						  WHILE (@@FETCH_STATUS=0 )
								BEGIN
								if @VARDIYAKODU='X' SET @MESAI=@MESAI+1
								if @VARDIYAKODU<>'X' SET @DIGER=@DIGER+1

								SET @IDALANLAR=@IDALANLAR+'V'+CAST(@VGUN AS NVARCHAR(2))+','
								SET @VALANLAR=@VALANLAR+'K'+CAST(@VGUN AS NVARCHAR(2))+','

								IF @IKVARDIYATANIMID>0		SET @IDLER=@IDLER+CAST(@IKVARDIYATANIMID AS NVARCHAR(10))+','
								IF @IKVARDIYATANIMID=NULL   SET @IDLER=@IDLER+'NULL'+','

								IF @IKVARDIYATANIMID>0		SET @KODLAR=@KODLAR+''''+@VARDIYAKODU+''''+','
								IF @IKVARDIYATANIMID=NULL   SET @KODLAR=@KODLAR+''''++''''+','

							FETCH NEXT FROM V_CURSOR INTO  @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
						  END 
						CLOSE V_CURSOR 
					DEALLOCATE V_CURSOR
		
					--SET @IDLER=SUBSTRING(@IDLER,1,(LEN(@IDLER)-1))
					SET @KODLAR=SUBSTRING(@KODLAR,1,(LEN(@KODLAR)-1))
					SET @VALANLAR=SUBSTRING(@VALANLAR,1,(LEN(@VALANLAR)-1))

					SET @SQLCUMLE='INSERT INTO IKVARDIYAAYLIK (YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,TMESAI,TDIGER,'+@IDALANLAR+@VALANLAR+') 
					VALUES('+@YIL+','+@AY+','+@FIRMAID+','+@SUBEID+','+CAST(@XDEPARTMANID AS NVARCHAR(10))+','+CAST(@XPSICILID AS NVARCHAR(10))+','+CAST(@MESAI AS NVARCHAR(2))+','+CAST(@DIGER AS NVARCHAR(2))+','+@IDLER+@KODLAR+')'
					EXEC(@SQLCUMLE)
					--PRINT  @SQLCUMLE
				FETCH NEXT FROM AYLIK_CURSOR INTO  @XDEPARTMANID,@XPSICILID
			  END 
			  CLOSE AYLIK_CURSOR 
			  DEALLOCATE AYLIK_CURSOR
	END
IF @TUR='VK'
	BEGIN
			DELETE FROM IKVARDIYAAYLIK_PER WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID AND YIL=@YIL AND AY=@AY AND DEPARTMANID=@DEPARTMANID

			DECLARE AYLIK_CURSOR CURSOR FOR 
			--BURAYI DUZELTECEĞİZ. SADECE O DEPARTMANIN O AY İÇİNDE PUANTAJI OLANLARI GEİTRELİM
			--SELECT YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,IKVARDIYATANIMID,VARDIYAKODU FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID ORDER BY PSICILID,GUN
			SELECT DEPARTMANID,PSICILID FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE SUBEID=@SUBEID AND DEPARTMANID=@DEPARTMANID GROUP BY DEPARTMANID,PSICILID ORDER BY PSICILID
			OPEN AYLIK_CURSOR
  
			FETCH NEXT FROM AYLIK_CURSOR INTO @XDEPARTMANID,@XPSICILID
 
			  WHILE (@@FETCH_STATUS=0 )
			  BEGIN
					DECLARE V_CURSOR CURSOR FOR 
					SELECT IKVARDIYATANIMID, VARDIYAKODU,GUN FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID AND PSICILID=@XPSICILID ORDER BY GUN

					SET @MESAI=0
					SET @DIGER=0
					SET @IDLER=''
					SET @KODLAR=''
					SET @IDALANLAR=''
					SET @VALANLAR=''

					OPEN V_CURSOR

					FETCH NEXT FROM V_CURSOR INTO @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
			
						  WHILE (@@FETCH_STATUS=0 )
								BEGIN
								if @VARDIYAKODU='X' SET @MESAI=@MESAI+1
								if @VARDIYAKODU<>'X' SET @DIGER=@DIGER+1

								SET @IDALANLAR=@IDALANLAR+'V'+CAST(@VGUN AS NVARCHAR(2))+','
								SET @VALANLAR=@VALANLAR+'K'+CAST(@VGUN AS NVARCHAR(2))+','

								IF @IKVARDIYATANIMID>0		SET @IDLER=@IDLER+CAST(@IKVARDIYATANIMID AS NVARCHAR(10))+','
								IF @IKVARDIYATANIMID=NULL   SET @IDLER=@IDLER+'NULL'+','

								IF @IKVARDIYATANIMID>0		SET @KODLAR=@KODLAR+''''+@VARDIYAKODU+''''+','
								IF @IKVARDIYATANIMID=NULL   SET @KODLAR=@KODLAR+''''++''''+','

							FETCH NEXT FROM V_CURSOR INTO  @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
						  END 
						CLOSE V_CURSOR 
					DEALLOCATE V_CURSOR
		
					--SET @IDLER=SUBSTRING(@IDLER,1,(LEN(@IDLER)-1))
					SET @KODLAR=SUBSTRING(@KODLAR,1,(LEN(@KODLAR)-1))
					SET @VALANLAR=SUBSTRING(@VALANLAR,1,(LEN(@VALANLAR)-1))

					SET @SQLCUMLE='INSERT INTO IKVARDIYAAYLIK_PER (YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,TMESAI,TDIGER,'+@IDALANLAR+@VALANLAR+') 
					VALUES('+@YIL+','+@AY+','+@FIRMAID+','+@SUBEID+','+CAST(@XDEPARTMANID AS NVARCHAR(10))+','+CAST(@XPSICILID AS NVARCHAR(10))+','+CAST(@MESAI AS NVARCHAR(2))+','+CAST(@DIGER AS NVARCHAR(2))+','+@IDLER+@KODLAR+')'
					EXEC(@SQLCUMLE)
					--PRINT  @SQLCUMLE
				FETCH NEXT FROM AYLIK_CURSOR INTO  @XDEPARTMANID,@XPSICILID
			  END 
			  CLOSE AYLIK_CURSOR 
			  DEALLOCATE AYLIK_CURSOR
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_AYLIKVARDIYA_TEST]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROC  [dbo].[PRE_AYLIKVARDIYA_TEST] (@FIRMAID NVARCHAR(10),@SUBEID NVARCHAR(10), @YIL NVARCHAR(4),@AY NVARCHAR(2), @DEPARTMANID NVARCHAR(10), @TUR NVARCHAR(5))
As
Begin
DECLARE @Sayac INT=1
DECLARE @GUN INT=31
DECLARE @XYIL INT
DECLARE @XAY INT
DECLARE @XFIRMAID INT
DECLARE @XSUBEID INT
DECLARE @XDEPARTMANID INT
DECLARE @XPSICILID INT
DECLARE @XIKVARDIYATANIMID INT
DECLARE @XVARDIYAKODU NVARCHAR(10)
DECLARE @IKVARDIYATANIMID INT
DECLARE @VARDIYAKODU NVARCHAR(10)
DECLARE @VGUN INT
DECLARE @IDLER NVARCHAR(500)
DECLARE @KODLAR NVARCHAR(800)
DECLARE @IDALANLAR NVARCHAR(300)
DECLARE @VALANLAR NVARCHAR(300)
DECLARE @SQLCUMLE NVARCHAR(MAX)
DECLARE @MESAI INT
DECLARE @DIGER INT

IF @TUR='OZEL'
	BEGIN
			DELETE FROM IKVARDIYAAYLIK WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID AND YIL=@YIL AND AY=@AY AND DEPARTMANID=@DEPARTMANID

			DECLARE AYLIK_CURSOR CURSOR FOR 
			--BURAYI DUZELTECEĞİZ. SADECE O DEPARTMANIN O AY İÇİNDE PUANTAJI OLANLARI GEİTRELİM
			--SELECT YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,IKVARDIYATANIMID,VARDIYAKODU FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID ORDER BY PSICILID,GUN
			SELECT DEPARTMANID,PSICILID FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE SUBEID=@SUBEID AND DEPARTMANID=@DEPARTMANID GROUP BY DEPARTMANID,PSICILID ORDER BY PSICILID
			OPEN AYLIK_CURSOR
  
			FETCH NEXT FROM AYLIK_CURSOR INTO @XDEPARTMANID,@XPSICILID
 
			  WHILE (@@FETCH_STATUS=0 )
			  BEGIN
					DECLARE V_CURSOR CURSOR FOR 
					SELECT IKVARDIYATANIMID, OZELKOD,GUN FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID AND PSICILID=@XPSICILID ORDER BY GUN

					SET @MESAI=0
					SET @DIGER=0
					SET @IDLER=''
					SET @KODLAR=''
					SET @IDALANLAR=''
					SET @VALANLAR=''

					OPEN V_CURSOR

					FETCH NEXT FROM V_CURSOR INTO @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
			
						  WHILE (@@FETCH_STATUS=0 )
								BEGIN
								if @VARDIYAKODU='X' SET @MESAI=@MESAI+1
								if @VARDIYAKODU<>'X' SET @DIGER=@DIGER+1

								SET @IDALANLAR=@IDALANLAR+'V'+CAST(@VGUN AS NVARCHAR(2))+','
								SET @VALANLAR=@VALANLAR+'K'+CAST(@VGUN AS NVARCHAR(2))+','

								IF @IKVARDIYATANIMID>0		SET @IDLER=@IDLER+CAST(@IKVARDIYATANIMID AS NVARCHAR(10))+','
								IF @IKVARDIYATANIMID=NULL   SET @IDLER=@IDLER+'NULL'+','

								IF @IKVARDIYATANIMID>0		SET @KODLAR=@KODLAR+''''+@VARDIYAKODU+''''+','
								IF @IKVARDIYATANIMID=NULL   SET @KODLAR=@KODLAR+''''++''''+','

							FETCH NEXT FROM V_CURSOR INTO  @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
						  END 
						CLOSE V_CURSOR 
					DEALLOCATE V_CURSOR
		
					--SET @IDLER=SUBSTRING(@IDLER,1,(LEN(@IDLER)-1))
					SET @KODLAR=SUBSTRING(@KODLAR,1,(LEN(@KODLAR)-1))
					SET @VALANLAR=SUBSTRING(@VALANLAR,1,(LEN(@VALANLAR)-1))

					SET @SQLCUMLE='INSERT INTO IKVARDIYAAYLIK (YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,TMESAI,TDIGER,'+@IDALANLAR+@VALANLAR+') 
					VALUES('+@YIL+','+@AY+','+@FIRMAID+','+@SUBEID+','+CAST(@XDEPARTMANID AS NVARCHAR(10))+','+CAST(@XPSICILID AS NVARCHAR(10))+','+CAST(@MESAI AS NVARCHAR(2))+','+CAST(@DIGER AS NVARCHAR(2))+','+@IDLER+@KODLAR+')'
				--	EXEC(@SQLCUMLE)
					PRINT  @SQLCUMLE
				FETCH NEXT FROM AYLIK_CURSOR INTO  @XDEPARTMANID,@XPSICILID
			  END 
			  CLOSE AYLIK_CURSOR 
			  DEALLOCATE AYLIK_CURSOR
	END
IF @TUR='VK'
	BEGIN
			DELETE FROM IKVARDIYAAYLIK WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID AND YIL=@YIL AND AY=@AY AND DEPARTMANID=@DEPARTMANID

			DECLARE AYLIK_CURSOR CURSOR FOR 
			--BURAYI DUZELTECEĞİZ. SADECE O DEPARTMANIN O AY İÇİNDE PUANTAJI OLANLARI GEİTRELİM
			--SELECT YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,IKVARDIYATANIMID,VARDIYAKODU FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID ORDER BY PSICILID,GUN
			SELECT DEPARTMANID,PSICILID FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE SUBEID=@SUBEID AND DEPARTMANID=@DEPARTMANID GROUP BY DEPARTMANID,PSICILID ORDER BY PSICILID
			OPEN AYLIK_CURSOR
  
			FETCH NEXT FROM AYLIK_CURSOR INTO @XDEPARTMANID,@XPSICILID
 
			  WHILE (@@FETCH_STATUS=0 )
			  BEGIN
					DECLARE V_CURSOR CURSOR FOR 
					SELECT IKVARDIYATANIMID, VARDIYAKODU,GUN FROM [FNCQ_VARDIYA_ANALIZ] (@FIRMAID,@YIL,@AY) WHERE DEPARTMANID=@DEPARTMANID AND PSICILID=@XPSICILID ORDER BY GUN

					SET @MESAI=0
					SET @DIGER=0
					SET @IDLER=''
					SET @KODLAR=''
					SET @IDALANLAR=''
					SET @VALANLAR=''

					OPEN V_CURSOR

					FETCH NEXT FROM V_CURSOR INTO @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
			
						  WHILE (@@FETCH_STATUS=0 )
								BEGIN
								if @VARDIYAKODU='X' SET @MESAI=@MESAI+1
								if @VARDIYAKODU<>'X' SET @DIGER=@DIGER+1

								SET @IDALANLAR=@IDALANLAR+'V'+CAST(@VGUN AS NVARCHAR(2))+','
								SET @VALANLAR=@VALANLAR+'K'+CAST(@VGUN AS NVARCHAR(2))+','

								IF @IKVARDIYATANIMID>0		SET @IDLER=@IDLER+CAST(@IKVARDIYATANIMID AS NVARCHAR(10))+','
								IF @IKVARDIYATANIMID=NULL   SET @IDLER=@IDLER+'NULL'+','

								IF @IKVARDIYATANIMID>0		SET @KODLAR=@KODLAR+''''+@VARDIYAKODU+''''+','
								IF @IKVARDIYATANIMID=NULL   SET @KODLAR=@KODLAR+''''++''''+','

							FETCH NEXT FROM V_CURSOR INTO  @IKVARDIYATANIMID, @VARDIYAKODU, @VGUN
						  END 
						CLOSE V_CURSOR 
					DEALLOCATE V_CURSOR
		
					--SET @IDLER=SUBSTRING(@IDLER,1,(LEN(@IDLER)-1))
					SET @KODLAR=SUBSTRING(@KODLAR,1,(LEN(@KODLAR)-1))
					SET @VALANLAR=SUBSTRING(@VALANLAR,1,(LEN(@VALANLAR)-1))

					SET @SQLCUMLE='INSERT INTO IKVARDIYAAYLIK (YIL,AY,FIRMAID,SUBEID,DEPARTMANID,PSICILID,TMESAI,TDIGER,'+@IDALANLAR+@VALANLAR+') 
					VALUES('+@YIL+','+@AY+','+@FIRMAID+','+@SUBEID+','+CAST(@XDEPARTMANID AS NVARCHAR(10))+','+CAST(@XPSICILID AS NVARCHAR(10))+','+CAST(@MESAI AS NVARCHAR(2))+','+CAST(@DIGER AS NVARCHAR(2))+','+@IDLER+@KODLAR+')'
					--EXEC(@SQLCUMLE)
					PRINT  @SQLCUMLE
				FETCH NEXT FROM AYLIK_CURSOR INTO  @XDEPARTMANID,@XPSICILID
			  END 
			  CLOSE AYLIK_CURSOR 
			  DEALLOCATE AYLIK_CURSOR
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODADETEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRE_BARKODADETEKLE]  @MIKTAR INT, @STOKID INT, @SUBEID INT, @DEPOID INT, @FIRMAID INT, @BARKOD NVARCHAR(30)
AS
SET NOCOUNT ON
BEGIN
DECLARE @SAYAC INT=1
	DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	IF @BARKOD=''
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BARKOD,FIYATI,BIRIM) SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,BARKOD,SFIYAT1,BIRIM FROM STOK WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
	ELSE
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BARKOD,FIYATI,BIRIM) SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@BARKOD,SFIYAT1,BIRIM FROM STOK WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODADETSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRE_BARKODADETSIL]  @FIRMAID INT, @SUBEID INT, @DEPOID INT
AS
BEGIN
if @DEPOID>0
	BEGIN
		DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID
	END
ELSE
	BEGIN
		DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODARTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_BARKODARTIR] @FIRMAID NVARCHAR(10)
AS
BEGIN
	IF (SELECT COUNT(*) FROM FIRMABARKOD WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0)>0
		BEGIN
			UPDATE FIRMABARKOD SET BARKOD=BARKOD+1 WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0
		END
	ELSE
		BEGIN
			INSERT INTO FIRMABARKOD (FIRMAID,BARKOD) VALUES(@FIRMAID,'11100001')
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODARTIR2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_BARKODARTIR2] @FIRMAID NVARCHAR(10), @TUR NVARCHAR(10)
AS
BEGIN
DECLARE
@SIRANO NVARCHAR(20)
	IF (SELECT COUNT(*) FROM FIRMABARKOD WHERE TUR=@TUR AND FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0)>0
		BEGIN
			UPDATE FIRMABARKOD SET BARKOD=BARKOD+1 WHERE TUR=@TUR AND FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0
		END
	ELSE
		BEGIN
			SET @SIRANO='3300001'
			IF @TUR='STOK'		SET @SIRANO='3300001'
			IF @TUR='RENKBEDEN' SET @SIRANO='2700001'
			IF @TUR='MUH_HESAP' SET @SIRANO='11100001'			
			IF @TUR='MUH_HESAP' SET @SIRANO='00000001'
			IF @TUR='120'		SET @SIRANO='12010001'
			IF @TUR='320'		SET @SIRANO='32010001'
			IF @TUR='100' 		SET @SIRANO='10010001'
			IF @TUR='101' 		SET @SIRANO='10110001'
			IF @TUR='102'		SET @SIRANO='10210001'
			IF @TUR='103'		SET @SIRANO='10310001'
			IF @TUR='150'		SET @SIRANO='15010001'
			IF @TUR='7'			SET @SIRANO='70010001'
			IF @TUR='6'			SET @SIRANO='60010001'
			IF @TUR='191'		SET @SIRANO='19110001'
			IF @TUR='391'		SET @SIRANO='39110001'				
			IF @TUR='900'		SET @SIRANO='90010001'	
			IF @TUR='800'		SET @SIRANO='80010001'		
			IF @TUR='335'		SET @SIRANO='33510001'		
			IF @TUR='331'		SET @SIRANO='33110001'
			IF @TUR='PLU'		SET @SIRANO='1001'
			
			INSERT INTO FIRMABARKOD (FIRMAID,TUR,BARKOD) VALUES(@FIRMAID,@TUR,@SIRANO)				

		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_BARKODEKLE] @FIRMAID INT, @STOKID INT,@BARKOD NVARCHAR(30), 
@BARKOD2 NVARCHAR(30),@BARKOD3 NVARCHAR(30),@BARKOD4 NVARCHAR(30),@BARKOD5 NVARCHAR(30),
@BIRIM NVARCHAR(20), @BIRIM2 NVARCHAR(20),@BIRIM3 NVARCHAR(20),@BIRIM4 NVARCHAR(20),@BIRIM5 NVARCHAR(20),
@KATSAYI FLOAT,@KATSAYI2 FLOAT,@KATSAYI3 FLOAT,@KATSAYI4 FLOAT,@KATSAYI5 FLOAT
AS
BEGIN
IF @BARKOD<>''
	BEGIN
		INSERT INTO BARKOD (FIRMAID,STOKID,BARKOD,BIRIM,BIRIMID,DMIKTAR) VALUES(@FIRMAID,@STOKID,@BARKOD,@BIRIM,9,@KATSAYI)
	END
IF @BARKOD2<>''
	BEGIN
		INSERT INTO BARKOD (FIRMAID,STOKID,BARKOD,BIRIM,BIRIMID,DMIKTAR) VALUES(@FIRMAID,@STOKID,@BARKOD2,@BIRIM2,2,@KATSAYI2)
	END
IF @BARKOD3<>''
	BEGIN
		INSERT INTO BARKOD (FIRMAID,STOKID,BARKOD,BIRIM,BIRIMID,DMIKTAR) VALUES(@FIRMAID,@STOKID,@BARKOD3,@BIRIM3,3,@KATSAYI3)
	END
IF @BARKOD4<>''
	BEGIN
		INSERT INTO BARKOD (FIRMAID,STOKID,BARKOD,BIRIM,BIRIMID,DMIKTAR) VALUES(@FIRMAID,@STOKID,@BARKOD4,@BIRIM4,4,@KATSAYI4)
	END
IF @BARKOD5<>''
	BEGIN
		INSERT INTO BARKOD (FIRMAID,STOKID,BARKOD,BIRIM,BIRIMID,DMIKTAR) VALUES(@FIRMAID,@STOKID,@BARKOD5,@BIRIM5,5,@KATSAYI5)
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_BARKODSIL] @STOKID INT
AS
BEGIN
DELETE FROM BARKOD WHERE STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BARKODUPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_BARKODUPDATE] @FIRMAID INT, @STOKID INT, 
@BIRIM NVARCHAR(10), @BIRIM2 NVARCHAR(10), @BIRIM3 NVARCHAR(10), @BIRIM4 NVARCHAR(10), @BIRIM5 NVARCHAR(10),
@KATSAYI FLOAT,@KATSAYI2 FLOAT,@KATSAYI3 FLOAT,@KATSAYI4 FLOAT,@KATSAYI5 FLOAT
AS
BEGIN
UPDATE BARKOD SET BARKOD.BIRIM=@BIRIM, BARKOD.DMIKTAR=@KATSAYI WHERE BARKOD.BIRIMID=1 AND STOKID=@STOKID
UPDATE BARKOD SET BARKOD.BIRIM=@BIRIM2, BARKOD.DMIKTAR=@KATSAYI2 WHERE BARKOD.BIRIMID=2 AND STOKID=@STOKID
UPDATE BARKOD SET BARKOD.BIRIM=@BIRIM3, BARKOD.DMIKTAR=@KATSAYI3 WHERE BARKOD.BIRIMID=3 AND STOKID=@STOKID
UPDATE BARKOD SET BARKOD.BIRIM=@BIRIM4, BARKOD.DMIKTAR=@KATSAYI4 WHERE BARKOD.BIRIMID=4 AND STOKID=@STOKID
UPDATE BARKOD SET BARKOD.BIRIM=@BIRIM5, BARKOD.DMIKTAR=@KATSAYI5 WHERE BARKOD.BIRIMID=5 AND STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BRUTMAASHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROC  [dbo].[PRE_BRUTMAASHESAPLA](@FIRMAID INT,@SUBEID INT, @YIL INT,@AY INT, @FIYATTIPI NVARCHAR(1))
As
Begin
DECLARE @Sayac INT=1--@KGVM @SGKMatrah
DECLARE @KGVM  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @SGKMatrah  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @BRUT  DECIMAL(15,4)=0.00--@KGVM @SGKMatrah
DECLARE @GVMATRAH  DECIMAL(15,4)=0
DECLARE @KUMULATIF_GV_MATRAHI DECIMAL(15,4)=0
DECLARE @DEPID INT
DECLARE @UNVANID INT
DECLARE @NET DECIMAL(15,4)
DECLARE @NET1 DECIMAL(15,4)
DECLARE @NET2 DECIMAL(15,4)
DECLARE @NET3 DECIMAL(15,4)
DECLARE @NET4 DECIMAL(15,4)
DECLARE @NET5 DECIMAL(15,4)
DECLARE @SQLCUMLE NVARCHAR(800)

DELETE FROM PERBUTCE WHERE FIRMAID=@FIRMAID and @SUBEID=@SUBEID

DECLARE UNVAN_CURSOR CURSOR FOR 

SELECT PERUNVANID,DEPID,BUTCEUCRET1,BUTCEUCRET2,BUTCEUCRET3,BUTCEUCRET4,BUTCEUCRET5 FROM PERUNVAN WHERE FIRMAID=@FIRMAID ORDER BY DEPID,PERUNVANID

OPEN UNVAN_CURSOR
  
FETCH NEXT FROM UNVAN_CURSOR INTO @UNVANID,@DEPID,@NET1,@NET2,@NET3,@NET4,@NET5
  
  WHILE (@@FETCH_STATUS=0 )
  BEGIN
			IF @FIYATTIPI='1' SET @NET=@NET1
			IF @FIYATTIPI='2' SET @NET=@NET2
			IF @FIYATTIPI='3' SET @NET=@NET3
			IF @FIYATTIPI='4' SET @NET=@NET4
			IF @FIYATTIPI='5' SET @NET=@NET5

			SET @Sayac=1
			SET @KGVM=0.00--@KGVM @SGKMatrah
			SET @SGKMatrah=0.00--@KGVM @SGKMatrah
			SET @BRUT=0.00--@KGVM @SGKMatrah
			SET @GVMATRAH=0
			SET @KUMULATIF_GV_MATRAHI=0

			IF @NET>0
				BEGIN
					WHILE (@Sayac<=@AY)
						BEGIN 

								IF(@SAYAC=1)
								BEGIN
										SELECT @BRUT= [dbo].[Brut](@NET,0.00,0.00,@YIL,@FIRMAID)
										SELECT @GVMATRAH=[dbo].[GV_MATRAH] (@BRUT,@YIL ,@FIRMAID)
					
										INSERT INTO [dbo].[PERBUTCE] (YIL,AY,NETMAAS,BRUTMAAS,SSKISVEREN,ISSIZLIKISVEREN,GVMATRAH,KUMGVMATRAH,FIRMAID,SUBEID,DEPID,UNVANID)
										VALUES (@YIL,@Sayac,@NET,@BRUT,(@BRUT/100)*20.5,(@BRUT/100)*2,@GVMATRAH,0.00,@FIRMAID,@SUBEID,@DEPID,@UNVANID)
								END
								IF(@Sayac>1)
								BEGIN
										SELECT @KUMULATIF_GV_MATRAHI=SUM(GVMATRAH) FROM PERBUTCE WHERE YIL=@YIL AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPID=@DEPID AND UNVANID=@UNVANID
										SELECT @BRUT= [dbo].[Brut](@NET,@KUMULATIF_GV_MATRAHI,0.00,@YIL,@FIRMAID)
										SELECT @GVMATRAH=[dbo].[GV_MATRAH](@BRUT,@YIL ,@FIRMAID)
										INSERT INTO [dbo].[PERBUTCE] (YIL,AY,NETMAAS,BRUTMAAS,SSKISVEREN,ISSIZLIKISVEREN,GVMATRAH,KUMGVMATRAH,FIRMAID,SUBEID,DEPID,UNVANID)
										VALUES (@YIL,@Sayac,@NET,@BRUT,(@BRUT/100)*20.5,(@BRUT/100)*2,@GVMATRAH,@KUMULATIF_GV_MATRAHI,@FIRMAID,@SUBEID,@DEPID,@UNVANID)
								END
							SET @Sayac=@Sayac+1
						END
				END
	FETCH NEXT FROM UNVAN_CURSOR INTO @UNVANID ,@DEPID, @NET1,@NET2,@NET3,@NET4,@NET5
  END 
  CLOSE UNVAN_CURSOR 
  DEALLOCATE UNVAN_CURSOR
SET @SAYAC=1
WHILE (@Sayac<=12)
	BEGIN
		SET @SQLCUMLE='UPDATE PERBUTCEGIRIS SET AY'+CAST(@Sayac AS NVARCHAR(2))+'_MAAS=BRUTMAAS+ISNULL(SSKISVEREN,0)+ISNULL(ISSIZLIKISVEREN,0) FROM PERBUTCEGIRIS 
		INNER JOIN PERBUTCE ON PERBUTCEGIRIS.FIRMAID=PERBUTCE.FIRMAID AND PERBUTCEGIRIS.SUBEID=PERBUTCE.SUBEID
		AND PERBUTCEGIRIS.DEPID=PERBUTCE.DEPID AND PERBUTCEGIRIS.UNVANID=PERBUTCE.UNVANID 
		WHERE PERBUTCE.FIRMAID='+CAST(@FIRMAID AS NVARCHAR(10))+' AND PERBUTCE.SUBEID='+CAST(@SUBEID AS NVARCHAR(10))+' AND 
		PERBUTCE.YIL='+CAST(@YIL AS NVARCHAR(4))+' AND PERBUTCE.AY='+CAST(@Sayac AS NVARCHAR(2))
		EXEC(@SQLCUMLE)
		SET @Sayac=@Sayac+1
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_BUTCEGIRIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_BUTCEGIRIS]  @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @YIL NVARCHAR(4)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='INSERT INTO PERBUTCEGIRIS (FIRMAID,SUBEID,DEPID,UNVANID,DEPKODU,UNVANKODU,YIL) SELECT '+@FIRMAID+','+@SUBEID+',PERUNVAN.DEPID,PERUNVANID,PERUNVAN.DEPKODU,
PERUNVAN.UNVANKODU,'+@YIL+' FROM PERUNVAN WHERE FIRMAID='+@FIRMAID+' AND CAST(PERUNVANID AS NVARCHAR(5))+UNVANKODU
NOT IN(SELECT CAST(UNVANID AS NVARCHAR(5))+UNVANKODU FROM PERBUTCEGIRIS WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_CALLUPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_CALLUPDATE]  @CALLSIPARISID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE CALLSIPARIS SET CALLSIPARIS.CARIID=CARIKART.CARIID 
   FROM CALLSIPARIS INNER JOIN CARIKART ON CALLSIPARIS.TEL=CARIKART.CEPTEL WHERE CALLSIPARIS.CARIID IS NULL AND  CALLSIPARISID=0'+@CALLSIPARISID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE CALLSIPARIS SET CALLSIPARIS.CARIID=CARIKART.CARIID 
   FROM CALLSIPARIS INNER JOIN CARIKART ON CALLSIPARIS.TEL=CARIKART.TEL1 WHERE CALLSIPARIS.CARIID IS NULL AND  CALLSIPARISID=0'+@CALLSIPARISID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE CALLSIPARIS SET CALLSIPARIS.CARIID=CARIKART.CARIID 
   FROM CALLSIPARIS INNER JOIN CARIKART ON CALLSIPARIS.TEL=CARIKART.TEL2 WHERE CALLSIPARIS.CARIID IS NULL AND  CALLSIPARISID=0'+@CALLSIPARISID
EXEC (@SQLCUMLE)

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_CALLUPDATE_CARIID]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_CALLUPDATE_CARIID]  @CARIID NVARCHAR(10), @CALLSIPARISID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE CALLSIPARIS SET CARIID='+@CARIID+
      ' WHERE CALLSIPARISID=0'+@CALLSIPARISID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_CALLUPDATE_DURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_CALLUPDATE_DURUM]  @DURUM NVARCHAR(20), @CALLSIPARISID NVARCHAR(10), @CIKISSAATI NVARCHAR(25), @FISCOUNTER NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @CIKISSAATI=''
	BEGIN
		SET @SQLCUMLE='UPDATE CALLSIPARIS SET FISCOUNTER='+@FISCOUNTER+', PAKETDURUMU='''+@DURUM+'''  WHERE CALLSIPARISID=0'+@CALLSIPARISID
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='UPDATE CALLSIPARIS SET FISCOUNTER='+@FISCOUNTER+', PAKETDURUMU='''+@DURUM+''', CIKISSAATI='''+@CIKISSAATI+'''  WHERE CALLSIPARISID=0'+@CALLSIPARISID
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_CEKGUNCELLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_CEKGUNCELLE]  @FISID INT, @CEKID INT, @HESAPID INT ,@ALTCARIID INT, @CEKHESAPID INT, @CEKALTCARIID INT
AS
SET NOCOUNT ON
BEGIN
UPDATE CEKLER SET SONFISID=@FISID, SONHESAPID=@HESAPID, SONALTCARIID=@ALTCARIID, SONCEKHESAPID=@CEKHESAPID, SONCEKALTCARIID=@CEKALTCARIID
WHERE CEKID=@CEKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_DEPSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_DEPSIL]
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='TRUNCATE TABLE PERELEKTRADEP'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_DOVIZEKLESIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRE_DOVIZEKLESIL]  @ISLEM NVARCHAR(10), @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @ISLEM='SIL'
	BEGIN
		SET @SQLCUMLE='DELETE FROM DOVIZISL WHERE 1=1 '+@PARAMETRE
		EXEC (@SQLCUMLE)
	END
ELSE IF @ISLEM='EKLE'
	BEGIN
		SET @SQLCUMLE=@PARAMETRE
		EXEC (@SQLCUMLE)
	END
ELSE IF @ISLEM='DUZELT'
	BEGIN
		SET @SQLCUMLE='UPDATE DOVIZISL SET DOVIZISL.KODU=DOVIZ.KODU FROM DOVIZISL INNER JOIN DOVIZ ON DOVIZISL.KODU=DOVIZ.TCMBKODU
		WHERE 1=1 '+@PARAMETRE
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_EFATURA_TEMP_AKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_EFATURA_TEMP_AKTAR] @TABLOADI NVARCHAR(50), @KONTROL NVARCHAR(1), @TARIH NVARCHAR(12)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @KONTROL='H'
	BEGIN
			SET @SQLCUMLE='SET ANSI_WARNINGS  OFF '
								 + ' TRUNCATE TABLE EFATURA_FIRMA'
								 + ' INSERT INTO EFATURA_FIRMA (VDNO,KODU,UNVANI,TIPI,KAYITTARIHI,FIRMATIPI) '
								 + ' SELECT VDNO,KODU,UNVANI,TIPI,KAYITTARIHI,FIRMATIPI FROM ' + @TABLOADI
								 +' DROP TABLE ' + @TABLOADI
			EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
			SET @SQLCUMLE='SET ANSI_WARNINGS  OFF '
								 + ' DELETE FROM EFATURA_FIRMA WHERE KAYITTARIHI>='''+@TARIH+''''
								 + ' INSERT INTO EFATURA_FIRMA (VDNO,KODU,UNVANI,TIPI,KAYITTARIHI,FIRMATIPI) '
								 + ' SELECT VDNO,KODU,UNVANI,TIPI,KAYITTARIHI,FIRMATIPI FROM ' + @TABLOADI
								 +' DROP TABLE ' + @TABLOADI
			EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_EFATURA_TEMP_OLUSTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_EFATURA_TEMP_OLUSTUR] @TABLOADI NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP 0 * INTO ' + @TABLOADI + ' FROM EFATURA_FIRMA';
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_FATURA_MAHSUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_FATURA_MAHSUP]  
 (@FIRMAID INT,@SUBEID INT,@TARIH1 SMALLDATETIME, @TARIH2 SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@FISID INT,
	@FATID INT,
	@FISUUID uniqueidentifier
			DECLARE MAHSUP_EKLE CURSOR FOR
					
			SELECT FATID FROM FATURA WITH (NOLOCK)  WHERE SUBEID=@SUBEID AND FIRMAID=@FIRMAID AND ISNULL(MUHFC,0)=0 AND TARIH BETWEEN @TARIH1 AND @TARIH2 order by TARIH

			OPEN MAHSUP_EKLE		

			FETCH NEXT FROM MAHSUP_EKLE INTO @FATID

	WHILE @@FETCH_STATUS=0
		BEGIN
			set @FISUUID=NEWID()
			
			INSERT INTO  MUH_FIS (FISUUID,TARIH,FISNO,FISTURID,FISTURU,MODULID,MODULEKRANID,FIRMAID,SUBEID,FISDURUMID,DETAYLIENTEGRE,ADD_DATE,ADD_USERID,ACIKLAMA,BELGENO,ENTKAYNAKID,ENTKAYNAK)
			SELECT @FISUUID,TARIH,'0000001' AS FISNO,41 AS FISTURID,'Mahsup' AS FISTURU,1,1,@FIRMAID,@SUBEID,1,1,TARIH,-1,FISTURADI+ ' Fatura Entegrasyonu','',DEPOFISID,'TUKETIMFIS' FROM FATURA WITH (NOLOCK) 
			WHERE FATID=@FATID

			SET @FISID=(SELECT FISID FROM MUH_FIS WHERE FISUUID=@FISUUID)

			INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ)
			SELECT @FISID, ISNULL(HESAPID,-999),ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ FROM [FNCQ_FATURAMUH] (@FATID, @FIRMAID, @SUBEID) WHERE ISNULL(BORC,0)+ISNULL(ALACAK,0)>0
			
			UPDATE FATURA SET MUHFC=@FISID, FISIVAR=1, FISUUID=@FISUUID WHERE FATID=@FATID

			FETCH NEXT FROM MAHSUP_EKLE  INTO @FATID
		END
	CLOSE MAHSUP_EKLE
	DEALLOCATE MAHSUP_EKLE
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_FIRMAMODULSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_FIRMAMODULSIL]  @FIRMAID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='DELETE FROM FIRMAMODUL WHERE FIRMAID=0'+@FIRMAID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_FR_EKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE PROCEDURE [dbo].[PRE_FR_EKLE] @MASTERTABLE NVARCHAR(20), @MASTERTABLEALAN NVARCHAR(20), @ISLEMTABLO NVARCHAR(20), @ISLEMTABLOALAN NVARCHAR(20)
 AS
 DECLARE
 @FKNAME NVARCHAR(100),
 @SQLCUMLE NVARCHAR(350)

 SET @FKNAME='FKe_'+@ISLEMTABLO+'_'+@ISLEMTABLOALAN+'_'+@MASTERTABLE+'_'+@MASTERTABLEALAN
 SET @SQLCUMLE='IF OBJECT_ID('''+@FKNAME+''',''F'') IS NULL 
 ALTER TABLE '+@ISLEMTABLO+' ADD CONSTRAINT '+@FKNAME+' FOREIGN KEY ('+@ISLEMTABLOALAN+') REFERENCES '+@MASTERTABLE+' ('+@MASTERTABLEALAN+')'
 EXEC(@SQLCUMLE)
GO
/****** Object:  StoredProcedure [dbo].[PRE_HESAPAKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_HESAPAKTAR] @ILKHESAP NVARCHAR(10), @SONHESAP NVARCHAR(10), @FIRMAID NVARCHAR(10), @ILKALTCARI NVARCHAR(10), @SONALTCARI NVARCHAR(10),
@ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @USERID NVARCHAR(10), @HESABISIL NVARCHAR(5)
AS
IF (@ILKHESAP<>'') AND (@SONHESAP<>'') AND (@ILKALTCARI='') AND (@SONALTCARI='')
	 BEGIN
		UPDATE MUH_HESAPISL SET HESAPID=@SONHESAP WHERE HESAPID=@ILKHESAP AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH AND @SONTARIH) 
		UPDATE MUH_FIS SET FISHESAPID=@SONHESAP WHERE FISHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE FATURA SET FISHESAPID=@SONHESAP WHERE FISHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE MUH_BANKAEKSTRE_DETAY SET KARSIHESAPID=@SONHESAP WHERE KARSIHESAPID=@ILKHESAP AND BANKAEKSTREID IN(SELECT BANKAEKSTREID FROM MUH_BANKAEKSTRE WHERE FIRMAID=@FIRMAID AND TARIHSON BETWEEN @ILKTARIH AND @SONTARIH) 
		UPDATE TUKETIMFIS SET HESAPID=@SONHESAP WHERE HESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE TUKETIMFIS SET KHESAPID=@SONHESAP WHERE KHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH 
		UPDATE CEKLER SET CEKHESAPID=@SONHESAP WHERE CEKHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET SONHESAPID=@SONHESAP WHERE SONHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET SONCEKHESAPID=@SONHESAP WHERE SONCEKHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET HESAPID=@SONHESAP WHERE HESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE SERVISFORM SET CARIID=@SONHESAP WHERE CARIID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		IF @HESABISIL='EVET' 
			BEGIN
				UPDATE MUH_HESAP SET SIL=-2, KODU=KODU+' AKTARIM_SİLİNDİ',EDIT_USERID=@USERID WHERE HESAPID=@ILKHESAP
			END
	END
ELSE IF (@ILKHESAP<>'') AND (@SONHESAP<>'') AND (@ILKALTCARI<>'') AND (@SONALTCARI<>'')
	BEGIN
		UPDATE MUH_HESAPISL SET HESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE HESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH AND @SONTARIH) 
		UPDATE MUH_FIS SET FISHESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE FISHESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI  AND TARIH BETWEEN @ILKTARIH AND @SONTARIH 
		UPDATE FATURA SET FISHESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE FISHESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI  AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE MUH_BANKAEKSTRE_DETAY SET KARSIHESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE KARSIHESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI AND BANKAEKSTREID IN(SELECT BANKAEKSTREID FROM MUH_BANKAEKSTRE WHERE FIRMAID=@FIRMAID AND TARIHSON BETWEEN @ILKTARIH AND @SONTARIH) 
		UPDATE TUKETIMFIS SET HESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE HESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE TUKETIMFIS SET KHESAPID=@SONHESAP WHERE KHESAPID=@ILKHESAP AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET CEKHESAPID=@SONHESAP, CEKALTCARIID=@SONALTCARI WHERE CEKHESAPID=@ILKHESAP AND CEKALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET SONHESAPID=@SONHESAP, SONALTCARIID=@SONALTCARI WHERE SONHESAPID=@ILKHESAP AND SONALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET SONCEKHESAPID=@SONHESAP, SONCEKALTCARIID=@SONALTCARI WHERE SONCEKHESAPID=@ILKHESAP AND SONCEKALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE CEKLER SET HESAPID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE HESAPID=@ILKHESAP AND ALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		UPDATE SERVISFORM SET CARIID=@SONHESAP, ALTCARIID=@SONALTCARI WHERE CARIID=@ILKHESAP AND ALTCARIID=@ILKALTCARI AND TARIH BETWEEN @ILKTARIH AND @SONTARIH
		IF @HESABISIL='EVET'
			BEGIN
				UPDATE MUH_HESAP SET SIL=-2, KODU=KODU+' SİLİNDİ' WHERE HESAPID=@ILKHESAP
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRE_HESAPISLDUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRE_HESAPISLDUZELT]  @ALANTIPI NVARCHAR(10), @DALANTIPI NVARCHAR(10), @FISID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SELECT @ALANTIPI=ALANTIPI FROM QMUH_FISTUR WHERE FISTURID=(SELECT FISTURID FROM MUH_FIS WHERE FISID=@FISID)
IF @ALANTIPI='ALACAK'
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_HESAPISL SET BORC=0, ALACAK=0, DBORC=0, DALACAK=0 WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE MUH_HESAPISL SET BORC=TUTAR, DBORC=DTUTAR  WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)
	END
ELSE IF @ALANTIPI='BORC'
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_HESAPISL SET BORC=0, ALACAK=0, DBORC=0, DALACAK=0 WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE MUH_HESAPISL SET ALACAK=TUTAR, DALACAK=DTUTAR  WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_HESAPSONKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRE_HESAPSONKOD]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  MAX(KODU) AS SONKOD FROM MUH_HESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_HESPSONKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_HESPSONKOD]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SELECT MAX(KODU) AS SONKOD FROM MUH_HESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_HESSONKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRE_HESSONKOD]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SELECT MAX(KODU) AS SONKOD FROM MUH_HESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_ISLEMSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_ISLEMSIL]  @FIRMAID NVARCHAR(10), @FISID NVARCHAR(50), @FATSIL NVARCHAR(5), @USERID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @FATSIL='EVET'
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, TFISACIKLAMA=''SILINDI'', DEL_DATE=GETDATE(), DEL_USERID='+@USERID+' WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE FATURA SET SIL=-2, FISDURUMID=-2, IPTALACIKLAMA=''SILINDI'', DEL_DATE=GETDATE(), DEL_USERID='+@USERID+' WHERE MUHFC='''+@FISID+''''
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, TFISACIKLAMA=''SILINDI'', DEL_DATE=GETDATE(), DEL_USERID='+@USERID+' WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE FATURA SET FISUUID=NULL, MUHFC=NULL, FISIVAR=0 WHERE MUHFC='''+@FISID+''''
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_KILLSESSION]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_KILLSESSION] @KILL NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='KILL '+@KILL
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_KURUSDUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE  PROCEDURE [dbo].[PRE_KURUSDUZELT]  
 (@ID NVARCHAR(MAX)='0',@TARIH1 DATETIME,@TARIH2 DATETIME, @FIRMAID INT) AS  

  BEGIN  

  DECLARE @FISID INT  

  DECLARE @BALANCE FLOAT    

 

  DECLARE @FISIDS TABLE(FISID INT PRIMARY KEY) 

  INSERT INTO @FISIDS 

  SELECT DISTINCT CAST(splitdata AS INT) 

  FROM FN_SPLIT_STRING(@ID,',') 

  WHERE LEN(splitdata) > 0 

   

  IF ISNULL(@ID,'0')<>'0'  

  BEGIN 

  SET @ID=','+REPLACE(@ID,CHAR(39),'')+','   

   UPDATE MUH_HESAPISL SET ALACAK=0,BORC=BORC-ALACAK WHERE BORC>ALACAK AND ALACAK<>0  AND FISID IN(SELECT FISID FROM @FISIDS) 

			AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2) 

  

   UPDATE MUH_HESAPISL SET BORC=0,ALACAK=ALACAK-BORC WHERE BORC<ALACAK AND BORC<>0 AND FISID IN(SELECT FISID FROM @FISIDS) 

         AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

  DECLARE MUHFIS_CURSOR CURSOR  FOR  

                  SELECT FISID FROM MUH_HESAPISL (nolock) 

         WHERE ISNULL(SILINDI,0)=0 AND CHARINDEX(','+CAST(FISID AS NVARCHAR(20))+',',@ID)>0  

 				 AND FISID IN (SELECT FISID FROM MUH_FIS (nolock) WHERE FIRMAID=@FIRMAID AND ISNULL(YEVMNO,'0')='0' AND (MUH_FIS.TARIH BETWEEN @TARIH1 AND @TARIH2) AND ISNULL(FISDURUMID,0)>=0) 

         GROUP BY FISID  

          HAVING ABS((SUM(BORC)-SUM(ALACAK)))>0.00001 AND ABS((SUM(BORC)-SUM(ALACAK)))<0.05  

  END 

  ELSE  

  BEGIN 

   UPDATE MUH_HESAPISL SET ALACAK=0,BORC=BORC-ALACAK WHERE BORC>ALACAK AND ALACAK<>0  

			AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

     

   UPDATE MUH_HESAPISL SET BORC=0,ALACAK=ALACAK-BORC WHERE BORC<ALACAK AND BORC<>0

         AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

  DECLARE MUHFIS_CURSOR CURSOR FOR  

                  SELECT FISID FROM MUH_HESAPISL (nolock)  

 				          WHERE ISNULL(SILINDI,0)=0 AND FISID  IN (SELECT FISID FROM MUH_FIS (nolock)  WHERE FIRMAID=@FIRMAID AND ISNULL(YEVMNO,'0')='0' AND (MUH_FIS.TARIH BETWEEN @TARIH1 AND @TARIH2) AND ISNULL(FISDURUMID,0)>=0) 

                  GROUP BY FISID  

          HAVING ABS((SUM(BORC)-SUM(ALACAK)))>0.00001 AND ABS((SUM(BORC)-SUM(ALACAK)))<0.05  

  

  END   OPEN MUHFIS_CURSOR 

  FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID  

  WHILE(@@FETCH_STATUS = 0)  

  BEGIN  

  	 SELECT @BALANCE=(CASE WHEN ABS(SUM(BORC)-SUM(ALACAK))>0.00001 AND ABS(SUM(BORC)-SUM(ALACAK))<0.05 THEN SUM(BORC)-SUM(ALACAK) ELSE 0 END) FROM MUH_HESAPISL (nolock)      WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID  

      IF @BALANCE<> 0  

      BEGIN  

       IF @BALANCE>0  

       BEGIN  

        UPDATE MUH_HESAPISL  

        SET BORC=BORC-@BALANCE  

        WHERE BORC>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE  ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

        UPDATE MUH_HESAPISL  

        SET ALACAK=ALACAK+@BALANCE   

        WHERE ALACAK>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

       END  

       ELSE  

       IF @BALANCE<0  

       BEGIN  

        UPDATE MUH_HESAPISL  

        SET ALACAK=ALACAK-ABS(@BALANCE)  

        WHERE ALACAK>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND  FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

   

        UPDATE MUH_HESAPISL  

        SET BORC=BORC+ABS(@BALANCE)  

        WHERE BORC>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK)DESC) ORDER BY (BORC+ALACAK) DESC)  

       END  

   

       UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=MUH_FIS.FISID ) WHERE ISNULL(FISDURUMID,0)>=0 AND FISID=@FISID  

      END  

     FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID  

  END  

  CLOSE MUHFIS_CURSOR  

  DEALLOCATE MUHFIS_CURSOR  

  END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MAASARTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MAASARTIR] @FIRMAID INT, @ORAN FLOAT
AS
BEGIN
if @ORAN>0
	BEGIN
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET1=(BUTCEUCRET1/100)*(100+@ORAN) WHERE ISNULL(BUTCEUCRET1,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET2=(BUTCEUCRET2/100)*(100+@ORAN) WHERE ISNULL(BUTCEUCRET2,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET3=(BUTCEUCRET3/100)*(100+@ORAN) WHERE ISNULL(BUTCEUCRET3,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET4=(BUTCEUCRET4/100)*(100+@ORAN) WHERE ISNULL(BUTCEUCRET4,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET5=(BUTCEUCRET5/100)*(100+@ORAN) WHERE ISNULL(BUTCEUCRET5,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
	END
ELSE if @ORAN<0
	BEGIN
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET1=(BUTCEUCRET1/(100+ABS(@ORAN)))*100 WHERE ISNULL(BUTCEUCRET1,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET2=(BUTCEUCRET2/(100+ABS(@ORAN)))*100 WHERE ISNULL(BUTCEUCRET2,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET3=(BUTCEUCRET3/(100+ABS(@ORAN)))*100 WHERE ISNULL(BUTCEUCRET3,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET4=(BUTCEUCRET4/(100+ABS(@ORAN)))*100 WHERE ISNULL(BUTCEUCRET4,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
		UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET5=(BUTCEUCRET5/(100+ABS(@ORAN)))*100 WHERE ISNULL(BUTCEUCRET5,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MAASDUSUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_MAASDUSUR] @FIRMAID INT, @ORAN FLOAT
AS
BEGIN
UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET1=BUTCEUCRET1/100*(100-@ORAN) WHERE ISNULL(BUTCEUCRET1,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET2=BUTCEUCRET2/100*(100-@ORAN) WHERE ISNULL(BUTCEUCRET2,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET3=BUTCEUCRET3/100*(100-@ORAN) WHERE ISNULL(BUTCEUCRET3,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET4=BUTCEUCRET4/100*(100-@ORAN) WHERE ISNULL(BUTCEUCRET4,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET5=BUTCEUCRET5/100*(100-@ORAN) WHERE ISNULL(BUTCEUCRET5,0)>0 and PERUNVAN.FIRMAID=@FIRMAID
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MAASGUNCELLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_MAASGUNCELLE] @FIRMAID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.NETUCRET1=UCRET FROM PERUNVAN 
INNER JOIN FU_OZETPERSONEL ON PERUNVAN.ELKUNVANID=FU_OZETPERSONEL.UNVANID AND PERUNVAN.DEPKODU=FU_OZETPERSONEL.DEPT
WHERE FU_OZETPERSONEL.FIRMA=10 AND PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.NETUCRET2=UCRET FROM PERUNVAN 
INNER JOIN FU_OZETPERSONEL ON PERUNVAN.ELKUNVANID=FU_OZETPERSONEL.UNVANID AND PERUNVAN.DEPKODU=FU_OZETPERSONEL.DEPT
WHERE FU_OZETPERSONEL.FIRMA=11 AND PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.NETUCRET3=UCRET FROM PERUNVAN 
INNER JOIN FU_OZETPERSONEL ON PERUNVAN.ELKUNVANID=FU_OZETPERSONEL.UNVANID AND PERUNVAN.DEPKODU=FU_OZETPERSONEL.DEPT
WHERE FU_OZETPERSONEL.FIRMA=12 AND PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.NETUCRET4=UCRET FROM PERUNVAN 
INNER JOIN FU_OZETPERSONEL ON PERUNVAN.ELKUNVANID=FU_OZETPERSONEL.UNVANID AND PERUNVAN.DEPKODU=FU_OZETPERSONEL.DEPT
WHERE FU_OZETPERSONEL.FIRMA=12 AND PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.NETUCRET5=UCRET FROM PERUNVAN 
INNER JOIN FU_OZETPERSONEL ON PERUNVAN.ELKUNVANID=FU_OZETPERSONEL.UNVANID AND PERUNVAN.DEPKODU=FU_OZETPERSONEL.DEPT
WHERE FU_OZETPERSONEL.FIRMA=12 AND PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)


SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET1=NETUCRET1 WHERE ISNULL(BUTCEUCRET1,0)=0 and PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET2=NETUCRET2 WHERE ISNULL(BUTCEUCRET2,0)=0 and PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET3=NETUCRET3 WHERE ISNULL(BUTCEUCRET3,0)=0 and PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET4=NETUCRET4 WHERE ISNULL(BUTCEUCRET4,0)=0 and PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.BUTCEUCRET5=NETUCRET5 WHERE ISNULL(BUTCEUCRET5,0)=0 and PERUNVAN.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MALIYETHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MALIYETHESAPLA]  
@FISID INT,
@FIRMAID NVARCHAR(10),
@TABLOADI NVARCHAR(20)
AS
BEGIN
IF @TABLOADI='FATURA'
	BEGIN
		
		IF (SELECT FISTURID FROM FATURA WHERE FATID=@FISID)=51
			BEGIN
				 UPDATE STOK
				 SET STOK.KARY=100-(( (STOK.SFIYAT1/(100+SATISKDV)*100)/ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT))*100),
				 STOK.SALISFIYAT  = ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT),
				 STOK.SALISBFIYAT = QMUH_STOKSONALIS.BFIYAT,
				 STOK.SONALISF    = QMUH_STOKSONALIS.BFIYAT,
				 STOK.MALIYET     = QMUH_STOKSONALIS.NFIYAT/100*(100+SONKDV),
				 STOK.SALISFBIRIM = QMUH_STOKSONALIS.SONABIRIM,
				 STOK.SALISFBFIYAT = QMUH_STOKSONALIS.NFBFIYAT,
				 STOK.SSATICI     = QMUH_STOKSONALIS.CARIID,
				 STOK.SFATTARIHI       = QMUH_STOKSONALIS.TARIH,
				 STOK.SFATURANO       = QMUH_STOKSONALIS.FATNO
				 FROM STOK WITH (NOLOCK) INNER JOIN FNCQ_STOKSONALIS2(@FIRMAID) AS QMUH_STOKSONALIS ON
				 STOK.STOKID = QMUH_STOKSONALIS.STOKID WHERE STOK.FIRMAID=@FIRMAID AND
				 QMUH_STOKSONALIS.STOKID IN(SELECT STOKID FROM FATISL WHERE FATID=@FISID) AND
				 CARIUNVANI<>'SAYIM' AND QMUH_STOKSONALIS.NFIYAT>0
			END

		UPDATE FATISL SET FATISL.BMALIYET=STOK.SALISFIYAT, FATISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		FATISL.BKATSAYI=(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		FATISL.ADET=FADET*(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		FATISL.BFIYAT=FBFIYAT/(CASE WHEN FATISL.FBIRIM=STOK.BIRIM THEN 1 WHEN FATISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN FATISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM FATISL INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID WHERE FATISL.FATID=@FISID

	END
ELSE IF @TABLOADI='DEPOFIS'
	BEGIN
		UPDATE DEPOFISISL SET DEPOFISISL.BMALIYET=STOK.SALISFIYAT, DEPOFISISL.FBMALIYET=STOK.SALISFBFIYAT, 
		
		DEPOFISISL.BKATSAYI=(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		DEPOFISISL.MIKTAR=FMIKTAR*(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		DEPOFISISL.BFIYAT=FBFIYAT/(CASE WHEN DEPOFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN DEPOFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID WHERE DEPOFISISL.DEPOFISID=@FISID
	END
ELSE IF @TABLOADI='TUKETIMFIS'
	BEGIN
		UPDATE TUKETIMFISISL SET TUKETIMFISISL.BMALIYET=STOK.MALIYET, TUKETIMFISISL.FBMALIYET=STOK.MALIYET, 
		
		TUKETIMFISISL.BKATSAYI=(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		TUKETIMFISISL.MIKTAR=FMIKTAR*(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END),
		
		TUKETIMFISISL.BFIYAT=FBFIYAT/(CASE WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM THEN 1 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM2 THEN KATSAYI2 
		WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 WHEN TUKETIMFISISL.FBIRIM=STOK.BIRIM3 THEN KATSAYI3 ELSE 1 END)
		
		
		FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID WHERE TUKETIMFISISL.DEPOFISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MALIYETHESAPLA_ALL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MALIYETHESAPLA_ALL]  
@FIRMAID NVARCHAR(10)
AS
BEGIN
				 UPDATE STOK
				 SET STOK.KARY=100-(( (STOK.SFIYAT1/(100+SATISKDV)*100)/ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT))*100),
				 STOK.SALISFIYAT  = ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT),
				 STOK.SALISBFIYAT = QMUH_STOKSONALIS.BFIYAT,
				 STOK.SONALISF    = QMUH_STOKSONALIS.BFIYAT,
				 STOK.MALIYET     = QMUH_STOKSONALIS.NFIYAT/100*(100+SONKDV),
				 STOK.SALISFBIRIM = QMUH_STOKSONALIS.SONABIRIM,
				 STOK.SALISFBFIYAT = QMUH_STOKSONALIS.NFBFIYAT,
				 STOK.SSATICI     = QMUH_STOKSONALIS.CARIID,
				 STOK.SFATTARIHI       = QMUH_STOKSONALIS.TARIH,
				 STOK.SFATURANO       = QMUH_STOKSONALIS.FATNO
				 FROM STOK WITH (NOLOCK) INNER JOIN FNCQ_STOKSONALIS_IRSALIYELI(@FIRMAID) AS QMUH_STOKSONALIS    ON
				 STOK.STOKID = QMUH_STOKSONALIS.STOKID WHERE STOK.FIRMAID=@FIRMAID AND CARIUNVANI<>'SAYIM' AND QMUH_STOKSONALIS.NFIYAT>0

		UPDATE FATISL SET FATISL.BMALIYET=STOK.SALISFIYAT, FATISL.FBMALIYET=STOK.SALISFBFIYAT 
		FROM FATISL INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID WHERE FATISL.FATFIRMAID=@FIRMAID AND ISNULL(BMALIYET,0)=0
		
		UPDATE TUKETIMFISISL SET TUKETIMFISISL.BMALIYET=STOK.MALIYET, TUKETIMFISISL.FBMALIYET=STOK.MALIYET
		FROM TUKETIMFISISL WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID 
		INNER JOIN STOK WITH (NOLOCK) ON TUKETIMFISISL.STOKID=STOK.STOKID WHERE ISNULL(TUKETIMFISISL.BMALIYET,0)=0 and TUKETIMFIS.FIRMAID=@FIRMAID

		UPDATE TUKETIMFIS SET ACIK=ISNULL((SELECT SUM(MIKTAR*ISNULL(BMALIYET,BFIYAT)) 
		FROM TUKETIMFISISL WITH (NOLOCK) WHERE TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID AND ISNULL(SILINDI,0)=0),ACIK) 
		FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN MUH_HESAP WITH (NOLOCK) ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID WHERE TUKETIMFIS.ACIK>0 AND TUKETIMFIS.FIRMAID=@FIRMAID AND MUH_HESAP.GSFIYAT=1
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MASAAKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_MASAAKTAR]  @ILKFISCOUNTER NVARCHAR(10), @SONFISCOUNTER NVARCHAR(10), @ESKIDEPID NVARCHAR(10),
@YENIDEPID NVARCHAR(10),@ESKIMASANO NVARCHAR(10), @YENIMASANO NVARCHAR(10), @DOLUMASAMI NVARCHAR(5), @INDORAN NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @DOLUMASAMI='EVET'
	BEGIN
		SET @SQLCUMLE='UPDATE ADSSATIR SET ILKFISCOUNTER='+@ILKFISCOUNTER+', FISCOUNTER='+@SONFISCOUNTER+' WHERE FISCOUNTER='+@ILKFISCOUNTER
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE ADISYON SET MCOUNTER='+@SONFISCOUNTER+', AKTARILDI=1,  SIL=-5 WHERE FISCOUNTER='+@ILKFISCOUNTER
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE ADISYON SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0))/100*(100-'+@INDORAN+') FROM ADSSATIR 
		WHERE ISNULL(ADSSATIR.SIL,0)=0 AND FISCOUNTER='+@SONFISCOUNTER+') WHERE FISCOUNTER='+@SONFISCOUNTER
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE MASALAR SET STATU=0 WHERE DEPID='+@ESKIDEPID+' AND MASANO='''+@ESKIMASANO+''''
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='UPDATE ADISYON SET DEPID='+@YENIDEPID+', ILKMASANO='''+@ESKIMASANO+''', MASANO='''+@YENIMASANO+''' WHERE FISCOUNTER='+@ILKFISCOUNTER
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE MASALAR SET STATU=0 WHERE DEPID='+@ESKIDEPID+' AND MASANO='''+@ESKIMASANO+''''
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE MASALAR SET STATU=1 WHERE DEPID='+@YENIDEPID+' AND MASANO='''+@YENIMASANO+''''
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MASASTATU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_MASASTATU]  @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @MASANO NVARCHAR(30), @DEPT NVARCHAR(10), @STATU NVARCHAR(2)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(250)
SET @SQLCUMLE='UPDATE MASALAR SET STATU='+@STATU+' WHERE MASANO='''+@MASANO+''' AND DEPID='''+@DEPT+''' AND FIRMAID=0'+@FIRMAID+' AND SUBEID=0'+@SUBEID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MASASTATU2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRE_MASASTATU2]  @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @MASANO NVARCHAR(30), @DEPT NVARCHAR(10), @STATU NVARCHAR(2), @ACIKLAMA NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(250)
if @ACIKLAMA<>''
	BEGIN
		SET @SQLCUMLE='UPDATE MASALAR SET STATU='+@STATU+', ACIKLAMA='''+@ACIKLAMA+''' WHERE MASANO='''+@MASANO+''' AND DEPID='''+@DEPT+''' AND FIRMAID=0'+@FIRMAID+' AND SUBEID=0'+@SUBEID
	END
ELSE if (@ACIKLAMA='') AND (@STATU='0')
	BEGIN
		SET @SQLCUMLE='UPDATE MASALAR SET STATU='+@STATU+', ACIKLAMA=NULL WHERE MASANO='''+@MASANO+''' AND DEPID='''+@DEPT+''' AND FIRMAID=0'+@FIRMAID+' AND SUBEID=0'+@SUBEID
	END
ELSE
	BEGIN
		SET @SQLCUMLE='UPDATE MASALAR SET STATU='+@STATU+' WHERE MASANO='''+@MASANO+''' AND DEPID='''+@DEPT+''' AND FIRMAID=0'+@FIRMAID+' AND SUBEID=0'+@SUBEID
	END
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MASATOPLAMDUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MASATOPLAMDUZELT]  @ILKFISCOUNTER NVARCHAR(10), @SONFISCOUNTER NVARCHAR(10), @ILKINDORAN NVARCHAR(10),
@SONINDORAN NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)

		SET @SQLCUMLE='UPDATE ADISYON SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0))/100*(100-'+@SONINDORAN+') FROM ADSSATIR 
		WHERE ISNULL(ADSSATIR.SIL,0)=0 AND FISCOUNTER='+@SONFISCOUNTER+') WHERE FISCOUNTER='+@SONFISCOUNTER
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='UPDATE ADISYON SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0))/100*(100-'+@ILKINDORAN+') FROM ADSSATIR 
		WHERE ISNULL(ADSSATIR.SIL,0)=0 AND FISCOUNTER='+@ILKFISCOUNTER+') WHERE FISCOUNTER='+@ILKFISCOUNTER
		EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MUHFIS_FISNODUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_MUHFIS_FISNODUZELT]  
 (@SUBEID INT,@TAR1 DATETIME,@TAR2 DATETIME,@TARIH DATETIME) AS 

  BEGIN 

  DECLARE @FISID INT  


 --UPDATE MUH_FIS SET FISNO=NULL WHERE SUBEID=@SUBEID AND TARIH>=@TARIH
  

 	 UPDATE MUH_FIS 

 	 SET FISNO=NULL 

   FROM MUH_FIS  

   INNER JOIN (SELECT MIN(FISID) AS FISID ,FISNO AS FNO FROM MUH_FIS  

               WHERE ISNULL(SIL,0)=0 AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0  

               GROUP BY FISNO)  AS TBL  

    	  ON TBL.FNO=MUH_FIS.FISNO AND TBL.FISID<>MUH_FIS.FISID  

 	 WHERE ISNULL(SIL,0)=0 AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0 

   AND (FISNO IN ( 

 	      SELECT FISNO FROM MUH_FIS 

 	      WHERE ISNULL(SIL,0)=0 AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0 

 	      GROUP BY FISNO  

 	      HAVING COUNT(*)>1) OR LEN(FISNO)<7) 

   DECLARE MUHFIS_CURSOR CURSOR FOR   

 			  SELECT FISID FROM 
			  (SELECT TARIH,FISID FROM MUH_FIS 
 			  WHERE ISNULL(SIL,0)=0 AND FISTURID IN (49) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH
			  UNION ALL
			  SELECT TARIH,FISID FROM MUH_FIS 
 			  WHERE ISNULL(SIL,0)=0 AND FISTURID NOT IN (48,49) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH
			  UNION ALL
			  SELECT TARIH,FISID FROM MUH_FIS 
 			  WHERE ISNULL(SIL,0)=0 AND FISTURID IN (48) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH) AS MUH_FIS   ORDER BY TARIH

   OPEN MUHFIS_CURSOR  

   FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID   

   WHILE(@@FETCH_STATUS = 0)   

   BEGIN   

 		    UPDATE MUH_FIS  

 		    SET FISNO=DBO.FNMUH_FISNO_VER(SUBEID,FISTURU,TARIH) 

 	    	WHERE FISID=@FISID 

        FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID   

   END   

  

   CLOSE MUHFIS_CURSOR   

   DEALLOCATE MUHFIS_CURSOR   

 END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MUHFISSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MUHFISSIL]  @FISUUID NVARCHAR(50), @FISID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @FISUUID<>''
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2 WHERE FISUUID='''+@FISUUID+''''
		EXEC (@SQLCUMLE)
	END
ELSE IF @FISID<>''
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2 WHERE FISID='''+@FISID+''''
		EXEC (@SQLCUMLE)
	END
ELSE IF @PARAMETRE<>''
	BEGIN
		SET @SQLCUMLE='UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2 WHERE 1=1 '+@PARAMETRE
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_MUHFISTOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_MUHFISTOPLAM]  @FISUUID NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(ISNULL(BORC,0)) FROM MUH_HESAPISL WHERE MUH_HESAPISL.FISID=MUH_FIS.FISID), 
DTOPLAM=(SELECT SUM(ISNULL(DBORC,0)) FROM MUH_HESAPISL WHERE MUH_HESAPISL.FISID=MUH_FIS.FISID)  WHERE FISUUID='''+@FISUUID+''''
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_PAKETSATILDI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_PAKETSATILDI] @HSPAKETID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE HSPAKET SET SATILDI=1 WHERE HSPAKETID='+@HSPAKETID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_RECETEMALIYET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_RECETEMALIYET]  
@FIRMAID INT
AS
BEGIN
				 UPDATE STOK
				 SET STOK.KARY=100-(( (STOK.SFIYAT1/(100+SATISKDV)*100)/ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT))*100),
				 STOK.SALISFIYAT  = ISNULL(QMUH_STOKSONALIS.NFIYAT,QMUH_STOKSONALIS.BFIYAT),
				 STOK.SALISBFIYAT = QMUH_STOKSONALIS.BFIYAT,
				 STOK.SONALISF    = QMUH_STOKSONALIS.BFIYAT,
				 STOK.MALIYET     = QMUH_STOKSONALIS.NFIYAT/100*(100+SONKDV),
				 STOK.SALISFBIRIM = QMUH_STOKSONALIS.SONABIRIM,
				 STOK.SALISFBFIYAT = QMUH_STOKSONALIS.NFBFIYAT,
				 STOK.SSATICI     = QMUH_STOKSONALIS.CARIID,
				 STOK.SFATTARIHI       = QMUH_STOKSONALIS.TARIH,
				 STOK.SFATURANO       = QMUH_STOKSONALIS.FATNO
				 FROM STOK WITH (NOLOCK) INNER JOIN FNCQ_STOKSONALIS_IRSALIYELI(@FIRMAID) AS QMUH_STOKSONALIS ON
				 STOK.STOKID = QMUH_STOKSONALIS.STOKID WHERE STOK.FIRMAID=@FIRMAID AND CARIUNVANI<>'SAYIM' AND QMUH_STOKSONALIS.NFIYAT>0


UPDATE RECETE  SET RECETE.BMALIYET    = NFIYAT FROM RECETE INNER JOIN 
 FNCQ_STOKSONALIS(@FIRMAID) AS TBL
 ON RECETE.STOKID = TBL.STOKID /*WHERE RECETE.STOKID IN(SELECT STOKID FROM STOK WHERE FIRMAID=@FIRMAID AND TURU='Mamul')   */

UPDATE RECETE  SET RECETE.SONBMALIYET  = NFIYAT FROM RECETE INNER JOIN 
 FNCQ_STOKSONALIS(@FIRMAID) AS TBL
 ON RECETE.STOKID = TBL.STOKID /*WHERE RECETE.STOKID IN(SELECT STOKID FROM STOK WHERE FIRMAID=@FIRMAID AND TURU='Mamul')   */

 UPDATE STOK SET MALIYET=(SELECT SUM(ISNULL(ORAN,0)*ISNULL(BMALIYET,0)) FROM RECETE WHERE RECETE.URUNID=STOK.STOKID), 
 SONMALIYET=(SELECT SUM(ISNULL(ORAN,0)*ISNULL(BMALIYET,0)) FROM RECETE WHERE RECETE.URUNID=STOK.STOKID) WHERE FIRMAID=@FIRMAID

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_RECETEMALIYET_YEDEK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_RECETEMALIYET_YEDEK]  
@FIRMAID INT
AS
BEGIN
--1
--3
UPDATE STOK   SET MALIYET=0     , SONMALIYET =0    
WHERE FIRMAID=@FIRMAID AND TURU <> 'Hammadde' AND STOKID IN(SELECT DISTINCT URUNID FROM RECETE)
--4
UPDATE STOK   SET RECETEKATSAYISI=1 WHERE FIRMAID=@FIRMAID AND  RECETEKATSAYISI=0 OR RECETEKATSAYISI IS NULL 
--5
UPDATE STOK   SET KISISAYISI=1      WHERE FIRMAID=@FIRMAID AND KISISAYISI=0 OR KISISAYISI IS NULL  
--6
UPDATE RECETE SET RECETE.RECETEKATSAYISI=STOK.RECETEKATSAYISI FROM STOK INNER JOIN RECETE ON STOK.STOKID=RECETE.STOKID WHERE STOK.FIRMAID=@FIRMAID
--7
UPDATE RECETE SET RECETEKATSAYISI=1 WHERE (RECETEKATSAYISI=0 OR RECETEKATSAYISI IS NULL)  AND URUNID IN(SELECT STOKID FROM STOK WHERE FIRMAID=@FIRMAID AND TURU='Mamul')  
--8
UPDATE RECETE  SET RECETE.BMALIYET    = NFIYAT FROM RECETE INNER JOIN 
 FNCQ_STOKSONALIS(@FIRMAID) AS TBL
 ON RECETE.STOKID = TBL.STOKID WHERE RECETE.STOKID IN(SELECT STOKID FROM STOK WHERE FIRMAID=@FIRMAID AND TURU='Mamul')  

UPDATE RECETE  SET RECETE.SONBMALIYET  = NFIYAT FROM RECETE INNER JOIN 
 FNCQ_STOKSONALIS(@FIRMAID) AS TBL
 ON RECETE.STOKID = TBL.STOKID WHERE RECETE.STOKID IN(SELECT STOKID FROM STOK WHERE FIRMAID=@FIRMAID AND TURU='Mamul')  

 UPDATE STOK SET MALIYET=(SELECT SUM(ORAN*BMALIYET) FROM RECETE WHERE RECETE.URUNID=STOK.STOKID), 
 SONMALIYET=(SELECT SUM(ORAN*BMALIYET) FROM RECETE WHERE RECETE.URUNID=STOK.STOKID) WHERE FIRMAID=@FIRMAID

END
GO
/****** Object:  StoredProcedure [dbo].[PRE_SICILSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_SICILSIL]
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='TRUNCATE TABLE PERELEKTRASICIL'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_SIPARISGONDERILDI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_SIPARISGONDERILDI]  @FISCOUNTER NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
UPDATE ADSSATIR SET GONDERILDI=1, YAZ=1 WHERE FISCOUNTER=@FISCOUNTER AND SIP=1
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_SIPARISGONDERILDI_NOVA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_SIPARISGONDERILDI_NOVA]  @FISCOUNTER NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
UPDATE ADSSATIR SET GONDERILDI=1, YAZ=1 WHERE FISCOUNTER=@FISCOUNTER AND ISNULL(H,0)<>-1  
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_SPAFISODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_SPAFISODEME]  @SPAFISID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='UPDATE SPAFIS SET NAKIT=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SPAODEME WHERE ODEMETURID=1 AND SPAFISID='+@SPAFISID+'),0),
KKARTI=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SPAODEME WHERE ODEMETURID=2 AND SPAFISID='+@SPAFISID+'),0),
ACIK=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SPAODEME WHERE ODEMETURID=3 AND SPAFISID='+@SPAFISID+'),0),
TICKET=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM SPAODEME WHERE ODEMETURID=4 AND SPAFISID='+@SPAFISID+'),0)
WHERE SPAFISID='+@SPAFISID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_STDHESAPEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_STDHESAPEKLE] @FIRMAID INT, @SUBEID INT
AS
BEGIN
declare @COUNT INT

SELECT @COUNT=COUNT(*) FROM MUH_HESAP WHERE FIRMAID=@FIRMAID
IF @COUNT<=0 
	BEGIN
 	 INSERT INTO MUH_HESAP (FIRMAID,SUBEID,HESAPTIPID,KODU,ACIKLAMA,FAALIYETICI,UCHESAP,SEVIYE) 
 	 SELECT @FIRMAID,@SUBEID,HESAPTIPID,KODU,ACIKLAMA,FAALIYETICI,0 AS UCHESAP,1 AS SEVIYE FROM MUH_HESAP WHERE FIRMAID=-1

	 UPDATE MUH_HESAP SET UCHESAP = 1  WHERE FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET UCHESAP = 0 WHERE LEN(KODU)<=2   AND FIRMAID=@FIRMAID
	 UPDATE H SET UCHESAP = 0 FROM MUH_HESAP H INNER JOIN MUH_HESAP H2 ON H2.KODU LIKE H.KODU+'.%'  AND H.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '780%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '770%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '760%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '740%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '730%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '720%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '710%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=6 WHERE HESAPTIPID IS NULL AND KODU LIKE '600%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=335 WHERE HESAPTIPID IS NULL AND KODU LIKE '335%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=331 WHERE HESAPTIPID IS NULL AND KODU LIKE '331%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=320 WHERE HESAPTIPID IS NULL AND KODU LIKE '320%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=150 WHERE HESAPTIPID IS NULL AND KODU LIKE '150%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=120 WHERE HESAPTIPID IS NULL AND KODU LIKE '120%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=102 WHERE HESAPTIPID IS NULL AND KODU LIKE '108%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=103 WHERE HESAPTIPID IS NULL AND KODU LIKE '103%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=102 WHERE HESAPTIPID IS NULL AND KODU LIKE '102%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=101 WHERE HESAPTIPID IS NULL AND KODU LIKE '101%' AND FIRMAID=@FIRMAID
	 UPDATE MUH_HESAP SET HESAPTIPID=100 WHERE HESAPTIPID IS NULL AND KODU LIKE '100%' AND FIRMAID=@FIRMAID
	END
ELSE
	BEGIN
	 RAISERROR('Hesap planı dolu yaratılamaz',16,1)
	end
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_STOKAKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_STOKAKTAR] @ILKSTOK NVARCHAR(10), @SONSTOK NVARCHAR(10), @FIRMAID NVARCHAR(10)
AS
IF (@ILKSTOK<>'') AND (@SONSTOK<>'')
	BEGIN
		UPDATE FATISL SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE TUKETIMFISISL SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE DEPOFISISL SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE SIPARISDETAY SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE RECETE SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE SAYIMFIS SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		UPDATE SAYIMFISARSIV SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
		/*UPDATE SAYIM2 SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK */
		UPDATE STOK SET SIL=-2, OZELKOD3='AKTARSİL' WHERE STOKID=@ILKSTOK
		UPDATE BARKOD SET STOKID=@SONSTOK WHERE STOKID=@ILKSTOK
	END
GO
/****** Object:  StoredProcedure [dbo].[PRE_STOKKODU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_STOKKODU]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  MAX(KODU) AS SONKOD FROM STOK WITH (NOLOCK) WHERE LEN(KODU)<=9 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_TOPLUMALIYETHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_TOPLUMALIYETHESAPLA]  
 (@FIRMAID NVARCHAR(10),@TARIH1 SMALLDATETIME, @TARIH2 SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@FATID INT
			DECLARE MALIYET_HESAPLA CURSOR FOR
					
			SELECT FATID FROM FATURA WITH (NOLOCK)  WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND TUR=1 AND TARIH BETWEEN @TARIH1 AND @TARIH2 ORDER BY TARIH

			OPEN MALIYET_HESAPLA		

			FETCH NEXT FROM MALIYET_HESAPLA INTO @FATID

	WHILE @@FETCH_STATUS=0
		BEGIN
			EXEC PRE_MALIYETHESAPLA @FATID,@FIRMAID,'FATURA'

			FETCH NEXT FROM MALIYET_HESAPLA INTO @FATID
		END
	CLOSE MALIYET_HESAPLA
	DEALLOCATE MALIYET_HESAPLA
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_TUKETIMFIS_MAHSUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_TUKETIMFIS_MAHSUP]  
 (@FIRMAID INT,@SUBEID INT,@TARIH1 SMALLDATETIME, @TARIH2 SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@FISID INT,
	@DEPOFISID INT,
	@FISUUID uniqueidentifier
			DECLARE MAHSUP_EKLE CURSOR FOR
					
			SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK)  WHERE FIRMAID=@FIRMAID AND ACIK>0 AND ISNULL(MUHFISID,0)=0 AND TARIH BETWEEN @TARIH1 AND @TARIH2

			OPEN MAHSUP_EKLE		

			FETCH NEXT FROM MAHSUP_EKLE INTO @DEPOFISID

	WHILE @@FETCH_STATUS=0
		BEGIN
			set @FISUUID=NEWID()
			
			INSERT INTO  MUH_FIS (FISUUID,TARIH,FISNO,FISTURID,FISTURU,MODULID,MODULEKRANID,FIRMAID,SUBEID,FISDURUMID,DETAYLIENTEGRE,ADD_DATE,ADD_USERID,ACIKLAMA,BELGENO,ENTKAYNAKID,ENTKAYNAK)
			SELECT @FISUUID,TARIH,'0000001' AS FISNO,41 AS FISTURID,'Mahsup' AS FISTURU,1,1,@FIRMAID,@SUBEID,1,1,TARIH,-1,'Perakande Satış Fişi','',DEPOFISID,'TUKETIMFIS' FROM TUKETIMFIS WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID

			SET @FISID=(SELECT FISID FROM MUH_FIS WHERE FISUUID=@FISUUID)

			INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ)
			SELECT @FISID,HESAPID,'Açık Hesap Perakende Satış' as ACIKLAMA,ACIK AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
			LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID
			UNION ALL
			SELECT @FISID,ISNULL(ACIKHESAPID,-999) AS HESAPID,'Açık Hesap Perakende Satış' as ACIKLAMA,0.00 AS BORC, ACIK AS ALACAK,0.00 AS DBORC,0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
			LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID

			UPDATE TUKETIMFIS SET MUHFISID=@FISID WHERE DEPOFISID=@DEPOFISID
			UPDATE TUKETIMFISISL SET ISLREFID=@FISID WHERE DEPOFISID=@DEPOFISID

			FETCH NEXT FROM MAHSUP_EKLE  INTO @DEPOFISID
		END
	CLOSE MAHSUP_EKLE
	DEALLOCATE MAHSUP_EKLE
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_TUKETIMFISODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_TUKETIMFISODEME]  @DEPOFISID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='UPDATE TUKETIMFIS SET NAKIT=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SATISODEME WHERE ODEMETURID=1 AND DEPOFISID='+@DEPOFISID+'),0),
KKARTI=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SATISODEME WHERE ODEMETURID=2 AND DEPOFISID='+@DEPOFISID+'),0),
ACIK=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SATISODEME WHERE ODEMETURID=3 AND DEPOFISID='+@DEPOFISID+'),0),
TICKET1=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM SATISODEME WHERE ODEMETURID=4 AND DEPOFISID='+@DEPOFISID+'),0),
TICKET2=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1))  FROM SATISODEME WHERE ODEMETURID=5 AND DEPOFISID='+@DEPOFISID+'),0),
TICKET3=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM SATISODEME WHERE ODEMETURID=6 AND DEPOFISID='+@DEPOFISID+'),0),
TICKET4=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM SATISODEME WHERE ODEMETURID=7 AND DEPOFISID='+@DEPOFISID+'),0),
TICKET5=ISNULL((SELECT SUM(TUTAR*ISNULL(KUR,1)) FROM SATISODEME WHERE ODEMETURID=8 AND DEPOFISID='+@DEPOFISID+'),0)
WHERE DEPOFISID='+@DEPOFISID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_UCHESAPDUZENLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRE_UCHESAPDUZENLE] @FIRMAID INT
AS
BEGIN
 UPDATE MUH_HESAP SET UCHESAP = 1  WHERE FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET UCHESAP = 0 WHERE LEN(KODU)<=2   AND FIRMAID=@FIRMAID
 UPDATE H SET UCHESAP = 0 FROM MUH_HESAP H INNER JOIN MUH_HESAP H2 ON H2.KODU LIKE H.KODU+'.%'  AND H.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '780%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '770%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '760%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '740%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '730%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '720%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=7 WHERE HESAPTIPID IS NULL AND KODU LIKE '710%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=6 WHERE HESAPTIPID IS NULL AND KODU LIKE '600%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=335 WHERE HESAPTIPID IS NULL AND KODU LIKE '335%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=331 WHERE HESAPTIPID IS NULL AND KODU LIKE '331%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=320 WHERE HESAPTIPID IS NULL AND KODU LIKE '320%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=150 WHERE HESAPTIPID IS NULL AND KODU LIKE '150%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=120 WHERE HESAPTIPID IS NULL AND KODU LIKE '120%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=102 WHERE HESAPTIPID IS NULL AND KODU LIKE '108%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=103 WHERE HESAPTIPID IS NULL AND KODU LIKE '103%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=102 WHERE HESAPTIPID IS NULL AND KODU LIKE '102%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=101 WHERE HESAPTIPID IS NULL AND KODU LIKE '101%' AND FIRMAID=@FIRMAID
 UPDATE MUH_HESAP SET HESAPTIPID=100 WHERE HESAPTIPID IS NULL AND KODU LIKE '100%' AND FIRMAID=@FIRMAID
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_UNVANDEPGUNCELLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_UNVANDEPGUNCELLE] @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='INSERT INTO PERUNVAN (FIRMAID,SUBEID,ELKUNVANID,UNVANKODU,UNVANADI,DEPKODU)
SELECT '+@FIRMAID+', '+@SUBEID+',UNVANID,UNVANKODU,UNVANADI,DEPKODU FROM PERELEKTRAUNV WHERE UNVANID NOT IN(SELECT ELKUNVANID FROM PERUNVAN WHERE FIRMAID='+@FIRMAID+')'
EXEC (@SQLCUMLE)


SET @SQLCUMLE='UPDATE PERUNVAN SET PERUNVAN.DEPID=PERDEPART.PERDEPARTMANID
FROM PERUNVAN INNER JOIN PERDEPART ON PERUNVAN.DEPKODU=PERDEPART.DEPKODU WHERE PERUNVAN.FIRMAID='+@FIRMAID+' AND PERDEPART.FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_UNVANSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_UNVANSIL]
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='TRUNCATE TABLE PERELEKTRAUNV'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_URETIMMAHSUBU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_URETIMMAHSUBU]  
@TARIH SMALLDATETIME,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@SUBEID INT,
@FIRMAID INT,
@EKLEYEN INT
AS
BEGIN
DECLARE
@GUID uniqueidentifier = NEWID(),
@FISID INT
DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSURETIM')
DELETE FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='POSURETIM'
if (SELECT ISNULL(COUNT(*),0) FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH,@FIRMAID) WHERE SUBEID=@SUBEID AND ISNULL(MUHALISHESAPID,0)<>0 AND ISNULL(MUHSARFHESAPID,0)<>0 AND TARIH=@TARIH AND ISLEM='TÜKETİM')>0
	BEGIN
		INSERT INTO MUH_FIS (FISUUID,FIRMAID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1,MODULID,MODULEKRANID)
		VALUES(@GUID,@FIRMAID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Üretim Mahsubu',1,'TL',1,@TOPLAM,0.00,'POSURETIM',1,1)
		
		SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@GUID

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,MIKTAR,BORC,ALACAK,DBORC,DALACAK)
		SELECT @FISID, MUHALISHESAPID AS HESAPID, 'Üretim Giderleri' as ACIKLAMA, 'TL' AS DOVIZ, 'POSURETIM' AS OZELKOD1, SUM(FADET*FBFIYAT) AS TUTAR, 0.00 AS DTUTAR,ABS(SUM(FADET)) AS MIKTAR, 0.00 AS BORC,  SUM(FADET*FBFIYAT) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
		FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH,@FIRMAID)  WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND  ISLEM='TÜKETİM' GROUP BY TARIH,MUHALISHESAPID
		UNION ALL
		SELECT @FISID, MUHSARFHESAPID AS HESAPID, 'Üretim Giderleri' as ACIKLAMA, 'TL' AS DOVIZ, 'POSURETIM' AS OZELKOD1, SUM(FADET*FBFIYAT) AS TUTAR, 0.00 AS DTUTAR,ABS(SUM(FADET)) AS MIKTAR,  SUM(FADET*FBFIYAT) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK
		FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH,@FIRMAID) WHERE SUBEID=@SUBEID AND TARIH=@TARIH AND ISLEM='TÜKETİM' GROUP BY TARIH,MUHSARFHESAPID

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL WHERE FISID=@FISID) WHERE FISID=@FISID
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_YANSITMAFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_YANSITMAFISI] @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @MASMEREGORE NVARCHAR(5), @PROJEGORE NVARCHAR(5)

AS

DECLARE 
@FISID INT,
@FISUUID uniqueidentifier

 
set @FISUUID=NEWID()

DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND FISTURID=44 AND TARIH=@SONTARIH AND OZELKOD1='YANSITMA1')

DELETE FROM MUH_FIS WHERE  FIRMAID=@FIRMAID AND FISTURID=44 AND TARIH=@SONTARIH AND OZELKOD1='YANSITMA1'

            

INSERT INTO MUH_FIS (FISUUID,FISNO,FIRMAID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1)
VALUES(@FISUUID,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@SONTARIH),@FIRMAID,@SUBEID,44,0,@SONTARIH,-1,@SONTARIH,@SONTARIH,'Mahsup','Yansıtma Fişi',1,'TL',1,0.00,0.00,'YANSITMA1')

 
SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
            
IF @PROJEGORE='HAYIR'
	BEGIN
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,MASMERID,ACIKLAMA,OZELKOD1,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK)

		SELECT @FISID,HESAPID,MASMERID,ACIKLAMA,'YANSITMA1' AS OZELKOD1,ABS((CASE WHEN BORCBAKIYE>0 THEN BORCBAKIYE ELSE ALACAKBAKIYE END)) AS TUTAR,
		ABS((CASE WHEN DBORCBAKIYE>0 THEN BORCBAKIYE ELSE DALACAKBAKIYE END)) AS DTUTAR,

		ABS(BORCBAKIYE) AS BORCBAKIYE,ABS(ALACAKBAKIYE) AS ALACAKBAKIYE, ABS(DBORCBAKIYE) AS DBORCBAKIYE, ABS(DALACAKBAKIYE) AS DALACAKBAKIYE

		FROM

		(SELECT '1' AS TIP, Q.MASMERID,Q.HESAPID,Q.KODU,Q.HESAPADI, 'Yansıtma Fişi' as ACIKLAMA,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS BORCBAKIYE,
		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DALACAKBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DBORCBAKIYE 

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  Q.MASMERID=YAN.MASMERID

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.MASMERID,Q.HESAPID,Q.KODU,Q.HESAPADI

		UNION ALL

		SELECT '1' AS TIP,Q.MASMERID, Q.HESAPID,Q.KODU,Q.HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS BORCBAKIYE,(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DALACAKBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DBORCBAKIYE 

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  ISNULL(Q.MASMERID,0)=0 AND ISNULL(YAN.MASMERID,0)=0

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.MASMERID,Q.HESAPID,Q.KODU,Q.HESAPADI 

		UNION ALL

		SELECT '2' AS TIP,Q.MASMERID, H3.HESAPID,H3.KODU,H3.ACIKLAMA AS HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS BORCBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DALACAKBAKIYE, 

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DBORCBAKIYE

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN MUH_HESAP AS H3 ON YAN.YANSITMAHESAPID1=H3.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q  ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  Q.MASMERID=YAN.MASMERID

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.MASMERID,H3.HESAPID,H3.KODU,H3.ACIKLAMA 

		UNION ALL

		SELECT '2' AS TIP,Q.MASMERID,H3.HESAPID,H3.KODU,H3.ACIKLAMA AS HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS BORCBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DALACAKBAKIYE, 

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DBORCBAKIYE

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN MUH_HESAP AS H3 ON YAN.YANSITMAHESAPID1=H3.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q  ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  ISNULL(Q.MASMERID,0)=0 AND ISNULL(YAN.MASMERID,0)=0

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.MASMERID,H3.HESAPID,H3.KODU,H3.ACIKLAMA) AS YANSITMA
	END
ELSE
	BEGIN
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,PROJEID,ACIKLAMA,OZELKOD1,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK)

		SELECT @FISID,HESAPID,PROJEID,ACIKLAMA,'YANSITMA1' AS OZELKOD1,
		ABS((CASE WHEN BORCBAKIYE>0 THEN BORCBAKIYE ELSE ALACAKBAKIYE END)) AS TUTAR, ABS((CASE WHEN DBORCBAKIYE>0 THEN BORCBAKIYE ELSE DALACAKBAKIYE END)) AS DTUTAR,

		ABS(BORCBAKIYE) AS BORCBAKIYE, ABS(ALACAKBAKIYE) AS ALACAKBAKIYE, ABS(DBORCBAKIYE) AS DBORCBAKIYE, ABS(DALACAKBAKIYE) AS DALACAKBAKIYE

		FROM

		(SELECT '1' AS TIP, Q.PROJEID,Q.HESAPID,Q.KODU,Q.HESAPADI, 'Yansıtma Fişi' as ACIKLAMA,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS BORCBAKIYE,(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DALACAKBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DBORCBAKIYE 

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  Q.PROJEID=YAN.PROJEID

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.PROJEID,Q.HESAPID,Q.KODU,Q.HESAPADI

		UNION ALL

		SELECT '1' AS TIP,Q.PROJEID, Q.HESAPID,Q.KODU,Q.HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS BORCBAKIYE,(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DALACAKBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DBORCBAKIYE 

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  ISNULL(Q.PROJEID,0)=0 AND ISNULL(YAN.PROJEID,0)=0

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.PROJEID,Q.HESAPID,Q.KODU,Q.HESAPADI 

		UNION ALL

		SELECT '2' AS TIP,Q.PROJEID, H3.HESAPID,H3.KODU,H3.ACIKLAMA AS HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS BORCBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DALACAKBAKIYE, 

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DBORCBAKIYE

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN MUH_HESAP AS H3 ON YAN.YANSITMAHESAPID1=H3.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q  ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  Q.PROJEID=YAN.PROJEID

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.PROJEID,H3.HESAPID,H3.KODU,H3.ACIKLAMA 

		UNION ALL

		SELECT '2' AS TIP,Q.PROJEID,H3.HESAPID,H3.KODU,H3.ACIKLAMA AS HESAPADI, 'Yansıtma Fişi' as ACIKLAMA, SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 0.00 ELSE SUM(BORC)-SUM(ALACAK) END) AS ALACAKBAKIYE,

		(CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN SUM(BORC)-SUM(ALACAK) ELSE 0.00 END) AS BORCBAKIYE,

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN 0.00 ELSE SUM(DBORC)-SUM(DALACAK) END) AS DALACAKBAKIYE, 

		(CASE WHEN SUM(DBORC)-SUM(DALACAK)>0 THEN SUM(DBORC)-SUM(DALACAK) ELSE 0.00 END) AS DBORCBAKIYE

		FROM MUH_HESAPYANSITMA AS YAN INNER JOIN MUH_HESAP AS H1 ON YAN.HESAPID1=H1.HESAPID INNER JOIN MUH_HESAP AS H2 ON YAN.HESAPID2=H2.HESAPID INNER JOIN MUH_HESAP AS H3 ON YAN.YANSITMAHESAPID1=H3.HESAPID INNER JOIN 
		[FNCQ_QMUHMIZAN] (@ILKTARIH, @SONTARIH, @FIRMAID) AS Q  ON Q.KODU>=H1.KODU AND Q.KODU<=H2.KODU AND  ISNULL(Q.PROJEID,0)=0 AND ISNULL(YAN.PROJEID,0)=0

		WHERE YAN.FIRMAID=@FIRMAID AND H1.FIRMAID=@FIRMAID AND H2.FIRMAID=@FIRMAID AND TARIH BETWEEN @ILKTARIH  AND @SONTARIH

		GROUP BY Q.PROJEID,H3.HESAPID,H3.KODU,H3.ACIKLAMA) AS YANSITMA
	END
GO
/****** Object:  StoredProcedure [dbo].[PRE_YETKIEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRE_YETKIEKLE]  @USERID NVARCHAR(5), @FIRMAID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='DELETE FROM NOVAUSERD WHERE NOVAUSERID='+@USERID
EXEC (@SQLCUMLE)
SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
SELECT '+@USERID+','+@FIRMAID+',EKRANID,1,1,1,1,1,1,1,1 FROM EKRANLAR WHERE AKTIF=1 AND ANAMODULMU=1
           AND EKRANID IN(SELECT EKRANID FROM FIRMAMODUL WHERE AKTIF=1 AND 
           FIRMAID='+@FIRMAID+')  ORDER BY EKRANSIRA  '
EXEC (@SQLCUMLE)
SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
SELECT '+@USERID+','+@FIRMAID+',EKRANID,1,1,1,1,1,1,1,1 FROM EKRANLAR WHERE AKTIF=1 AND ANAMODULMU=0'+
          ' AND BAGLIMODULID IN(SELECT EKRANID FROM FIRMAMODUL WHERE AKTIF=1 AND'+
          ' FIRMAID='+@FIRMAID+')  ORDER BY EKRANSIRA '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_YETKIEKLE_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRE_YETKIEKLE_DETAY] @FIRMAID NVARCHAR(10), @USERID NVARCHAR(10), @BAGLIMODULID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='DELETE FROM NOVAUSERD WHERE NOVAUSERID='+@USERID+' AND EKRANID IN(SELECT EKRANID FROM EKRANLAR WHERE BAGLIMODULID='+@BAGLIMODULID+')'
EXEC (@SQLCUMLE)
SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
SELECT '+@USERID+','+@FIRMAID+',EKRANID,1,1,1,1,1,1,1,1 FROM EKRANLAR WHERE AKTIF=1 AND ANAMODULMU=0'+
          ' AND BAGLIMODULID='+@BAGLIMODULID+'  ORDER BY EKRANSIRA '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRE_YETKIEKLE2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRE_YETKIEKLE2]  @USERID NVARCHAR(10), @FIRMAID NVARCHAR(10), @YETKIUSERID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='DELETE FROM NOVAUSERD WHERE NOVAUSERID='+@USERID
EXEC (@SQLCUMLE)
IF @YETKIUSERID='' 
	BEGIN
		SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
		SELECT '+@USERID+','+@FIRMAID+',EKRANID,1,1,1,1,1,1,1,1 FROM EKRANLAR WHERE AKTIF=1 AND ANAMODULMU=1
				   AND EKRANID IN(SELECT EKRANID FROM FIRMAMODUL WHERE AKTIF=1 AND 
				   FIRMAID='+@FIRMAID+')  ORDER BY EKRANSIRA  '
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
		SELECT '+@USERID+','+@FIRMAID+',EKRANID,1,1,1,1,1,1,1,1 FROM EKRANLAR WHERE AKTIF=1 AND ANAMODULMU=0'+
				  ' AND BAGLIMODULID IN(SELECT EKRANID FROM FIRMAMODUL WHERE AKTIF=1 AND'+
				  ' FIRMAID='+@FIRMAID+')  ORDER BY EKRANSIRA '
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='INSERT INTO NOVAUSERD (NOVAUSERID,FIRMAID,EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS)
		SELECT '+@USERID+','+@FIRMAID+',EKRANID,EKRANAC,YENI,DUZELT,KAYDET,SIL,YAZDIR,RAPOR,LISTEGIRIS FROM NOVAUSERD WHERE NOVAUSERID=0'+@YETKIUSERID
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ACIK_SATIS_MALIYET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ACIK_SATIS_MALIYET] @HESAPID INT, @FIRMAID INT, @DEPOFISID INT
AS
DECLARE @GSFIYAT INT
SELECT @GSFIYAT=GSFIYAT FROM MUH_HESAP WHERE HESAPID=@HESAPID AND FIRMAID=@FIRMAID
IF @GSFIYAT=1
	BEGIN
		UPDATE TUKETIMFISISL SET ZRURUNID=-1, FBFIYAT=(ISNULL(MIKTAR,1)/ISNULL(FMIKTAR,1))*ISNULL(BMALIYET,FBFIYAT) WHERE DEPOFISID=@DEPOFISID
		UPDATE TUKETIMFIS SET ACIK=ISNULL((SELECT SUM(FMIKTAR*FBFIYAT) FROM TUKETIMFISISL WHERE ISNULL(SILINDI,0)=0 AND DEPOFISID=@DEPOFISID),ACIK) WHERE DEPOFISID=@DEPOFISID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ACIKADISYON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ACIKADISYON]  @PARAMETRE NVARCHAR(450)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TARIH,MASANO,(TOPLAM/100)*(100-ISNULL(INDORAN,0))  AS TOPLAM FROM  ADISYON WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ACIKHESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ACIKHESAP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' DEPOFISID,TARIH,SAAT,D.DEPOADI AS DEPO,H.ACIKLAMA AS CARIHESAP, ACIK FROM TUKETIMFIS AS T WITH (NOLOCK)
   LEFT JOIN DEPO AS D WITH (NOLOCK) ON T.CDEPOID=D.DEPOID AND T.SUBEID=D.SUBEID LEFT JOIN MUH_HESAP AS H WITH (NOLOCK) ON T.HESAPID=H.HESAPID AND T.SUBEID=H.SUBEID
   WHERE ISNULL(T.SIL,0)=0 AND ACIK>0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ACILISFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_ACILISFISI] (@FIRMAID INT, @FISUUID uniqueidentifier, @SUBEID INT,@TARIH NVARCHAR(10), @KAPANISFISUUID uniqueidentifier,  @EKLEYENID INT, @ALTCARIMI INT, @ACIKLAMA NVARCHAR(100)) AS
BEGIN
DECLARE @FISID INT
DECLARE @KAPANISFISID INT
DECLARE @HATA INT
BEGIN TRANSACTION
		IF @ALTCARIMI=0
			BEGIN
				INSERT INTO MUH_FIS (FISUUID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, FIRMAID, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
				VALUES (@FISUUID, @TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Açılış', 41, @ACIKLAMA,@FIRMAID,@SUBEID,'ACILIS',0, @EKLEYENID,GETDATE(), 0, 1,'R')

				SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
				SELECT @KAPANISFISID=FISID FROM MUH_FIS WHERE FISUUID=@KAPANISFISUUID

				INSERT INTO MUH_HESAPISL(FISID,HESAPID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
				SELECT @FISID,  HESAPID, @ACIKLAMA, TUTAR,DTUTAR,   ALACAK,   BORC, DALACAK,   DBORC, KUR,DOVIZ,0  FROM MUH_HESAPISL WHERE FISID=@KAPANISFISID

				UPDATE MUH_FIS SET FISTURID=49 WHERE FISID=@FISID
				UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID

			END
		ELSE IF @ALTCARIMI=1
			BEGIN
				INSERT INTO MUH_FIS (FISUUID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, FIRMAID,SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
				VALUES (@FISUUID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Açılış', 41, @ACIKLAMA,@FIRMAID,@SUBEID,'ACILIS',0, @EKLEYENID,GETDATE(), 0, 1,'R')

				SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
				SELECT @KAPANISFISID=FISID FROM MUH_FIS WHERE FISUUID=@KAPANISFISUUID

				INSERT INTO MUH_HESAPISL(FISID,HESAPID,ALTCARIID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
				SELECT @FISID,  HESAPID,ALTCARIID,@ACIKLAMA, TUTAR,DTUTAR,   ALACAK,   BORC, DALACAK,   DBORC, KUR,DOVIZ,0  FROM MUH_HESAPISL WHERE FISID=@KAPANISFISID
		
				UPDATE MUH_FIS SET FISTURID=49 WHERE FISID=@FISID
				UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID
			END
SET @HATA=@@ERROR
IF @HATA > 0 
	BEGIN
		ROLLBACK TRANSACTION
	END
ELSE
	BEGIN
		COMMIT TRANSACTION
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADISYON WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE+' ORDER BY MASANO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_GARSONOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON_GARSONOZET]  @PARAMETRE NVARCHAR(400)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TARIH,DEPART.ADI AS DEPARTMAN,ADISYON.TUR, GARSON.GADI, SUM(TOPLAM) AS TOPLAM, 
SUM(TOPLAM/100*ISNULL(INDORAN,0)) AS INDTUTAR, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS NETTOPLAM 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART WITH (NOLOCK) ON ADISYON.DEPID=DEPART.DEPARTMANID
INNER JOIN GARSON WITH (NOLOCK) ON ADISYON.GARSONID=GARSON.GARSONID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,DEPART.ADI,ADISYON.TUR,GADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_ODENEN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_ADISYON_ODENEN] @FISCOUNTER INT
AS
SELECT FISCOUNTER,TARIH,MASANO,GARSONID,DEPID,
TOPLAM,INDORAN,(TOPLAM/100)*(100-ISNULL(INDORAN,0)) AS NETTOPLAM, 
(SELECT SUM(ISNULL(TUTAR,0)*ISNULL(KUR,1)) FROM ADSODEME WITH (NOLOCK) WHERE ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER)*-1 AS ALINANODENEN,
(TOPLAM/100)*(100-ISNULL(INDORAN,0))-ISNULL((SELECT SUM(ISNULL(TUTAR,0)*ISNULL(KUR,1)) FROM ADSODEME WITH (NOLOCK) WHERE ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER),0) AS KALANODEME
FROM ADISYON WITH (NOLOCK) where FISCOUNTER=@FISCOUNTER
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON_OZET]  @PARAMETRE NVARCHAR(400)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TARIH,DEPART.ADI AS DEPARTMAN,ADISYON.TUR, SUM(TOPLAM) AS TOPLAM, 
SUM(TOPLAM/100*ISNULL(INDORAN,0)) AS INDTUTAR, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS NETTOPLAM 
FROM ADISYON WITH (NOLOCK) INNER JOIN DEPART WITH (NOLOCK) ON ADISYON.DEPID=DEPART.DEPARTMANID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,DEPART.ADI,ADISYON.TUR'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_TAHSILATOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON_TAHSILATOZET]  @PARAMETRE NVARCHAR(400)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(900)
SET @SQLCUMLE='SELECT TARIH,ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(DOVIZ,''TL'') AS DOVIZ  
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(SIL,0)=0 AND TUR=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID,DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_TOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON_TOPLAM]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SUM(TOPLAM/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM
FROM ADISYON
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_URUNSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYON_URUNSATIS]  @PARAMETRE NVARCHAR(450)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1250)
SET @SQLCUMLE='SELECT 
(CASE WHEN IKRAM=1 THEN ''IKRAM''
	 WHEN IADE=1 THEN ''IADE''
	 WHEN ZAYII=1 THEN ''ZAYII''
	 ELSE ''SATIŞ'' END) AS DURUM,
TARIH,DEPART.ADI AS DEPARTMAN, ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID 
AND ADISYON.SUBEID=STOK.SUBEID
INNER JOIN DEPART ON ADISYON.DEPID=DEPART.DEPARTMANID
WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND MASANO LIKE''Z%'' AND 1=1 '+@PARAMETRE+'
GROUP BY DEPART.ADI,TARIH,STOK.ADI,STOK.BIRIM,ADISYON.TUR,ADSSATIR.IKRAM,ADSSATIR.IADE, ADSSATIR.ZAYII
ORDER BY DEPART.ADI, DURUM DESC,ADISYON.TUR DESC,STOK.ADI'
EXEC (@SQLCUMLE)

/*SET @SQLCUMLE='SELECT TARIH,ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM,  */
/*SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM  */
/*FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER */
/*INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID  */
/*AND ADISYON.SUBEID=STOK.SUBEID */
/*WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+' */
/*GROUP BY TARIH,STOK.ADI,STOK.BIRIM,ADISYON.TUR */
/*ORDER BY ADISYON.TUR DESC,STOK.ADI' */

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYON_URUNSATIS_YEDEK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_ADISYON_URUNSATIS_YEDEK]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TARIH,ADISYON.TUR,STOK.ADI AS URUNADI,STOK.BIRIM, SUM(ADET) AS MIKTAR, SUM(TUTAR) AS TOPLAM, 
SUM(TUTAR/100*(100-ISNULL(ADISYON.INDORAN,0))) AS NETTOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID AND ADISYON.FIRMAID=STOK.FIRMAID 
AND ADISYON.SUBEID=STOK.SUBEID
WHERE ISNULL(ADSSATIR.SIL,0)=0 and ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,STOK.ADI,STOK.BIRIM,ADISYON.TUR
ORDER BY ADISYON.TUR DESC,STOK.ADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONACIK_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONACIK_MOBIL] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT CARIKART.UNVANI,STOK.ADI AS URUNADI, SUM(ADET) AS MIKTAR, SUM( (ADET*BIRIMFIYAT)/100*(100-ADISYON.INDORAN)) AS TOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN CARIKART ON ADISYON.MKNO=CARIKART.CARIID
WHERE MKNO>0 AND ISNULL(ADSSATIR.SIL,0)=0 AND ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GROUP BY CARIKART.UNVANI,STOK.ADI ORDER BY CARIKART.UNVANI
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONANALIZ]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_ADISYONANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONANALIZ_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONANALIZ_DETAY]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @CARIID NVARCHAR(20), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_ADISYONANALIZ_DETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@CARIID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONIADE_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_ADISYONIADE_MOBIL] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT GARSON.GADI, MASANO, convert(varchar, SAAT, 108) as SAAT, STOK.ADI AS URUNADI, SUM(ADET) AS MIKTAR, SUM( (ADET*BIRIMFIYAT)/100*(100-ADISYON.INDORAN)) AS TOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
LEFT JOIN GARSON ON ADSSATIR.GARSONID=GARSON.GARSONID
WHERE ADET<0 AND ISNULL(ADSSATIR.SIL,0)=0 AND ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GROUP BY GARSON.GADI,SAAT,STOK.ADI,MASANO ORDER BY GARSON.GADI
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONOZET_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONOZET_MOBIL] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT (SELECT SUM(ISNULL(ONAKIT,0)+ISNULL(OKK,0)) AS TOPLAM FROM ADISYON WHERE TUR='SATIS' AND ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2) AS NAKIT,
(SELECT SUM(ISNULL(OACIK,0)) AS TOPLAM FROM ADISYON WHERE TUR='SATIS' AND ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2) AS ACIK,
(SELECT SUM(ISNULL(OACIK,0)+ISNULL(OKK,0)) AS TOPLAM FROM ADISYON WHERE TUR<>'SATIS' AND ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2) AS ODENMEZ,
(SELECT SUM(ISNULL(TOPLAM,0)/100*(100-ISNULL(INDORAN,0))) AS TOPLAM FROM ADISYON WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2) AS TOPLAM
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONOZET_TOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONOZET_TOPLAM]  @TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH, (CASE WHEN POSTURU=1 THEN ''01-Yiyecek'' WHEN POSTURU=2 THEN ''02-İçecek'' 
WHEN POSTURU=3 then ''03-Diğer'' ELSE ''04-Muhtelif'' END) AS TURU, 
SUM(ADET) AS MIKTAR, SUM(NETTOPLAM) AS TOPLAM FROM [FNCQ_ADISYONANALIZ] ('''+@TARIH+''','''+@TARIH+''','''+@FIRMAID+''')
WHERE TUR=''SATIS'' GROUP BY TARIH,POSTURU ORDER BY TARIH,POSTURU '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADISYONSIRANO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADISYONSIRANO] @FIRMAID INT, @SUBEID INT
AS
UPDATE SAYACLAR SET SIRANO=1 WHERE TABLENAME='ADISYONNO' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSODEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_ADSODEME]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADSODEME WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSODEME_EKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSODEME_EKLE] @FISCOUNTER INT,@ODEMETURID INT, @TUTAR FLOAT, @ODEMETURU NVARCHAR(10), @GARSONID INT
AS
INSERT INTO ADSODEME (FISCOUNTER,ODEMETURID,ODEMETURU,TUTAR,YETKILIID,ACIKLAMA,ISLEMTIPI)
VALUES(@FISCOUNTER,@ODEMETURID,@ODEMETURU,@TUTAR,@GARSONID,'Tahsilat',1)
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSSATIR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(500)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADSSATIR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIR_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSSATIR_OZET]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT ADSSATIR.STOKID, ADSSATIR.GARSONID, GARSON.GADI AS GARSON, STOK.ADI AS URUNADI,STOK.ADI+'' ''+ISNULL(ADSSATIR.ACIKLAMA,'''') AS URUNADI2,STOK.BIRIM,ISNULL(BEKLET,0) AS BEKLET,
SUM(ADET) AS ADET, SUM(TUTAR) AS TUTAR, NULLIF(SUM(TUTAR),0)/NULLIF(SUM(ADET),0) AS BIRIMFIYAT
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
LEFT JOIN GARSON ON ADSSATIR.GARSONID=GARSON.GARSONID
WHERE ISNULL(ADSSATIR.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY STOK.ADI,STOK.BIRIM,ADSSATIR.ACIKLAMA,BEKLET,ADSSATIR.STOKID,ADSSATIR.GARSONID,GARSON.GADI ORDER BY BEKLET'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIR_OZET2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSSATIR_OZET2]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT ADSSATIR.STOKID, STOK.ADI AS URUNADI,STOK.ADI AS URUNADI2,STOK.BIRIM,
SUM(ADET) AS ADET, SUM(TUTAR) AS TUTAR, NULLIF(SUM(TUTAR),0)/NULLIF(SUM(ADET),0) AS BIRIMFIYAT
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
WHERE ISNULL(ADSSATIR.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY STOK.ADI,STOK.BIRIM,ADSSATIR.STOKID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIR_SIPARIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSSATIR_SIPARIS]  @FISCOUNTER NVARCHAR(10), @YAZICIID NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT POSYAZICIID1, ADSSATIR.STOKID,STOK.ADI AS STOKADI,STOK.BIRIM,
ACIKLAMA,ADSSATIR.BARKOD,H,SIP,INDORAN,ADSSATIR.GGRUP,SIPADET,INDTUTAR,ADET,BIRIMFIYAT,TUTAR 
FROM ADSSATIR INNER JOIN STOK ON ADSSATIR.STOKID=STOK.STOKID
WHERE FISCOUNTER='+@FISCOUNTER+' AND POSYAZICIID1='+@YAZICIID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIR_YAZDIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_ADSSATIR_YAZDIR]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT ADSSATIR.*, GARSON.GKODU, GARSON.GADI AS GARSONADI, STOK.ADI AS URUNADI,STOK.ADI+'' ''+ISNULL(ADSSATIR.ACIKLAMA,'''') AS URUNADI2 ,STOK.BIRIM,STOK.POSYAZICIID1,STOK.POSYAZICIID2,
NULLIF(ISNULL(ADSSATIR.TUTAR,0),0)/100*ISNULL(ADISYON.INDORAN,0) AS INDTUTAR, 
NULLIF(ISNULL(ADSSATIR.TUTAR,0),0)/100*(100-ISNULL(ADISYON.INDORAN,0)) AS NETTUTAR FROM ADSSATIR WITH (NOLOCK)
INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
LEFT JOIN GARSON WITH (NOLOCK) ON ADSSATIR.GARSONID=GARSON.GARSONID
WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSSATIRILAVE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSSATIRILAVE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(300)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADSSATIRILAVE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ADSYAZICI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ADSYAZICI]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT POSYAZICITIPID,YAZICIADI FROM POSYAZICITIP  WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AIDATFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AIDATFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM AIDATFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AIDATISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AIDATISLEM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM AIDATISLEM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AIDATMAHSUPSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AIDATMAHSUPSIL] @AIDATFISID INT, @FIRMAID INT, @USERID INT
AS
UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, DEL_USERID=@USERID, DEL_DATE=GETDATE() WHERE FIRMAID=@FIRMAID AND ENTKAYNAK='TOPLUBORC' AND ENTKAYNAKID=@AIDATFISID
UPDATE AIDATISLEM SET FISID=NULL WHERE AIDATFISID=@AIDATFISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_AIDATOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AIDATOZET] @AIDATFISID INT
AS
SELECT AIDATFISID,TARIH,VADESI,DVZ,KUR FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID GROUP BY AIDATFISID,TARIH,VADESI,DVZ,KUR ORDER BY TARIH
GO
/****** Object:  StoredProcedure [dbo].[PRL_AJANDA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AJANDA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM AJANDA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AJANDAIPTAL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AJANDAIPTAL] @SPAFISID INT, @FIRMAID INT, @FISDURUM INT
AS
IF @FISDURUM=-2
	BEGIN
		UPDATE AJANDA SET SIL=-3 WHERE SPAFISID=@SPAFISID AND FIRMAID=@FIRMAID
	END
ELSE
	BEGIN
		UPDATE AJANDA SET SIL=0 WHERE SPAFISID=@SPAFISID AND FIRMAID=@FIRMAID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AJANDAISLEMSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

 

CREATE PROCEDURE [dbo].[PRL_AJANDAISLEMSIL] (@FIRMAID INT, @ISLEMID INT, @MODUL NVARCHAR(20))
AS
IF @FIRMAID>0
	BEGIN
		DELETE FROM AJANDA WHERE FIRMAID=@FIRMAID AND ISLEMID=@ISLEMID AND [LOCATION]=@MODUL
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AJANDAKAYNAK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_AJANDAKAYNAK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM AJANDAKAYNAK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AJANDATAKSITSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 

CREATE PROCEDURE [dbo].[PRL_AJANDATAKSITSIL] (@FIRMAID INT, @ISLEMID INT)
AS
IF @FIRMAID>0
	BEGIN
		DELETE FROM AJANDA WHERE FIRMAID=@FIRMAID AND ISLEMID=@ISLEMID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_GERIAL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_GERIAL] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
BEGIN
	IF @FISHESAPID>0
		BEGIN
			UPDATE FATURA SET SIL=-2 WHERE FIRMAID=@FIRMAID AND FATID IN(SELECT DISTINCT FATID FROM FATAKTARIM WHERE FATID>0 AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND TARIH BETWEEN @TARIH AND @TARIH2)
			UPDATE FATAKTARIM SET FATID=NULL WHERE FATID>0 AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND TARIH BETWEEN @TARIH AND @TARIH2
		END
	ELSE
		BEGIN
			UPDATE FATURA SET SIL=-2 WHERE FIRMAID=@FIRMAID AND FATID IN(SELECT DISTINCT FATID FROM FATAKTARIM WHERE FATID>0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2)
			UPDATE FATAKTARIM SET FATID=NULL WHERE FATID>0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2		
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_ISARETLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_ISARETLE] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @FATID INT
AS
BEGIN
	UPDATE FATAKTARIM SET FATAKTARIM.FATID=@FATID WHERE FATID IS NULL AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND TARIH=@TARIH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_ISARETLE_FATNO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_ISARETLE_FATNO] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @FATID INT, @FATURANO NVARCHAR(30)
AS
BEGIN
	UPDATE FATAKTARIM SET FATAKTARIM.FATID=@FATID WHERE FATID IS NULL AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND TARIH=@TARIH AND FATURANO=@FATURANO
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_KONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_KONTROL] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
BEGIN
	SELECT TARIH,FIRMAID,SUBEID,DEPOID,FISHESAPID FROM FATAKTARIM WHERE ISNULL(STOKID,0)=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND FATID IS NULL GROUP BY TARIH,FIRMAID,SUBEID,DEPOID,FISHESAPID ORDER BY TARIH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_OZET] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
BEGIN
	SELECT TARIH,FATURANO,FIRMAID,SUBEID,DEPOID,FISHESAPID FROM FATAKTARIM WHERE TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND FATID IS NULL GROUP BY TARIH,FATURANO,FIRMAID,SUBEID,DEPOID,FISHESAPID ORDER BY TARIH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_SATIRLAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_SATIRLAR] @FIRMAID INT, @FISHESAPID INT, @TARIH NVARCHAR(10), @FATURANO NVARCHAR(30)
AS
BEGIN
	SELECT * FROM FATAKTARIM WHERE STOKID IS NOT NULL AND TARIH=@TARIH AND FIRMAID=@FIRMAID AND FISHESAPID=@FISHESAPID AND FATURANO=@FATURANO AND FATID IS NULL 
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AKTARIM_STOK_ESLESTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AKTARIM_STOK_ESLESTIR] @FIRMAID INT, @AKTARIMUUID uniqueidentifier, @KDVAYIR SMALLINT
AS
BEGIN
IF @KDVAYIR=1
	BEGIN
		UPDATE FATAKTARIM SET FATAKTARIM.STOKID=STOK.STOKID, FATAKTARIM.KDVORAN=ISNULL(STOK.SATISKDV,FATAKTARIM.KDVORAN), FATAKTARIM.FBIRIM=STOK.BIRIM
		FROM FATAKTARIM INNER JOIN STOK ON FATAKTARIM.STOKADI=STOK.ADI WHERE FATAKTARIM.FIRMAID=@FIRMAID AND STOK.FIRMAID=@FIRMAID /*AND FATAKTARIM.AKTARIMUUID=@AKTARIMUUID */

		UPDATE FATAKTARIM SET FBFIYAT=FBFIYAT/(100+KDVORAN)*100, ARATOPLAM=FMIKTAR*(FBFIYAT/(100+KDVORAN)*100) WHERE KDVORAN>0 AND AKTARIMUUID=@AKTARIMUUID
	END
ELSE IF @KDVAYIR=0
	BEGIN
		UPDATE FATAKTARIM SET FATAKTARIM.STOKID=STOK.STOKID, FATAKTARIM.KDVORAN=ISNULL(STOK.SATISKDV,FATAKTARIM.KDVORAN), FATAKTARIM.FBIRIM=STOK.BIRIM
		FROM FATAKTARIM INNER JOIN STOK ON FATAKTARIM.STOKADI=STOK.ADI WHERE FATAKTARIM.FIRMAID=@FIRMAID AND STOK.FIRMAID=@FIRMAID /*AND FATAKTARIM.AKTARIMUUID=@AKTARIMUUID */
	END
	UPDATE FATAKTARIM SET FATAKTARIM.FISHESAPID=MUH_HESAP.HESAPID 
	FROM FATAKTARIM INNER JOIN MUH_HESAP ON SUBSTRING(FATAKTARIM.CARIUNVAN,1,25)=SUBSTRING(MUH_HESAP.ACIKLAMA,1,25)
	WHERE FATAKTARIM.FIRMAID=@FIRMAID AND MUH_HESAP.FIRMAID=@FIRMAID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ALISFATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ALISFATURA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATID,TARIH,D.DEPOADI AS DEPOADI,FATNO,UNVANI,TOPLAM,KDV,GTOPLAM 
FROM FATURA WITH (NOLOCK) LEFT JOIN DEPO AS D WITH (NOLOCK) ON FATURA.DEPOID=D.DEPOID  
WHERE ISNULL(FATURA.SIL,0)=0 AND TUR=1 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ALTCARI_ISARETLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ALTCARI_ISARETLE] @HESAPID INT, @FIRMAID INT
AS
UPDATE MUH_HESAP SET ALTCARIKULLANIR=1 WHERE HESAPID=@HESAPID AND FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[PRL_ANLASMAFIYATBUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ANLASMAFIYATBUL] @FIRMAID INT, @SUBEID INT, @TARIH SMALLDATETIME, @HESAPID INT, @STOKID INT
AS
SET NOCOUNT ON
BEGIN
SELECT CARIID,BTARIH,STARIH,
SAD.STOKID,SAD.BIRIM AS ANLASMABIRIM,KOTA,
SAD.FIYAT AS ANLASMAFIYAT, ISNULL(SAD.NETMANUEL,0) AS MANUELFIYAT, ISNULL(ISKONTOORAN,0) AS ISKONTOORAN,ISNULL(ISKONTOORAN2,0) AS ISKONTOORAN2,
ISNULL(ISKONTOORAN3,0) AS ISKONTOORAN3,
(SAD.FIYAT/100*(100-ISNULL(ISKONTOORAN,0)))/100*(100-ISNULL(ISKONTOORAN2,0)) AS NETANLASMAFIYAT, SAD.KDV, SAD.KDVDAHILMI, BEDELSIZ,SAD.DOVIZ
FROM STOK_ANLASMA AS SA WITH (NOLOCK) INNER JOIN STOK_ANLASMA_DETAY AS SAD WITH (NOLOCK) 
ON SA.ANLASMAID=SAD.ANLASMAID
WHERE ISNULL(SA.SIL,0)=0 AND  SA.FIRMAID=@FIRMAID AND SA.SUBEID=@SUBEID AND CARIID=@HESAPID AND SAD.STOKID=@STOKID AND BTARIH<=@TARIH AND STARIH>=@TARIH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AYILKGUN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AYILKGUN]
AS
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) AS AYINILKGUNU,
DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) AS AYINSONGUNU
GO
/****** Object:  StoredProcedure [dbo].[PRL_AYLIK_PUANTAJ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_AYLIK_PUANTAJ] @FIRMAID INT, @TARIH1 SMALLDATETIME, @TARIH2 SMALLDATETIME
AS
BEGIN
	SELECT GOREVI,IKVARDIYA.IKVARDIYAID,SUBELER.SUBEADI,PERDEPART.DEPKODU,PERDEPART.DEPADI,IKPERSONEL.ADSOYAD,TARIH,YEAR(TARIH) AS YILI, MONTH(TARIH) AS AYI, 
	IKVARDIYATARIH.IKVARDIYATANIMID, V.VARDIYAKODU,V.VARDIYAADI,V.GIRIS,V.CIKIS,V.TURU,SAY AS GUN, DAY(TARIH) AS GUNU 
	FROM IKVARDIYA WITH (NOLOCK)
	INNER JOIN IKVARDIYATARIH WITH (NOLOCK) ON IKVARDIYA.IKVARDIYAID=IKVARDIYATARIH.IKVARDIYAID 
	INNER JOIN IKVARDIYATANIM AS V WITH (NOLOCK) ON IKVARDIYATARIH.IKVARDIYATANIMID=V.IKVARDIYATANIMID
	INNER JOIN SUBELER WITH (NOLOCK) ON IKVARDIYA.SUBEID=SUBELER.SUBEID
	INNER JOIN IKPERSONEL WITH (NOLOCK) ON IKVARDIYATARIH.PSICILID=IKPERSONEL.PSICILID
	LEFT JOIN PERDEPART WITH (NOLOCK) ON IKPERSONEL.DEPARTMANID=PERDEPART.PERDEPARTMANID
	WHERE IKVARDIYA.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AYLIKVARDIYA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_AYLIKVARDIYA]  @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_AYLIK_VARDIYA ('''+@FIRMAID+''') WHERE  1=1  '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_AYLIKVARDIYA_PER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_AYLIKVARDIYA_PER]  @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_AYLIK_VARDIYA_PER ('''+@FIRMAID+''') WHERE  1=1  '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BABS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BABS]  
@FIRMAID NVARCHAR(10),
@SUBEID NVARCHAR(10),
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10),
@YIL NVARCHAR(5),
@AY NVARCHAR(5),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(  SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MAX(UNVANI) AS UNVANI, MAX(EMAIL) AS EMAIL,REPLACE(VDNO,' ','') AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE F.FIRMAID=@FIRMAID AND ISNULL(FISIVAR,0)=1 AND  ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0) AND (VDNO IS NOT NULL AND LTRIM(VDNO)<>'') AND FISDURUMID>=0   AND SUBEID=@SUBEID   AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), REPLACE(VDNO,' ',''),REPLACE(CASE WHEN VDNO='1111111111' OR VDNO='11111111111' OR VDNO='2222222222' OR VDNO='22222222222' THEN  UNVANI ELSE VDNO END,' ','')  
			   UNION ALL 
			   SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, UNVANI, EMAIL,CASE WHEN TUR = 1 THEN '1111111111' ELSE '2222222222' END AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM((GTOPLAM-KDV-ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS BABSNET, SUM((KDV+ISNULL(DBO.FNETS_SATIR_KDV(F.FATID),0)) ) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         dbo.FATURA AS F (NOLOCK) 
			   WHERE F.FIRMAID=@FIRMAID AND  ISNULL(FISIVAR,0)=1 AND   ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0)   AND (VDNO IS NULL OR LTRIM(VDNO)='') AND FISDURUMID>=0    AND SUBEID=@SUBEID  AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), UNVANI,EMAIL  
			  UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, MAX(ISNULL(H.UNVANI,H.ACIKLAMA) ) AS UNVANI, MAX(H.EMAIL) AS EMAIL, REPLACE(H.VDNO,' ','') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
			 FROM (SELECT FISTURID,SUBEID, TARIH, HESAPID, BABSTUTAR,'' AS OZELKOD1, BORC+ALACAK AS TOPLAM
		   , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
		   FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS  QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		   WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')<>'' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		   GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),REPLACE(VDNO,' ',''),REPLACE(CASE WHEN H.VDNO='1111111111' OR H.VDNO='11111111111' OR H.VDNO='2222222222' OR H.VDNO='22222222222' THEN  H.ACIKLAMA ELSE H.VDNO END,' ',''), F.ALANTIPI
		 UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, ISNULL(H.UNVANI,H.ACIKLAMA)  AS UNVANI, H.EMAIL,ISNULL(H.VDNO,'') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
		 FROM (SELECT FISTURID, SUBEID,TARIH, HESAPID, BABSTUTAR,'' AS OZELKOD1,BORC+ALACAK AS TOPLAM
			 , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
			 FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS  QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		 WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')='' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		 GROUP BY YEAR(F.TARIH),MONTH(F.TARIH),ISNULL(H.UNVANI,H.ACIKLAMA) ,EMAIL, H.VDNO, F.ALANTIPI
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BABSFATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BABSFATURA]  
@FIRMAID NVARCHAR(10),
@SUBEID NVARCHAR(10),
@YIL NVARCHAR(5),
@AY NVARCHAR(5),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(  SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MAX(UNVANI) AS UNVANI, MAX(EMAIL) AS EMAIL, REPLACE(VDNO,' ','') AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM(TOPLAM) AS BABSNET, SUM(KDV) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         FATURA AS F (NOLOCK) 
			   WHERE F.FIRMAID=@FIRMAID AND ISNULL(FISIVAR,0)=0 AND  ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0) AND (VDNO IS NOT NULL AND LTRIM(VDNO)<>'') AND FISDURUMID>=0   AND SUBEID=@SUBEID   AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, EMAIL,YEAR(TARIH), MONTH(TARIH), REPLACE(VDNO,' ',''),REPLACE(CASE WHEN VDNO='1111111111' OR VDNO='11111111111' OR VDNO='2222222222' OR VDNO='22222222222' THEN  UNVANI ELSE VDNO END,' ','')  
			   UNION ALL 
			   SELECT     YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, UNVANI, EMAIL, CASE WHEN TUR = 1 THEN '1111111111' ELSE '2222222222' END AS VDNO, MAX(ISNULL(ULKEKODU, '052')) AS ULKEKODU, 
									 SUM(TOPLAM) AS BABSNET, SUM(KDV) AS KDV, 
									 CASE WHEN (TUR = - 1) THEN 'BS' ELSE 'BA' END AS BABSDURUMU, COUNT(*) AS FATSAYISI 
			   FROM         FATURA AS F (NOLOCK) 
			   WHERE F.FIRMAID=@FIRMAID AND  ISNULL(FISIVAR,0)=0 AND   ISNULL(BABSHARIC,0)=0 AND  (ISNULL(FIPTAL, 0) = 0) AND (ISNULL(FISDURUMID,0)>=0)   AND (VDNO IS NULL OR LTRIM(VDNO)='') AND FISDURUMID>=0    AND SUBEID=@SUBEID  AND 1=1 AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
			   GROUP BY TUR, YEAR(TARIH), MONTH(TARIH), UNVANI,EMAIL  
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BABSMUH]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

--EXEC PRL_BABSMUH '1','1','2020','5','2020-01-01','2020-05-31',2000

CREATE PROCEDURE [dbo].[PRL_BABSMUH]  
@FIRMAID NVARCHAR(10),
@SUBEID NVARCHAR(10),
@YIL NVARCHAR(10),
@AY NVARCHAR(10),
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10),
@LIMIT FLOAT
AS
BEGIN
		SELECT TOP (100) PERCENT  ROW_NUMBER() OVER (ORDER BY YIL,AY,BABSDURUMU,UNVANI) AS SIRA ,YIL,AY,UNVANI,EMAIL,VDNO AS VDNO_TCNO,ULKEKODU,BABSNET,KDV,BABSDURUMU,FATSAYISI, 
		 CASE WHEN LEN(VDNO)=11 THEN VDNO ELSE '' END AS TCKIMLIKNO, CASE WHEN LEN(VDNO)<>11 THEN VDNO ELSE '' END AS VDNO 
		 FROM (    SELECT  YIL,AY,UNVANI,EMAIL,VDNO,MAX(ULKEKODU) AS ULKEKODU,FLOOR(SUM(BABSNET)) AS BABSNET,FLOOR(SUM(KDV)) AS KDV ,BABSDURUMU,SUM(FATSAYISI) AS FATSAYISI FROM 
			(SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, MAX(ISNULL(H.UNVANI,H.ACIKLAMA) ) AS UNVANI, EMAIL, REPLACE(H.VDNO,' ','') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
			 FROM (SELECT FISTURID,SUBEID, TARIH, HESAPID, BABSTUTAR,'' AS OZELKOD1, BORC+ALACAK AS TOPLAM
		   , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
		   FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		   WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')<>'' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		   GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),REPLACE(VDNO,' ',''),REPLACE(CASE WHEN H.VDNO='1111111111' OR H.VDNO='11111111111' OR H.VDNO='2222222222' OR H.VDNO='22222222222' THEN  H.ACIKLAMA ELSE H.VDNO END,' ',''), F.ALANTIPI
		 UNION ALL 
		 SELECT YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY, ISNULL(H.UNVANI,H.ACIKLAMA)  AS UNVANI, EMAIL, ISNULL(H.VDNO,'') AS VDNO, MAX(ISNULL(H.ULKEKODU, '052')) AS ULKEKODU,
			 SUM(F.BABSTUTAR) AS BABSNET, SUM(F.TOPLAM-F.BABSTUTAR) AS KDV,
			 CASE WHEN F.ALANTIPI<>'BORC' THEN 'BA' ELSE 'BS' END AS BABSDURUMU, COUNT(*) AS FATSAYISI
		 FROM (SELECT FISTURID, SUBEID,TARIH, HESAPID, BABSTUTAR, '' AS OZELKOD1,BORC+ALACAK AS TOPLAM
			 , CASE WHEN BORC>0 THEN 'BORC' ELSE 'ALACAK' END AS ALANTIPI
			 FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL WHERE BABSTUTAR > 0) AS F
		   INNER JOIN MUH_HESAP H ON F.HESAPID=H.HESAPID
		 WHERE F.FISTURID>40 AND F.FISTURID<50 AND ISNULL(H.VDNO,'')='' AND  YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND 1=1
		 AND F.SUBEID=@SUBEID AND 1=1
		 GROUP BY EMAIL,YEAR(F.TARIH),MONTH(F.TARIH),ISNULL(H.UNVANI,H.ACIKLAMA) , H.VDNO, F.ALANTIPI
			) AS TBL   GROUP BY YIL,AY,UNVANI,EMAIL,VDNO,BABSDURUMU  HAVING (SUM(BABSNET) >= @LIMIT)  ) AS TBL2  ORDER BY YIL,AY,BABSDURUMU,UNVANI
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKADONEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_BANKADONEM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BANKADONEM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKLE] @FIRMAID INT, @SUBEID INT
AS
INSERT INTO MUH_BANKATANIM (FIRMAID,SUBEID,BANKAKODU,BANKAADI,BANKAUNVAN) 
SELECT @FIRMAID,@SUBEID,BANKAKODU,BANKAADI,BANKAUNVAN FROM MUH_BANKATANIM WHERE FIRMAID=-1
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_BANKAEKSTRE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRE_FISSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRE_FISSIL] @FIRMAID INT, @ID INT, @SILTARIH NVARCHAR(20), @USERID INT
AS
BEGIN
	UPDATE MUH_FIS SET FISDURUMID=-2, SIL=-2, OZELKOD4='GERIALINDI', DEL_DATE=@SILTARIH, DEL_USERID=@USERID WHERE FIRMAID=@FIRMAID AND FISID IN(SELECT FISID FROM MUH_BANKAEKSTRE_DETAY WHERE BANKAEKSTREID=@ID and FISID>0)
	UPDATE MUH_BANKAEKSTRE_DETAY SET FISID=NULL, FISUUID=NULL WHERE BANKAEKSTREID=@ID AND FISID>0
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRE_HESAPBUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRE_HESAPBUL]  @SUBEID INT, @EKSTREID INT
AS
SET NOCOUNT ON
UPDATE MUH_BANKAEKSTRE_DETAY
     SET  KARSIHESAPID = (SELECT TOP 1 KARSIHESAPID FROM MUH_BANKAEKSTRE_DETAY X
     WHERE SUBEID=@SUBEID AND ISNULL(X.ANAHTAR,'')<>''
     AND  X.KARSIHESAPID IS NOT NULL AND CHARINDEX(X.ANAHTAR,MUH_BANKAEKSTRE_DETAY.ACIKLAMA)>0
     ORDER BY ID DESC),  ALTCARIID=(SELECT TOP 1 ALTCARIID
     FROM MUH_BANKAEKSTRE_DETAY X WHERE SUBEID=@SUBEID AND ISNULL(X.ANAHTAR,'')<>''
     AND  X.ALTCARIID IS NOT NULL AND CHARINDEX(X.ANAHTAR,MUH_BANKAEKSTRE_DETAY.ACIKLAMA)>0
     ORDER BY ID DESC )
     WHERE SUBEID=@SUBEID AND  ISNULL(ACIKLAMA,'')<>'' AND KARSIHESAPID IS NULL AND BANKAEKSTREID=@EKSTREID
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRE_KURBUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRE_KURBUL] @FIRMAID INT, @SUBEID INT, @ID INT
AS
BEGIN
	UPDATE MUH_BANKAEKSTRE_DETAY SET MUH_BANKAEKSTRE_DETAY.KUR=ISNULL(MBDOVIZALIS,1) 
	FROM MUH_BANKAEKSTRE_DETAY INNER JOIN MUH_BANKAEKSTRE ON MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=MUH_BANKAEKSTRE.ID
	LEFT JOIN DOVIZISL ON MUH_BANKAEKSTRE.DOVIZ=DOVIZISL.KODU AND MUH_BANKAEKSTRE_DETAY.TARIH=DOVIZISL.TARIH
	WHERE DOVIZISL.FIRMAID=@FIRMAID AND MUH_BANKAEKSTRE.FIRMAID=@FIRMAID AND  MUH_BANKAEKSTRE.SUBEID=@SUBEID AND 
	MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=@ID AND MUH_BANKAEKSTRE.ID=@ID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRE_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRE_OZET] @SUBEID INT, @ID INT, @BA NVARCHAR(1)
AS
BEGIN
IF @BA='A'
	BEGIN
		SELECT TARIH FROM MUH_BANKAEKSTRE_DETAY WITH (NOLOCK) 
		WHERE ISNULL(FISID,0)=0 AND BANKAEKSTREID=@ID AND TUTAR<0 AND ISNULL(KARSIHESAPID,0)<>0 GROUP BY TARIH ORDER BY TARIH
	END
ELSE IF @BA='B'
	BEGIN
		SELECT TARIH FROM MUH_BANKAEKSTRE_DETAY WITH (NOLOCK) 
		WHERE ISNULL(FISID,0)=0 AND BANKAEKSTREID=@ID AND TUTAR>0 AND ISNULL(KARSIHESAPID,0)<>0 GROUP BY TARIH ORDER BY TARIH
	END
ELSE
	BEGIN
		SELECT TARIH FROM MUH_BANKAEKSTRE_DETAY WITH (NOLOCK) 
		WHERE ISNULL(FISID,0)=0 AND BANKAEKSTREID=@ID AND ABS(TUTAR)>0 AND ISNULL(KARSIHESAPID,0)<>0 GROUP BY TARIH ORDER BY TARIH
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTREDETAY_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAEKSTREDETAY_DETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_BANKAEKSTRE_DETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAEKSTRETANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BANKAEKSTRETANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BANKAEXTRETANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAFISDUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAFISDUZELT] @HESAPID INT, @FISID INT, @DETAYID INT
AS
UPDATE MUH_HESAPISL SET HESAPID=@HESAPID WHERE FISID=@FISID AND BANKAEKSTREDETAYID=@DETAYID
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAFISI_OLUSTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAFISI_OLUSTUR]  
@FISUUID uniqueidentifier,
@TARIH SMALLDATETIME,
@EKLEMETARIH SMALLDATETIME,
@BANKAID INT,
@USERID INT,
@SUBEID INT,
@FIRMAID INT,
@FISTURID INT,
@BANKAEKSTREID INT,
@DOVIZ NVARCHAR(10)

AS
BEGIN 
declare @FISID INT
declare @HATA INT
BEGIN TRANSACTION
	INSERT INTO MUH_FIS (FISUUID,FISHESAPID,ALTCARIID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, FIRMAID,SUBEID, ENTKAYNAK, ADD_USERID, ADD_DATE, 
	TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE) 
	VALUES (@FISUUID,@BANKAID,Null,@TARIH,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH), (CASE WHEN @FISTURID=4 THEN 'Bankadan Ödeme' ELSE 'Bankaya Tahsilat' end),@FISTURID,'Günlük Banka İşlemleri','',@FIRMAID,@SUBEID,'BankaEkstreOku',@USERID,@EKLEMETARIH, 0, 
	0, 0, 0,@DOVIZ,1,@FISID,'Muhasebe Fişi','BANKA',-1,1)
SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
IF @FISTURID=4
	BEGIN
		INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
		SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
		ABS(TUTAR)*KUR AS BORC, 0.00 AS ALACAK,KUR,@DOVIZ,ABS(TUTAR) AS DBORC,0.00 AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
		MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
		FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
		KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR < 0 
	END

ELSE IF @FISTURID=3
	BEGIN
		INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
		SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
		0.00 AS BORC, ABS(TUTAR)*KUR AS ALACAK,KUR,@DOVIZ,0.00 AS DBORC,ABS(TUTAR) AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
		MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
		FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
		KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR > 0 
	END

UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(TUTAR) FROM MUH_HESAPISL WHERE
ISNULL(SILINDI,0)=0 AND FISID=@FISID),
DTOPLAM=(SELECT SUM(DTUTAR) FROM MUH_HESAPISL WHERE
ISNULL(SILINDI,0)=0 AND FISID=@FISID),
KUR=(SELECT AVG(KUR) FROM MUH_HESAPISL WHERE
ISNULL(SILINDI,0)=0 AND FISID=@FISID)
WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISID=@FISID


UPDATE MUH_BANKAEKSTRE_DETAY SET FISID=@FISID, FISUUID=@FISUUID WHERE SUBEID=@SUBEID AND ID IN
(SELECT BANKAEKSTREDETAYID FROM MUH_HESAPISL WHERE FISID=@FISID)

SET @HATA=@@ERROR
IF @HATA > 0 
	BEGIN
		ROLLBACK TRANSACTION
	END
ELSE
	BEGIN
		COMMIT TRANSACTION
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAFISI_OLUSTUR2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAFISI_OLUSTUR2]  
@FISUUID uniqueidentifier,
@TARIH SMALLDATETIME,
@EKLEMETARIH SMALLDATETIME,
@BANKAID INT,
@BANKAALTCARIID INT,
@USERID INT,
@SUBEID INT,
@FIRMAID INT,
@FISTURID INT,
@BANKAEKSTREID INT,
@DOVIZ NVARCHAR(10),
@FISTURU INT

AS
BEGIN 
declare @FISID INT
declare @HATA INT
BEGIN TRANSACTION
IF @FISTURU<>41 
	BEGIN
			INSERT INTO MUH_FIS (FISUUID,FISHESAPID,ALTCARIID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, FIRMAID,SUBEID, ENTKAYNAK, ADD_USERID, ADD_DATE, 
			TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE) 
			VALUES (@FISUUID,@BANKAID,@BANKAALTCARIID,@TARIH,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH), (CASE WHEN @FISTURID=4 THEN 'Bankadan Ödeme' ELSE 'Bankaya Tahsilat' end),@FISTURID,'Günlük Banka İşlemleri','',@FIRMAID,@SUBEID,'BankaEkstreOku',@USERID,@EKLEMETARIH, 0, 
			0, 0, 0,@DOVIZ,1,@FISID,'Muhasebe Fişi','BANKA',-1,1)
		SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
		IF @FISTURID=4
			BEGIN
				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
				ABS(TUTAR)*KUR AS BORC, 0.00 AS ALACAK,KUR,@DOVIZ,(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END) AS DBORC,0.00 AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
				MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR < 0 
			END

		ELSE IF @FISTURID=3
			BEGIN
				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,ACIKLAMA),
				0.00 AS BORC, ABS(TUTAR)*KUR AS ALACAK,KUR,@DOVIZ,0.00 AS DBORC,(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END) AS DALACAK,ABS(TUTAR)*KUR,ABS(TUTAR),
				MASMERID,PROJEID,ID,OZELKOD1,OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY WHERE SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR > 0 
			END

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),
		DTOPLAM=(SELECT SUM(ISNULL(DTUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),
		KUR=ISNULL((SELECT AVG(ISNULL(KUR,1)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),1)

		WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISID=@FISID
		UPDATE MUH_BANKAEKSTRE_DETAY SET FISID=@FISID, FISUUID=@FISUUID WHERE SUBEID=@SUBEID AND ID IN
		(SELECT BANKAEKSTREDETAYID FROM MUH_HESAPISL WHERE FISID=@FISID)
	END
ELSE 
	BEGIN
			INSERT INTO MUH_FIS (FISUUID,FISHESAPID,ALTCARIID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, FIRMAID,SUBEID, ENTKAYNAK, ADD_USERID, ADD_DATE, 
			TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE) 
			VALUES (@FISUUID,NULL,Null,@TARIH,DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH), 'Mahsup',41,'Banka İşlemleri','',@FIRMAID,@SUBEID,'BankaEkstreOku',@USERID,@EKLEMETARIH, 0, 
			0, 0, 0,@DOVIZ,1,@FISID,'Muhasebe Fişi','BANKA',-1,1)

			SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
				
				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,@BANKAALTCARIID,@BANKAID,ISNULL(FISACIKLAMA,MUH_BANKAEKSTRE_DETAY.ACIKLAMA),
				0.00 AS BORC, (CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS ALACAK,(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE KUR END) AS KUR,@DOVIZ,0.00 AS DBORC,
				(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END) AS DALACAK,(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS TUTAR,
				(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END) AS DTUTAR,
				MASMERID,PROJEID,MUH_BANKAEKSTRE_DETAY.ID,MUH_BANKAEKSTRE_DETAY.OZELKOD1,MUH_BANKAEKSTRE_DETAY.OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY INNER JOIN MUH_BANKAEKSTRE ON MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=MUH_BANKAEKSTRE.ID  WHERE MUH_BANKAEKSTRE_DETAY.SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(MUH_BANKAEKSTRE_DETAY.TARIH)=@TARIH  AND TUTAR < 0 

				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,MUH_BANKAEKSTRE_DETAY.ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,MUH_BANKAEKSTRE_DETAY.ACIKLAMA),
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS BORC, 0.00 AS ALACAK,KUR,SDOVIZ, 
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')<>ISNULL(SDOVIZ,'TL') AND @DOVIZ='TL' THEN ABS(TUTAR)/ISNULL(KUR,1) ELSE ABS(TUTAR) END) AS DBORC,0.00 AS DALACAK,
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS TUTAR,
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')<>ISNULL(SDOVIZ,'TL') AND @DOVIZ='TL' THEN ABS(TUTAR)/ISNULL(KUR,1) ELSE ABS(TUTAR) END) AS DTUTAR,
				MASMERID,PROJEID,MUH_BANKAEKSTRE_DETAY.ID,MUH_BANKAEKSTRE_DETAY.OZELKOD1,MUH_BANKAEKSTRE_DETAY.OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY INNER JOIN MUH_BANKAEKSTRE ON MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=MUH_BANKAEKSTRE.ID  WHERE MUH_BANKAEKSTRE_DETAY.SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR < 0 


				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,@BANKAALTCARIID,@BANKAID,ISNULL(FISACIKLAMA,MUH_BANKAEKSTRE_DETAY.ACIKLAMA),
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS BORC, 0.00 AS ALACAK,(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE KUR END) AS KUR,@DOVIZ,
				(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END) AS DBORC,0.00 AS DALACAK,(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS TUTAR,(CASE WHEN @DOVIZ='TL' THEN 0.00 ELSE ABS(TUTAR) END),
				MASMERID,PROJEID,MUH_BANKAEKSTRE_DETAY.ID,MUH_BANKAEKSTRE_DETAY.OZELKOD1,MUH_BANKAEKSTRE_DETAY.OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY INNER JOIN MUH_BANKAEKSTRE ON MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=MUH_BANKAEKSTRE.ID  WHERE MUH_BANKAEKSTRE_DETAY.SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR > 0 


				INSERT INTO MUH_HESAPISL(FISID,ALTCARIID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,MASMERID,PROJEID,BANKAEKSTREDETAYID,OZELKOD1,OZELKOD2,SILINDI,BELGETURU,BELGETARIH,BELGENO,ODEMEYONTEMI,BELGEACIKLAMA) 
				SELECT @FISID,MUH_BANKAEKSTRE_DETAY.ALTCARIID,KARSIHESAPID,ISNULL(FISACIKLAMA,MUH_BANKAEKSTRE_DETAY.ACIKLAMA),
				0.00 AS BORC, (CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS ALACAK,KUR,SDOVIZ, 0.00 AS DBORC,
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')<>ISNULL(SDOVIZ,'TL') AND @DOVIZ='TL' THEN ABS(TUTAR)/ISNULL(KUR,1) ELSE ABS(TUTAR) END) AS DALACAK,
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')=ISNULL(SDOVIZ,'TL') THEN ABS(TUTAR)*KUR ELSE ABS(TUTAR) END) AS TUTAR,
				(CASE WHEN ISNULL(MUH_BANKAEKSTRE.DOVIZ,'TL')<>ISNULL(SDOVIZ,'TL') AND @DOVIZ='TL' THEN ABS(TUTAR)/ISNULL(KUR,1) ELSE ABS(TUTAR) END) AS DTUTAR,
				MASMERID,PROJEID,MUH_BANKAEKSTRE_DETAY.ID,MUH_BANKAEKSTRE_DETAY.OZELKOD1,MUH_BANKAEKSTRE_DETAY.OZELKOD2,  0,-1,@TARIH,BELGENO, 'BANKA','Muhasebe Fişi' 
				FROM MUH_BANKAEKSTRE_DETAY INNER JOIN MUH_BANKAEKSTRE ON MUH_BANKAEKSTRE_DETAY.BANKAEKSTREID=MUH_BANKAEKSTRE.ID   WHERE MUH_BANKAEKSTRE_DETAY.SUBEID=@SUBEID AND ISNULL(MUH_BANKAEKSTRE_DETAY.AKTARMA,0)=0 AND 
				KARSIHESAPID IS NOT NULL AND FISUUID IS NULL AND BANKAEKSTREID=@BANKAEKSTREID AND dbo.TARIHAL(TARIH)=@TARIH  AND TUTAR > 0 

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),
		DTOPLAM=(SELECT SUM(ISNULL(DTUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID) WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISID=@FISID


		UPDATE MUH_BANKAEKSTRE_DETAY SET FISID=@FISID, AKTARMA=0, FISUUID=@FISUUID WHERE SUBEID=@SUBEID AND ID IN
		(SELECT BANKAEKSTREDETAYID FROM MUH_HESAPISL WHERE FISID=@FISID)

	END

		SET @HATA=@@ERROR
		IF @HATA > 0 
			BEGIN
				ROLLBACK TRANSACTION
			END
		ELSE
			BEGIN
				COMMIT TRANSACTION
			END
		END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAISLEMIPTAL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAISLEMIPTAL] @FISID INT, @EKSTREID INT
	AS
	UPDATE MUH_HESAPISL SET SILINDI=1 WHERE BANKAEKSTREDETAYID=@EKSTREID AND @FISID=@FISID

	UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0)) FROM MUH_HESAPISL WHERE
	ISNULL(SILINDI,0)=0 AND FISID=@FISID),
	DTOPLAM=(SELECT SUM(ISNULL(DTUTAR,0)) FROM MUH_HESAPISL WHERE
	ISNULL(SILINDI,0)=0 AND FISID=@FISID),
	KUR=ISNULL((SELECT AVG(ISNULL(KUR,1)) FROM MUH_HESAPISL WHERE
	ISNULL(SILINDI,0)=0 AND FISID=@FISID),1),
	EDIT_DATE=GETDATE()
	WHERE FISID=@FISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAKREDI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_BANKAKREDI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BANKAKREDI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAKREDI_ANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BANKAKREDI_ANALIZ] @FIRMAID  NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
DECLARE @SQL NVARCHAR(800)
SET @SQL='SELECT * FROM FNCQ_BANKAKREDI_ANALIZ ('''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC(@SQL)


GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAKREDIDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_BANKAKREDIDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BANKAKREDIDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKAKREDIMAHSUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BANKAKREDIMAHSUP]  
@FISUUID uniqueidentifier,
@TARIH nvarchar(10),
@ENTKAYNAKID INT,
@EKLEMETARIHI SMALLDATETIME,
@TOPLAM FLOAT,
@GERIODEMETUTARI FLOAT,
@SUBEID INT,
@FIRMAID INT,
@EKLEYEN INT,
@BANKAID INT,
@ANAPARAID INT,
@GELECEKGIDERID INT
AS
BEGIN
declare @FISID INT
IF @GELECEKGIDERID<=0
	BEGIN
		UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, DEL_DATE=GETDATE(), DEL_USERID=@EKLEYEN  WHERE ENTKAYNAKID=@ENTKAYNAKID AND FIRMAID=@FIRMAID AND  SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU'
		
		INSERT INTO MUH_FIS (FISNO,FISUUID,FIRMAID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1,ENTKAYNAK,ENTKAYNAKID)
		VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FISUUID,@FIRMAID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Banka Kredi Ent.',1,'TL',1,@TOPLAM,0.00,'BANKAKREDIMAHSUBU','BANKAKREDI',@ENTKAYNAKID)

		SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @BANKAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, @TOPLAM, 0.00, 0.00, 0.00, 0.00)
		
		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @ANAPARAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, 0.00, @TOPLAM, 0.00, 0.00, 0.00)
		UPDATE BANKAKREDI SET MUHFISID=@FISID, FISIVAR=1 WHERE BANKAKREDIID=@ENTKAYNAKID 
	END
ELSE
	BEGIN
		UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, DEL_DATE=GETDATE(), DEL_USERID=@EKLEYEN  WHERE ENTKAYNAKID=@ENTKAYNAKID AND FIRMAID=@FIRMAID AND  SUBEID=@SUBEID AND FISTURID=41 AND TARIH=@TARIH AND OZELKOD1='BANKAKREDIMAHSUBU'
		
		INSERT INTO MUH_FIS (FISNO,FISUUID,FIRMAID,SUBEID,FISTURID,FISDURUMID,ADD_DATE,ADD_USERID,TARIH,VADE,FISTURU,ACIKLAMA,DETAYLIENTEGRE,DOVIZ,KUR,TOPLAM,DTOPLAM,OZELKOD1,ENTKAYNAK,ENTKAYNAKID)
		VALUES(DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH),@FISUUID,@FIRMAID,@SUBEID,41,1,@EKLEMETARIHI,@EKLEYEN,@TARIH,@TARIH,'Mahsup','Banka Kredi Ent.',1,'TL',1,@TOPLAM,0.00,'BANKAKREDIMAHSUBU','BANKAKREDI',@ENTKAYNAKID)

		SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @BANKAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, @TOPLAM, 0.00, 0.00, 0.00, 0.00)

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @GELECEKGIDERID, 'Gelecek Aylara Ait Gider.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, (@GERIODEMETUTARI-@TOPLAM), 0.00, 0.00, 0.00, 0.00)

		INSERT INTO MUH_HESAPISL (FISID,HESAPID,ACIKLAMA,DOVIZ,OZELKOD1,TUTAR,DTUTAR,KUR,MIKTAR,BORC,ALACAK,DBORC,DALACAK,BABSTUTAR)
		VALUES(@FISID, @ANAPARAID, 'Banka Kredi Ent.', 'TL','BANKAKREDIMAHSUBU', @TOPLAM,
		@TOPLAM,1, 0.00, 0.00, @GERIODEMETUTARI, 0.00, 0.00, 0.00)
		UPDATE BANKAKREDI SET MUHFISID=@FISID, FISIVAR=1 WHERE BANKAKREDIID=@ENTKAYNAKID
	END

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BANKASEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE PROCEDURE [dbo].[PRL_BANKASEC]  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT HESAPID,SUBEID,HESAPTIPID,KODU,ACIKLAMA,DOVIZ,VADEGUN FROM 
MUH_HESAP WHERE ISNULL(SIL,0)=0 AND 
HESAPTIPID IN(102,108) AND UCHESAP=1 and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BARKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BARKOD WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODADET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BARKODADET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BARKODADET WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODADET_YENI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BARKODADET_YENI]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT BA.DEPOID,BA.FIRMAID,BA.SUBEID,SUBSTRING(BA.BARKOD,1,2) AS ULKEKODU, 
BRENKID,BBEDENID,RENKLER.RENKADI,BEDENLER.BEDEN AS BEDENADI, ISNULL(BA.BARKOD,S.BARKOD) AS BARKOD,S.BARKOD2,
S.KODU AS SKODU,S.ADI AS STOKADI,S.BIRIM2,S.KATSAYI2,BA.FIYATI AS BARKODFIYATI, 
S.SFIYAT1,S.SFIYAT2, S.SFIYAT3, S.SFIYAT4, S.SFIYAT5,
S.SDOVIZ1, S.SDOVIZ2, S.SDOVIZ3,S.SDOVIZ4,S.SDOVIZ5, 
S.BIRIM AS BIRIMI, S.SFIYAT2/NULLIF(ISNULL(S.KATSAYI2,0),0) AS KBFIYAT, S.SFIYAT1 AS FIYATI,
AMIKTAR,nullif(S.SFIYAT1/ISNULL(nullif(AMIKTAR,1000),1000),0)*1000 AS KGFIYATI,SFIYAT1KDV,ALISKDV,SATISKDV,
(CASE WHEN SFIYAT1KDV=0 THEN SFIYAT1/100*(100+SATISKDV) ELSE SFIYAT1 END) AS SFIYAT1KDVLI,S.OZELKOD1,S.OZELKOD2,S.OZELKOD3,S.AGIRLIK,
(CASE WHEN SUBSTRING(BA.BARKOD,1,2)=''86'' THEN ''TÜRKİYE'' ELSE ''OTHER'' END) AS ULKEADI,BA.SACIKLAMA,S.MALIYET,S.SALISFIYAT FROM BARKODADET AS BA WITH (NOLOCK) 
INNER JOIN STOK AS S WITH (NOLOCK)  ON BA.STOKID=S.STOKID
LEFT JOIN RENKLER WITH (NOLOCK) ON BA.BRENKID=RENKLER.RENKLERID 
LEFT JOIN BEDENLER WITH (NOLOCK) ON  BA.BBEDENID=BEDENLER.BEDENLERID 
WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODADETSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_BARKODADETSIL]  @STOKID INT, @FIRMAID INT 
AS
SET NOCOUNT ON
BEGIN
	DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BARKODEKLE]  @MIKTAR INT, @STOKID INT, @RENKID INT, @BEDENID INT, @SUBEID INT, @DEPOID INT, @FIRMAID INT, @BARKOD NVARCHAR(30),@ACIKLAMA NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE @SAYAC INT=1
	if (ISNULL(@BEDENID,0)<=0) AND (@DEPOID<0) DELETE FROM BARKODADET WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	IF @BARKOD=''
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM,SACIKLAMA) 
					SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,BARKOD,SFIYAT1,BIRIM,@ACIKLAMA FROM STOK WITH (NOLOCK) WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
	ELSE
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM,SACIKLAMA) 
					SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,@BARKOD,SFIYAT1,BIRIM,@ACIKLAMA FROM STOK WITH (NOLOCK) WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODEKLE_RENKBEDEN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_BARKODEKLE_RENKBEDEN]  @MIKTAR INT, @STOKID INT, @RENKID INT, @BEDENID INT, @SUBEID INT, @DEPOID INT, @FIRMAID INT, @BARKOD NVARCHAR(30)
AS
SET NOCOUNT ON
BEGIN
DECLARE @SAYAC INT=1
	IF @BARKOD=''
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM) SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,BARKOD,SFIYAT1,BIRIM FROM STOK WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
	ELSE
		BEGIN
			WHILE @SAYAC<=@MIKTAR
				BEGIN
					INSERT INTO BARKODADET (FIRMAID,SUBEID,DEPOID,STOKID,BRENKID,BBEDENID,BARKOD,FIYATI,BIRIM) SELECT @FIRMAID,@SUBEID,@DEPOID,STOKID,@RENKID,@BEDENID,@BARKOD,SFIYAT1,BIRIM FROM STOK WHERE STOKID=@STOKID
					SET @SAYAC=@SAYAC+1
				END
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BARKODRENKBEDEN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BARKODRENKBEDEN]  @STOKID INT
AS
BEGIN
SELECT STOKID,BARKOD,B.RENKID,B.BEDENID,R.RENKADI,BD.BEDEN
FROM BARKOD AS B LEFT JOIN RENKLER AS R ON B.RENKID=R.RENKLERID
LEFT JOIN BEDENLER AS BD ON B.BEDENID=BD.BEDENLERID WHERE STOKID=@STOKID AND B.BEDENID>0
ORDER BY RENKADI,BEDEN
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BEDENLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BEDENLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BEDENLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BELGEDUZENLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BELGEDUZENLE]  
(@SUBEID INT, @BASTARIH NVARCHAR(10),@BITTARIH NVARCHAR(10))
AS
BEGIN
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=3 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=4 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=1 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=2 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=42 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID=43 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGETURU=2, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID>=21 AND FISTURID<=36 AND BELGETURU IS NULL
		 UPDATE MUH_FIS SET BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGENO,'')='' AND BELGETURU=1
		 UPDATE MUH_FIS SET BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGENO IS NULL AND BELGETURU IN(-1,5,13,15,16,21)
		 UPDATE MUH_FIS SET BELGETURU=-1, BELGENO=FISNO WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGETURU,0)=0
		 

		 UPDATE MUH_FIS SET BELGETURU=11, BELGENO=ISNULL(BELGENO,FISNO)  WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'6%'))
		 UPDATE MUH_FIS SET BELGETURU=13  WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'335%'))
		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE BORC>0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'100%'))
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='NAKİT' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE ALACAK<0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'100%'))

		 UPDATE MUH_FIS SET BELGETURU=9, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE BORC>0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'102%'))
		 UPDATE MUH_FIS SET BELGETURU=10, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE ALACAK<0 AND HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'102%'))

		 UPDATE MUH_FIS SET BELGETURU=12, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='KREDI KARTI' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'108%'))

		 UPDATE MUH_FIS SET BELGETURU=2, BELGENO=ISNULL(BELGENO,FISNO), ODEMEYONTEMI='BANKA' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND BELGETURU IS NULL AND FISID IN(SELECT FISID FROM MUH_HESAPISL WHERE HESAPID IN(SELECT HESAPID FROM MUH_HESAP WHERE KODU LIKE'101%' OR KODU LIKE'103%'))


		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=MUH_FIS.BELGETURU, MUH_HESAPISL.BELGENO=MUH_FIS.BELGENO, MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH, MUH_HESAPISL.ODEMEYONTEMI=MUH_FIS.ODEMEYONTEMI
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND (MUH_HESAPISL.BELGETURU IS NULL OR MUH_HESAPISL.BELGETURU<>MUH_FIS.BELGETURU)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=-1, MUH_HESAPISL.BELGENO=NULL, MUH_HESAPISL.BELGETARIH=NULL, MUH_HESAPISL.ODEMEYONTEMI=NULL
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND (MUH_HESAPISL.BELGETURU IS NULL AND MUH_FIS.BELGETURU IS NULL)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGETURU=1, MUH_HESAPISL.BELGENO=ISNULL(MUH_FIS.BELGENO,MUH_FIS.FISNO), MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND MUH_FIS.BELGETURU=1

		 UPDATE MUH_FIS SET BELGEACIKLAMA=ACIKLAMA WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(BELGEACIKLAMA,'')='' AND MUH_FIS.BELGETURU IN(-1,5,13,15,16,21)

		 UPDATE MUH_HESAPISL SET MUH_HESAPISL.BELGENO=ISNULL(MUH_FIS.BELGENO,MUH_FIS.FISNO), MUH_HESAPISL.BELGETARIH=MUH_FIS.TARIH,MUH_HESAPISL.BELGEACIKLAMA=MUH_FIS.BELGEACIKLAMA
		 FROM MUH_HESAPISL INNER JOIN MUH_FIS ON MUH_HESAPISL.FISID=MUH_FIS.FISID 
		 WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND MUH_FIS.BELGETURU IN(-1,5,13,15,16,21)

		 UPDATE MUH_FIS SET SIL=-2, FISDURUMID=-2, OZELKOD3='FIS SATIRI YOK' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND  
		 FISID NOT IN(SELECT DISTINCT FISID FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH)) AND ISNULL(SIL,0)=0

		 UPDATE MUH_FIS SET ACIKLAMA='Muhasebe Fişi' WHERE SUBEID=@SUBEID AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND ISNULL(ACIKLAMA,'')=''

 END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BELGELER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_BELGELER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM BELGELER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BELGETURU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BELGETURU]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_BELGETURU WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_BIRIMSEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_BIRIMSEC]  @STOKID NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(200)
SET @SQLCUMLE='SELECT BIRIM,1 AS KATSAYI FROM STOK WHERE BIRIM<>'''' AND STOKID='''+@STOKID+'''
 UNION ALL
 SELECT BIRIM2,ISNULL(KATSAYI2,1) AS KATSAYI FROM STOK WHERE BIRIM5<>'''' AND STOKID='''+@STOKID+'''
 UNION ALL
 SELECT BIRIM3,ISNULL(KATSAYI3,1) AS KATSAYI FROM STOK WHERE BIRIM5<>'''' AND STOKID='''+@STOKID+'''
 UNION ALL
 SELECT BIRIM4,ISNULL(KATSAYI4,1) AS KATSAYI FROM STOK WHERE BIRIM5<>'''' AND STOKID='''+@STOKID+'''
 UNION ALL
 SELECT BIRIM5,ISNULL(KATSAYI5,1) AS KATSAYI FROM STOK WHERE BIRIM5<>'''' AND STOKID='''+@STOKID+''''
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CALLSIPARIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CALLSIPARIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CALLSIPARIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARI_KARSIISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARI_KARSIISLEM] @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
DECLARE @SQL NVARCHAR(2100)
SET @SQL='SELECT * FROM (
SELECT TARIH,''TUKETIMFIS'' AS TABLO,''01-STOK/MALZEME'' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, TEMPITSID AS ENTKAYNAKID,
DEPOFISISLID AS ISLEMID,MUH_HESAP.ACIKLAMA AS HESAPADI, STOK.ADI+'' ''+ISNULL(TUKETIMFISISL.ACIKLAMA,'''') AS ACIKLAMA, 
FMIKTAR AS MIKTAR, FBIRIM AS BIRIM, FBFIYAT AS BIRIMFIYAT,
FMIKTAR*FBFIYAT AS TUTAR, FBMALIYET AS SATISTUTARI 
FROM TUKETIMFIS INNER JOIN TUKETIMFISISL ON TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID 
INNER JOIN MUH_HESAP ON TUKETIMFIS.HESAPID=MUH_HESAP.HESAPID INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID
LEFT JOIN MUH_GRUP ON TUKETIMFIS.PROJEID=MUH_GRUP.GRUPID
WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND TUKETIMFIS.FIRMAID='+@FIRMAID+' AND ETSCARIID='+@HESAPID+'
UNION ALL
SELECT TARIH,''FATURA'' AS TABLO,''01-STOK/MALZEME'' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, KNO AS ENTKAYNAKID,FATISLID AS ISLEMID,MUH_HESAP.ACIKLAMA AS HESAPADI, STOK.ADI+'' ''+ISNULL(FATISL.ACIKLAMA,'''') AS ACIKLAMA, 
FADET AS MIKTAR, FBIRIM AS BIRIM, FBFIYAT AS BIRIMFIYAT,
ARATOPLAM AS TUTAR, FATISL.TOPLAM AS SATISTUTARI 
FROM FATURA INNER JOIN FATISL ON FATURA.FATID=FATISL.FATID INNER JOIN MUH_HESAP ON FATURA.FISHESAPID=MUH_HESAP.HESAPID INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID
LEFT JOIN MUH_GRUP ON FATURA.PROJEID=MUH_GRUP.GRUPID
WHERE ISNULL(FATURA.SIL,0)=0 AND FATURA.FIRMAID='+@FIRMAID+' AND FKARSIHESAPID='+@HESAPID+'
UNION ALL 
SELECT TARIH,''MUH_FIS'' AS TABLO, ''02-GİDERLER'' AS ISLEM, MUH_GRUP.GRUPADI AS PROJE, ENTKAYITID AS ENTKAYNAKID, ISLEMID, MUH_HESAP.ACIKLAMA AS HESAPADI,MUH_HESAPISL.ACIKLAMA,MIKTAR,BIRIM,BIRIMFIYAT,TUTAR,ISNULL(ODENMEYEN2,0) AS SATISTUTARI  FROM MUH_FIS
INNER JOIN MUH_HESAPISL ON MUH_FIS.FISID=MUH_HESAPISL.FISID INNER JOIN MUH_HESAP ON MUH_HESAPISL.HESAPID=MUH_HESAP.HESAPID
LEFT JOIN MUH_GRUP ON MUH_FIS.PROJEID=MUH_GRUP.GRUPID
WHERE ISNULL(MUH_FIS.SIL,0)=0 AND  MUH_FIS.FIRMAID='+@FIRMAID+' AND CKARSIHESAPID='+@HESAPID+') AS TBL WHERE 1=1 '+@PARAMETRE
EXEC(@SQL)
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARI_KARSIISLEM_SATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_CARI_KARSIISLEM_SATIS] @ISLEMID INT, @TUR NVARCHAR(10), @KARSIHESAPID INT, @ISLEM NVARCHAR(15), @DEGER FLOAT, @FISID INT
AS
IF ABS(@DEGER)>=0
	BEGIN
		IF @TUR='YUZDE'
			BEGIN
				IF @ISLEM='FATURA'
					BEGIN
						UPDATE FATISL SET TOPLAM=ARATOPLAM/100*(100+@DEGER) WHERE FATISL.FATISLID=@ISLEMID AND FKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='MUH_FIS'
					BEGIN
						UPDATE MUH_HESAPISL SET ODENMEYEN2=TUTAR/100*(100+@DEGER) WHERE ISLEMID=@ISLEMID AND CKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='TUKETIMFIS'
					BEGIN
						UPDATE TUKETIMFISISL SET FBMALIYET=(FMIKTAR*FBFIYAT)/100*(100+@DEGER) WHERE TUKETIMFISISL.DEPOFISISLID=@ISLEMID AND ETSCARIID=@KARSIHESAPID
					END
			END
		ELSE IF @TUR='TUTAR'
			BEGIN
				IF @ISLEM='FATURA'
					BEGIN
						UPDATE FATISL SET TOPLAM=@DEGER WHERE FATISL.FATISLID=@ISLEMID AND FKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='MUH_FIS'
					BEGIN
						UPDATE MUH_HESAPISL SET ODENMEYEN2=@DEGER WHERE ISLEMID=@ISLEMID AND CKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='TUKETIMFIS'
					BEGIN
						UPDATE TUKETIMFISISL SET FBMALIYET=@DEGER WHERE TUKETIMFISISL.DEPOFISISLID=@ISLEMID AND ETSCARIID=@KARSIHESAPID
					END
			END
		ELSE IF @TUR='UPDATE'
			BEGIN
				IF @ISLEM='FATURA'
					BEGIN
						UPDATE FATISL SET KNO=@FISID WHERE FATISL.FATISLID=@ISLEMID AND FKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='MUH_FIS'
					BEGIN
						UPDATE MUH_HESAPISL SET ENTKAYITID=@FISID WHERE ISLEMID=@ISLEMID AND CKARSIHESAPID=@KARSIHESAPID
					END
				IF @ISLEM='TUKETIMFIS'
					BEGIN
						UPDATE TUKETIMFISISL SET TEMPITSID=@FISID WHERE TUKETIMFISISL.DEPOFISISLID=@ISLEMID AND ETSCARIID=@KARSIHESAPID
					END
			END
		ELSE IF @TUR='DELETE'
			BEGIN
				IF @ISLEM='FATURA'
					BEGIN
						UPDATE FATISL SET KNO=NULL WHERE FATISL.FATISLID=@ISLEMID AND FKARSIHESAPID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='TUKETIMFIS'
					BEGIN
						UPDATE TUKETIMFISISL SET TEMPITSID=NULL WHERE TUKETIMFISISL.DEPOFISISLID=@ISLEMID AND ETSCARIID=@KARSIHESAPID
					END
				ELSE IF @ISLEM='MUH_FIS'
					BEGIN
						UPDATE MUH_HESAPISL SET ENTKAYITID=NULL WHERE ISLEMID=@ISLEMID AND CKARSIHESAPID=@KARSIHESAPID
						--PRINT(@ISLEMID)
						--PRINT(@FISID)
						--PRINT(@KARSIHESAPID)

					END
				UPDATE MUH_FIS SET SIL=-2 WHERE FISID=@FISID 	
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIBILET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARIBILET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CARIBILET WITH (NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIDAIRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CARIDAIRE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CARIDAIRE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIEKKART]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CARIEKKART]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CARIEKKART WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARIISLEM]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_CARIISLEM ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIISLEM_BAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_CARIISLEM_BAKIYE]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT CARIID, SUM(BORC) AS TBORC, SUM(ALACAK) AS TALACAK, SUM(BORC)-SUM(ALACAK) AS BAKIYE FROM FNCQ_CARIISLEM ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY CARIID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIISLEM_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARIISLEM_DETAY]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @CARIID NVARCHAR(20), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_CARIISLEM_MUAVIN ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@CARIID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIISLEM_SIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CARIISLEM_SIL] @FIRMAID INT, @KASAISLID INT
AS
DELETE FROM KASAMUH WHERE FIRMAID=@FIRMAID AND KASAISLID=@KASAISLID
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIKART]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARIKART]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CARIKART WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIKASAMUHISLEM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_CARIKASAMUHISLEM]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_KASAMUH ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARILER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_CARILER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' HESAPID,SUBEID,HESAPTIPID,KODU,ACIKLAMA,DOVIZ,VADEGUN,
VD,VDNO,TCKIMLIKNO,UNVANI,ADRES1,ADRES2,SEHIR,PKODU,YETKILI,
TEL1,STDIND,BORCTUTAR,ALACAKTUTAR,DBORCTUTAR,DALACAKTUTAR,
KARTKODU,AKTIF,ILCE,CINDORAN,SIL,STDIND2,ANLASMAOKU,FIYATTIPI,
TAPDK,VADEUYAR FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND 
HESAPTIPID IN(120,320,7,740) AND UCHESAP=1 and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CARIODEMETAHSILAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CARIODEMETAHSILAT] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(15), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT HESAPADI, MASMERADI,FISTURU AS FISTURADI,KARSIHESAPADI,ACIKLAMA,ALACAK AS TUTAR FROM FNCQ_QMUHMIZAN ('''+@TARIH+''','''+@TARIH+''','''+@FIRMAID+''')
WHERE HESAPKODU LIKE''120%'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CASCL3000]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CASCL3000]  @PARAMETRE NVARCHAR(250)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT 1 AS DeptNo, PLUNO AS PluNo, (case when BIRIM=''KG'' THEN 1 ELSE 2 END) AS PluType, PLUNO AS ItemCode, ADI AS Name1,
1 as FontSize1, 1 as FontSize2, 1 as FontSize3, 1 as FontSize4, 1 as FontSize5, 
ISNULL(SFIYAT1,0) AS UnitPrice, GETDATE() AS UpdateDate FROM STOK WHERE ISNULL(SIL,0)=0 AND PLUNO<>'''' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CASCL3000_2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CASCL3000_2] @FIRMAID INT
AS
SELECT  '1' AS [1.Department No], PLUNO AS [2.PLU No], '1' AS [4.PLU Type], 
PLUNO AS [11.ItemCode], SUBSTRING(ADI,1,20) AS [10.Name], 
SFIYAT1*100 AS [6.Price] FROM STOK WHERE FIRMAID=@FIRMAID AND ISNULL(SIL,0)=0 AND LEN(PLUNO)>=1 AND BARKOD LIKE'270%' ORDER BY PLUNO
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_CEKDETAY] @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT VADE,TARIH,BANKA,SUBE,CEKNO,HESAPADI AS SONFISHESAP,TLTUTAR FROM FNCQ_CEKLER ('''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE 
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CEKDURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CEKDURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKDURUMTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_CEKDURUMTIP]
AS
SELECT 1 AS DURUMID, 'İPTAL' AS DURUM
UNION ALL
SELECT 2 AS DURUMID, 'İADE' AS DURUM
UNION ALL
SELECT 3 AS DURUMID, 'KAYIP' AS DURUM
UNION ALL
SELECT 4 AS DURUMID, 'ZAYİ' AS DURUM
UNION ALL
SELECT 5 AS DURUMID, 'DİĞER' AS DURUM
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKKARNE_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	CREATE PROCEDURE [dbo].[PRL_CEKKARNE_DETAY]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @PARAMETRE NVARCHAR(350)
	AS
	BEGIN
	DECLARE
	@SQLCUMLE NVARCHAR(600)
	SET @SQLCUMLE='SELECT * FROM [FNCQ_CEKKARNEDETAY] ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE  1=1 '+@PARAMETRE
	EXEC (@SQLCUMLE)
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKKARNE_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CEKKARNE_UPDATE] @CEKID INT
AS
IF @CEKID>0
BEGIN
	UPDATE CEKKARNEDETAY SET CEKDURUMID=NULL, CEKID=NULL WHERE CEKID=@CEKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKKARNEDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_CEKKARNEDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CEKKARNEDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKKARNESI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_CEKKARNESI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CEKKARNESI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKLER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_CEKLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CEKLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKLISTE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CEKLISTE]  @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_CEKLER ('+@FIRMAID+') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKMIKTARI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CEKMIKTARI] @FIRMAID INT
AS
SELECT CD.CEKKARNESIID,MIKTAR, 
(SELECT COUNT(*) FROM CEKKARNEDETAY WHERE CEKID>0 AND CEKKARNEDETAY.CEKKARNESIID=CD.CEKKARNESIID) AS KULLANILAN, 
(SELECT COUNT(*) FROM CEKKARNEDETAY WHERE IPTALIADE>0 AND CEKKARNEDETAY.CEKKARNESIID=CD.CEKKARNESIID) AS IPTALIADE,
MIKTAR-((SELECT COUNT(*) FROM CEKKARNEDETAY WHERE CEKID>0 AND CEKKARNEDETAY.CEKKARNESIID=CD.CEKKARNESIID)+
(SELECT COUNT(*) FROM CEKKARNEDETAY WHERE IPTALIADE>0 AND CEKKARNEDETAY.CEKKARNESIID=CD.CEKKARNESIID)) AS KALAN
FROM CEKKARNESI INNER JOIN CEKKARNEDETAY AS CD ON CEKKARNESI.CEKKARNESIID=CD.CEKKARNESIID 
WHERE FIRMAID=@FIRMAID
GROUP BY CD.CEKKARNESIID,MIKTAR
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CEKOZET] @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1000)
SET @SQLCUMLE='SELECT VADEYIL AS VADEYILI,VADEAY AS VADEAYI, SUM(TLTUTAR) AS TOPLAM  
FROM FNCQ_CEKLER ('''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY VADEYIL,VADEAY ODER BY VADEYIL,VADEAY' 
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKSERI_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

	CREATE PROCEDURE [dbo].[PRL_CEKSERI_UPDATE] @CEKKARNEDETAYID INT, @CEKID INT, @CEKDURUMID INT
	as
	UPDATE CEKKARNEDETAY SET CEKID=@CEKID, CEKDURUMID=@CEKDURUMID WHERE CEKKARNEDETAYID=@CEKKARNEDETAYID
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKSERISEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_CEKSERISEC] @FIRMAID INT, @TUMU INT
AS
if @TUMU>0
	BEGIN
		SELECT CEKKARNEDETAYID, C.BANKAHESAPID,MUH_HESAP.KODU, MUH_HESAP.ACIKLAMA AS HESAPADI, C.BANKAID,MUH_BANKATANIM.BANKAADI, C.BANKASUBE, CD.CEKKARNESIID,CD.SERI,CD.CEKNO,CD.CEKDURUMID 
		FROM CEKKARNEDETAY AS CD LEFT JOIN CEKKARNESI AS C ON CD.CEKKARNESIID=C.CEKKARNESIID
		LEFT JOIN MUH_HESAP ON C.BANKAHESAPID=MUH_HESAP.HESAPID 
		LEFT JOIN MUH_BANKATANIM ON C.BANKAID=MUH_BANKATANIM.BANKAID
		WHERE ISNULL(CD.BANKAYAIADE,0)=0 AND ISNULL(C.SIL,0)=0 AND C.FIRMAID=@FIRMAID
	END
ELSE
	BEGIN
		SELECT CEKKARNEDETAYID,C.BANKAHESAPID,MUH_HESAP.KODU, MUH_HESAP.ACIKLAMA AS HESAPADI, C.BANKAID,MUH_BANKATANIM.BANKAADI, C.BANKASUBE, CD.CEKKARNESIID,CD.SERI,CD.CEKNO,CD.CEKDURUMID 
		FROM CEKKARNEDETAY AS CD LEFT JOIN CEKKARNESI AS C ON CD.CEKKARNESIID=C.CEKKARNESIID
		LEFT JOIN MUH_HESAP ON C.BANKAHESAPID=MUH_HESAP.HESAPID 
		LEFT JOIN MUH_BANKATANIM ON C.BANKAID=MUH_BANKATANIM.BANKAID
		WHERE ISNULL(CD.BANKAYAIADE,0)=0 AND ISNULL(C.SIL,0)=0 AND C.FIRMAID=@FIRMAID AND ISNULL(CD.CEKDURUMID,0)=0
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CEKTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CEKTUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_CEKTUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_CIFTENTEGRELER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CIFTENTEGRELER]
AS
SELECT TARIH,FISID,ACIKLAMA,DTOPLAM,ENTKAYNAK,ENTKAYNAKID,ADD_DATE FROM MUH_FIS WHERE ISNULL(SIL,0)=0 AND 
ENTKAYNAKID IN(SELECT ENTKAYNAKID FROM MUH_FIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=65 AND ENTKAYNAK='EMLAKSATIS' GROUP BY ENTKAYNAKID HAVING COUNT(ENTKAYNAKID)>1)
ORDER BY ENTKAYNAKID,ADD_DATE

GO
/****** Object:  StoredProcedure [dbo].[PRL_CONFIG]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_CONFIG]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM CONFIG WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DAIREHAREKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_DAIREHAREKET]   
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@OZELKODID NVARCHAR(20),
@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
		SET @SQLCUMLE='SELECT * FROM FNCQ_DAIREDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@OZELKODID+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPART]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPART]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPART WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPO]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPO WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_KOPYALA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOFIS_KOPYALA] @YENIDEPOFISID INT, @ESKIDEPOFISID INT
AS
INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,BARKOD,RENKID,BEDENID) 
SELECT @YENIDEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,BARKOD,RENKID,BEDENID FROM DEPOFISISL WHERE DEPOFISID=@ESKIDEPOFISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_SATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DEPOFIS_SATIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_SAYIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_DEPOFIS_SAYIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE ISLEM=''SAYIM'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_TRANSFER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DEPOFIS_TRANSFER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE ISLEM=''TRANSFER'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_TUKETIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DEPOFIS_TUKETIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE ISLEM=''TUKETIM'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIS_URETIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_DEPOFIS_URETIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFIS WITH (NOLOCK) WHERE ISLEM=''URETIM'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFISAKTAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_DEPOFISAKTAR]  
@TARIH SMALLDATETIME,
@CDEPOIDYIYECEK INT,
@CDEPOIDICECEK INT,
@CDEPOIDDIGER INT,
@SUBEID INT,
@FIRMAID INT,
@DEPKODU NVARCHAR(10)
AS
BEGIN
DECLARE
@GUID uniqueidentifier = NEWID(),
@DEPOFISID INT
DELETE FROM DEPOFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=@DEPKODU AND ISLEM='SATIS' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH)
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=@DEPKODU AND ISLEM='SATIS' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH
DELETE FROM DEPOFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=@DEPKODU AND ISLEM='ODENMEZ' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH)
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=@DEPKODU AND ISLEM='ODENMEZ' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH

if (SELECT ISNULL(COUNT(*),0) FROM ADSSATIR WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH))>0
	BEGIN
		
		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON  AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDYIYECEK>0
					BEGIN
						--YIYECEK SATISLAR

						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART) 
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDYIYECEK, @FIRMAID,@SUBEID, @SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDYIYECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK)  ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD  WITH (NOLOCK)INNER JOIN ADSSATIR AS ADS ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDICECEK>0
					BEGIN
						SET @GUID=NEWID()
						--ICECEK SATISLARI
				
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDICECEK, @FIRMAID,@SUBEID,@SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDDIGER>0 
					BEGIN
						SET @GUID=NEWID()
						--DIGER SATISLARI
						
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDDIGER, @FIRMAID,@SUBEID,@SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END
	END

if (SELECT ISNULL(COUNT(*),0) FROM ADSSATIR WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WITH (NOLOCK) WHERE TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH))>0
	BEGIN
		
		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD  WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDYIYECEK>0
					BEGIN
						SET @GUID=NEWID()
						--YIYECEK ODENMEZ
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDYIYECEK, @FIRMAID,@SUBEID, @SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDYIYECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
		
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDICECEK>0
					BEGIN
						SET @GUID=NEWID()
				
						--ICECEK ODENMEZ
						
						INSERT INTO DEPOFIS (DEPOFISID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART)
						SELECT @DEPOFISID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDICECEK,@FIRMAID,@SUBEID, @SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS  WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE  AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDDIGER>0
					BEGIN
						SET @GUID=NEWID()
						--DIGER ODENMEZ
						INSERT INTO DEPOFIS (DEPOFISID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,SDEPART)
						SELECT @DEPOFISID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDDIGER,@FIRMAID,@SUBEID, @SUBEID, @DEPKODU

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,ADET AS MIKTAR, S.BIRIM AS FBIRIM,ADET AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE  AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND  TUR='ODENMEZ' AND DEPKODU=@DEPKODU AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0

						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL  WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END

			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFISISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOFISISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPOFISISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIYATGUNCELLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_DEPOFIYATGUNCELLE] @STOKID INT
AS
BEGIN
	UPDATE SUBEFIYAT SET 
	SUBEFIYAT.SFIYAT1=STOK.SFIYAT1,
	SUBEFIYAT.SFIYAT2=STOK.SFIYAT2,
	SUBEFIYAT.SFIYAT3=STOK.SFIYAT3,
	SUBEFIYAT.SFIYAT4=STOK.SFIYAT4,
	SUBEFIYAT.SDOVIZ=STOK.SDOVIZ1,
	SUBEFIYAT.DOVIZ1=STOK.SDOVIZ1,
	SUBEFIYAT.DOVIZ2=STOK.SDOVIZ2,
	SUBEFIYAT.DOVIZ3=STOK.SDOVIZ3,
	SUBEFIYAT.DOVIZ4=STOK.SDOVIZ4,
	SUBEFIYAT.DOVIZ5=STOK.SDOVIZ5,
	SUBEFIYAT.KAYITDURUM=2
	FROM SUBEFIYAT INNER JOIN STOK ON SUBEFIYAT.STOKID=STOK.STOKID
	WHERE SUBEFIYAT.STOKID=@STOKID AND STOK.STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOFIYATGUNCELLE2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_DEPOFIYATGUNCELLE2] @STOKID INT, @FIRMAID INT
AS
BEGIN
IF (SELECT COUNT(*) FROM SUBEFIYAT WHERE STOKID=@STOKID)>0 
	BEGIN
		UPDATE SUBEFIYAT SET 
		SUBEFIYAT.SFIYAT1=STOK.SFIYAT1,
		SUBEFIYAT.SFIYAT2=STOK.SFIYAT2,
		SUBEFIYAT.SFIYAT3=STOK.SFIYAT3,
		SUBEFIYAT.SFIYAT4=STOK.SFIYAT4,
		SUBEFIYAT.SFIYAT5=STOK.SFIYAT5,
		SUBEFIYAT.SDOVIZ=STOK.SDOVIZ1,
		SUBEFIYAT.DOVIZ1=STOK.SDOVIZ1,
		SUBEFIYAT.DOVIZ2=STOK.SDOVIZ2,
		SUBEFIYAT.DOVIZ3=STOK.SDOVIZ3,
		SUBEFIYAT.DOVIZ4=STOK.SDOVIZ4,
		SUBEFIYAT.DOVIZ5=STOK.SDOVIZ5,
		SUBEFIYAT.KAYITDURUM=2
		FROM SUBEFIYAT INNER JOIN STOK ON SUBEFIYAT.STOKID=STOK.STOKID
		WHERE SUBEFIYAT.STOKID=@STOKID AND STOK.STOKID=@STOKID
	END
ELSE
	BEGIN
		INSERT INTO SUBEFIYAT (FIRMAID,SUBEID,DEPOID,STOKID,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SDOVIZ,DOVIZ1,DOVIZ2,DOVIZ3,DOVIZ4,DOVIZ5,KAYITDURUM)
		SELECT DEPO.FIRMAID,DEPO.SUBEID,DEPO.DEPOID,STOKID,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SDOVIZ1,SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,2 FROM DEPO,STOK
		WHERE STOKID=@STOKID AND DEPO.FIRMAID=@FIRMAID AND DEPO.SUBEFIYATKULLAN=1
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOTUSGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOTUSGRUP]  @FIRMAID INT, @DEPOID INT
AS
SET NOCOUNT ON
BEGIN
IF @DEPOID>0
	BEGIN
		SELECT TUSSUBE.FIRMAID,TUSSUBE.SUBEID,DEPOID,TSG.TUSGRUPID, TG.TUSGRUPADI,AKTIF 
		FROM TUSSUBE WITH (NOLOCK)  LEFT JOIN TUSSUBEGRUP AS TSG WITH (NOLOCK)  ON TUSSUBE.TUSSUBEID=TSG.TUSSUBEID 
		LEFT JOIN TUSGRUP AS TG WITH (NOLOCK) ON TSG.TUSGRUPID=TG.TUSGRUPID
		WHERE ISNULL(TUSSUBE.SIL,0)=0 AND TUSSUBE.FIRMAID=@FIRMAID AND TUSSUBE.DEPOID=@DEPOID ORDER BY TSG.SIRA
	END
ELSE
	BEGIN
		SELECT TG.FIRMAID,TG.SUBEID,-1 AS DEPOID,TG.TUSGRUPID, TG.TUSGRUPADI,AKTIF 
		FROM TUSGRUP AS TG WITH (NOLOCK) 
		WHERE ISNULL(TG.SIL,0)=0 AND TG.FIRMAID=@FIRMAID ORDER BY TG.SIRA
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOTUSSTOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOTUSSTOK]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT T.TUSSTOKID,TUSGRUPID,S.KKALDIR,S.PLUNO,S.BARKOD,S.GRUPID,T.STOKID,
S.ADI AS STOKADI,S.SFIYAT1 AS FIYAT,S.SFIYAT1,S.SFIYAT2,S.SFIYAT3,S.SFIYAT4,S.SFIYAT5,SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,
S.ETERAZI,AKTIF,SIRA,S.BIRIM,S.MALIYET,S.STOKRESIM,1 AS KATSAYI,SATISKDV,SFIYAT1KDV
FROM TUSSTOK AS T WITH (NOLOCK) LEFT OUTER JOIN STOK AS S WITH (NOLOCK) ON T.STOKID=S.STOKID
WHERE 1=1 '+@PARAMETRE+' order by SIRA'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOTUSSTOK_DEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPOTUSSTOK_DEPO]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT T.TUSSTOKID,TUSGRUPID,S.KKALDIR,S.PLUNO,S.BARKOD,S.GRUPID,T.STOKID,
S.ADI AS STOKADI,SUBEFIYAT.SFIYAT1 AS FIYAT,SUBEFIYAT.SFIYAT1,SUBEFIYAT.SFIYAT2,
SUBEFIYAT.SFIYAT3,SUBEFIYAT.SFIYAT4,SUBEFIYAT.SFIYAT5,SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,
S.ETERAZI,AKTIF,SIRA,S.BIRIM,S.MALIYET,S.STOKRESIM,1 AS KATSAYI,SATISKDV,SFIYAT1KDV
FROM TUSSTOK AS T WITH (NOLOCK) 
LEFT JOIN STOK AS S WITH (NOLOCK) ON T.STOKID=S.STOKID
INNER JOIN SUBEFIYAT ON S.STOKID=SUBEFIYAT.STOKID 
WHERE 1=1 '+@PARAMETRE+' order by T.SIRA'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPOTUSSTOK_TEST]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DEPOTUSSTOK_TEST]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TUSGRUPID,S.KKALDIR,S.PLUNO,S.BARKOD,S.GRUPID,T.STOKID,
S.ADI AS STOKADI,S.SFIYAT1 AS FIYAT,S.SFIYAT1,S.SFIYAT2,S.SFIYAT3,S.SFIYAT4,S.SFIYAT5,SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,
S.ETERAZI,AKTIF,SIRA,S.BIRIM,S.STOKRESIM,1 AS KATSAYI,SATISKDV
FROM TUSSTOK AS T LEFT JOIN STOK AS S ON T.STOKID=S.STOKID
WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DEPYAZICI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DEPYAZICI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DEPYAZICI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DINAMIKRAPOR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_DINAMIKRAPOR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DINAMIKRAPOR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DOLUMASALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DOLUMASALAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FISCOUNTER,FIRMAID,SUBEID,DEPKODU,DEPID,TARIH,(CASE WHEN CALLSIPARISID>0 THEN MASANO+'' ( PAKET) '' ELSE MASANO END) AS MASANO,ACIKLAMA,TUR,MUSTERIADI,MUSTERITELEFON,FADRESI1,FADRESI2,TOPLAM  
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DONEM_OLUSTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DONEM_OLUSTUR] @SOZLESMEID INT, @AY INT
AS
DELETE FROM SOZLESMEDETAY WHERE SOZLESMEID=@SOZLESMEID
DECLARE @SAYAC INT=0
	WHILE @SAYAC<=@AY-1
		BEGIN
			INSERT INTO SOZLESMEDETAY (SOZLESMEID,FTARIH,YIL,AY,YAZILIMBEDELI,DONANIMBEDELI,DIGERBEDELI,FTKESILDI,FATID,FTACIKLAMA)
			SELECT @SOZLESMEID, DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0, DATEADD(MONTH,+@SAYAC,ILKFTARIHI)) + 1, 0))  as FTARIHI, YEAR(ILKFTARIHI) AS YIL, MONTH(ILKFTARIHI) AS AY,
			YAZILIMBEDELI,DONANIMBEDELI,DIGERBEDEL,0,NULL,ACIKLAMA FROM SOZLESME WHERE SOZLESMEID=@SOZLESMEID
			SET @SAYAC=@SAYAC+1
		END
UPDATE SOZLESMEDETAY SET YIL=YEAR(FTARIH), AY=MONTH(FTARIH) WHERE SOZLESMEID=@SOZLESMEID


GO
/****** Object:  StoredProcedure [dbo].[PRL_DOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_DOVIZ]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DOVIZ WITH (NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_DOVIZISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_DOVIZISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM DOVIZISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EDEFTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EDEFTER] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @PARAMETRE NVARCHAR(700)
AS
BEGIN
DECLARE @SQL NVARCHAR(1500)
SET @SQL='SELECT H2.ISLEMID,H2.FISID,H2.YEVMNO,ISNULL(YEVMTARIH,TARIH) AS YEVMTARIH,H2.TFISACIKLAMA FISACIKLAMA,H2.FISNO,H2.SUBEID,H2.SUBEADI,  
   ANAHESAPKODU,MH.ACIKLAMA ANAHESAPADI,HESAPKODU,HESAPADI,H2.FISTOPLAM TBORC,H2.FISTOPLAM TALACAK,  
   (ISNULL(BORC,0)+ISNULL(ALACAK,0)) AS SATIRTUTAR ,H2.BORC,H2.ALACAK,H2.BATIPI,CAST(H2.SSIRA AS FLOAT) SIRANO,  
   FISNO AS SATIRFISNO,H2.ACIKLAMA SATIRACIKLAMA,ISNULL(GIBBELGETURUADI,'''') AS BELGETIPI,  
   CASE WHEN (GIBBELGETURUADI IS NULL) OR (GIBBELGETURUADI=''other'') THEN ''other'' ELSE GIBBELGETURUADI END AS BELGETURU,  
   CASE WHEN (GIBBELGETURUADI=''other'') THEN BELGEACIKLAMA ELSE NULL END BELGEACIKLAMA,  
   BELGENO, BELGETARIH,ODEMEYONTEMI,H2.EKLEYEN,  ISNULL(H2.ADD_DATE,TARIH) EKLEMETARIH,CAST(H2.YEVSATIRSIRANO AS FLOAT) YEVSATIRSIRANO FROM  
   FNCQ_QMUH_HESAPISLYEVMIYE ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''') as H2  
   INNER JOIN MUH_HESAP MH ON MH.KODU=H2.ANAHESAPKODU 
   WHERE MH.FIRMAID='+@FIRMAID+' AND 1=1 '+@PARAMETRE
EXEC(@SQL)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EDEVLETDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EDEVLETDURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_EDEVLETDURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EFATTUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_EFATTUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATURA_ESLESTIR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EFATURA_ESLESTIR] @FIRMAID INT, @FATID INT
AS
UPDATE FATURA SET FISUUID=NULL, IND1=0, IND2=0, IND3=0, EKORAN1=0, EKORAN2=0, 
EKORAN3=0, INDORAN1=0, INDORAN2=0, INDORAN3=0, EK1=0, EK2=0, EK3=0, OTV=0,
OIV=0, TINDEK=0, NTOPLAM=GTOPLAM,DNTOPLAM=0, IRSALIYE=0, 
YAZONAY=0, TEVKIFATTOPLAM=0, FARKFATURASI=0, BABSTUTAR=TOPLAM WHERE FATID=@FATID

UPDATE FATISL SET STOKID=ISNULL((SELECT TOP 1 STOKID FROM FATISL AS X 
WHERE FATFIRMAID=@FIRMAID AND LEN(ISNULL(X.ACIKLAMA,''))>4 AND X.STOKID>0 AND CHARINDEX(ISNULL(X.ACIKLAMA,''),ISNULL(FATISL.ACIKLAMA,''))>0  ORDER BY FATISLID DESC),-1),
FBIRIM=(SELECT TOP 1 ISNULL(FBIRIM,'Adet') FROM FATISL AS X
WHERE FATFIRMAID=@FIRMAID AND LEN(ISNULL(X.ACIKLAMA,''))>4 AND X.STOKID>0 AND CHARINDEX(ISNULL(X.ACIKLAMA,''),ISNULL(FATISL.ACIKLAMA,''))>0  ORDER BY FATISLID DESC),
KDV=ISNULL((SELECT TOP 1 KDV FROM FATISL AS X  
WHERE FATFIRMAID=@FIRMAID AND LEN(ISNULL(X.ACIKLAMA,''))>4 AND X.STOKID>0 AND CHARINDEX(ISNULL(X.ACIKLAMA,''),ISNULL(FATISL.ACIKLAMA,''))>0  ORDER BY FATISLID DESC),KDV)
WHERE ISNULL(ACIKLAMA,'')<>'' AND  FATID=@FATID
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATURA_FIRMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EFATURA_FIRMA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EFATURA_FIRMA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATURA_FIRMA_SEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EFATURA_FIRMA_SEC]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350), @TABLOADI NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM '+@TABLOADI+' WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATURA_ODEMESEKLI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EFATURA_ODEMESEKLI]
AS
SET NOCOUNT ON
BEGIN
SELECT * FROM EFATURA_ODEMESEKLI WITH (NOLOCK)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EFATURADURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EFATURADURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_EFATURADURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EGITIM_PLAN_SEC]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EGITIM_PLAN_SEC] @PARAMETRE NVARCHAR(100)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(600)
SET @PARAMETRE=REPLACE(@PARAMETRE,'SUBEID','I.SUBEID')
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','I.FIRMAID')
SET @PARAMETRE=REPLACE(@PARAMETRE,'DEPARTMANID','I.DEPARTMANID')
SET @SQLCUMLE='SELECT ID.IKEGITIMTANIMID,IE.EGITIMADI, I.IKEGITIMPLANID, DEPARTMANID,TARIH,ID.SURE,EGITIMVEREN,ID.ICDISEGITIM
FROM IKEGITIMPLAN_DETAY AS ID INNER JOIN IKEGITIMPLAN AS I ON ID.IKEGITIMPLANID=I.IKEGITIMPLANID
LEFT JOIN IKEGITIMTANIM AS IE ON ID.IKEGITIMTANIMID=IE.IKEGITIMTANIMID WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EGITIMANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EGITIMANALIZ]  @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_EGITIMANALIZ ('+@FIRMAID+') WHERE  1=1  '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EGITIMPLAN_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EGITIMPLAN_UPDATE] @EGITIMID INT, @TARIH SMALLDATETIME
AS
UPDATE IKEGITIMPLAN_DETAY SET EGITIMDURUMID=1 WHERE IKEGITIMTANIMID=@EGITIMID AND TARIH=@TARIH
GO
/****** Object:  StoredProcedure [dbo].[PRL_EKOZELLIK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EKOZELLIK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EKOZELLIK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EKRANLAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EKRANLAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EKRANLAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKDAIRE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EMLAKDAIRE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKDAIRE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKDOSYA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKDOSYA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKDOSYA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKDURUM_ISARETLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKDURUM_ISARETLE] @EMLAKSATISID INT, @FIRMAID INT, @DURUM NVARCHAR(20)
AS
DECLARE @DAIRE1 INT
DECLARE @DAIRE2 INT
DECLARE @DAIRE3 INT
SELECT @DAIRE1=DAIREID, @DAIRE2=DAIREID2, @DAIRE3=DAIREID3 FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID
UPDATE MUH_GRUP SET DURUM=@DURUM WHERE FIRMAID=@FIRMAID AND GRUPID IN(SELECT ISNULL(DAIREID,0) FROM EMLAKDAIRE WHERE EMLAKSATISID=@EMLAKSATISID)
IF @DAIRE1>0
	BEGIN
		UPDATE MUH_GRUP SET DURUM=@DURUM WHERE GRUPID=@DAIRE1 AND FIRMAID=@FIRMAID 
	END
IF @DAIRE2>0
	BEGIN
		UPDATE MUH_GRUP SET DURUM=@DURUM WHERE GRUPID=@DAIRE2 AND FIRMAID=@FIRMAID 
	END
IF @DAIRE3>0
	BEGIN
		UPDATE MUH_GRUP SET DURUM=@DURUM WHERE GRUPID=@DAIRE3 AND FIRMAID=@FIRMAID 
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKDURUM_RAPOR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKDURUM_RAPOR]  @DOVIZ NVARCHAR(5), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KOMHESABI NVARCHAR(20), @RAPORDOVIZI NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2950),
@DOVIZPARAM NVARCHAR(50)
SET @DOVIZPARAM=''
IF @DOVIZ<>'' SET @DOVIZPARAM='AND DOVIZ='''+@DOVIZ+''''
		IF @RAPORDOVIZI='HAYIR'
			BEGIN
				SET @SQLCUMLE='SELECT PROJEID, GRUPADI, SUM(LISTEFIYATI) AS LISTEFIYATI, SUM(INDIRIM) AS INDIRIM,
				SUM (NETFIYAT) AS NETFIYAT, SUM(KOMISYONTUTAR) AS KOMISYON,
				(SELECT SUM(DBORC) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE KODU='''+@KOMHESABI+''' AND Q.PROJEID=TBL.PROJEID AND 1=1 '+@DOVIZPARAM+') AS KOMODEMELERI,
				(SELECT SUM(DALACAK) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE  HESAPTIPID=120 AND Q.PROJEID=TBL.PROJEID  AND 1=1 '+@DOVIZPARAM+') AS TAHSILAT,
				(SELECT SUM(DBORC) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE  HESAPTIPID=120 AND Q.PROJEID=TBL.PROJEID  AND 1=1 '+@DOVIZPARAM+') AS ALICIBORC,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS TOPLAMDAIRE,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE DURUM=''SATILDI'' AND ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS SATILAN,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE ISNULL(DURUM,'''')<>''SATILDI'' AND ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS KALAN
				FROM (SELECT PROJEID, MUH_GRUP.GRUPADI, SUM(LISTEFIYATI) AS LISTEFIYATI,SUM(ISNULL(LISTEFIYATI,0))-(SELECT SUM(ISNULL(TUTAR,0)) AS NETFIYAT FROM EMLAKTAKSIT WHERE EMLAKTAKSIT.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID) AS INDIRIM, 
				(SELECT SUM(TUTAR) AS NETFIYAT FROM EMLAKTAKSIT WHERE EMLAKTAKSIT.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID) AS NETFIYAT,(SELECT SUM(KOMISYONTUTAR) AS KOMISYON FROM EMLAKSATISKOM WHERE EMLAKSATISKOM.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID)
				AS KOMISYONTUTAR  FROM EMLAKSATIS LEFT JOIN MUH_GRUP ON PROJEID=GRUPID 
				WHERE TARIH BETWEEN '''+@TARIH+''' AND '''+@TARIH2+''' AND EMLAKSATIS.FIRMAID='+@FIRMAID+' AND ISNULL(EMLAKSATIS.SIL,0)=0 AND 1=1 '+@DOVIZPARAM+' 
				GROUP BY PROJEID,GRUPADI,EMLAKSATISID) AS TBL WHERE 1=1 GROUP BY PROJEID,GRUPADI'
				EXEC(@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT PROJEID, GRUPADI, SUM(LISTEFIYATI) AS LISTEFIYATI, SUM(INDIRIM) AS INDIRIM,
				SUM (NETFIYAT) AS NETFIYAT, SUM(KOMISYONTUTAR) AS KOMISYON,
				(SELECT SUM(RBORC) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE KODU='''+@KOMHESABI+''' AND Q.PROJEID=TBL.PROJEID AND 1=1 '+@DOVIZPARAM+' ) AS KOMODEMELERI,
				(SELECT SUM(RALACAK) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE  HESAPTIPID=120 AND Q.PROJEID=TBL.PROJEID AND 1=1 '+@DOVIZPARAM+' ) AS TAHSILAT,
				(SELECT SUM(RBORC) AS TAHSILAT FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''')  AS Q WHERE  HESAPTIPID=120 AND Q.PROJEID=TBL.PROJEID AND 1=1 '+@DOVIZPARAM+' ) AS ALICIBORC,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS TOPLAMDAIRE,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE DURUM=''SATILDI'' AND ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS SATILAN,
				(SELECT COUNT(*) AS SAY FROM MUH_GRUP WHERE ISNULL(DURUM,'''')<>''SATILDI'' AND ISNULL(SIL,0)=0 AND MUH_GRUP.FIRMAID='+@FIRMAID+' AND MUH_GRUP.ANAGRUPID=TBL.PROJEID)
				AS KALAN
				FROM (SELECT PROJEID, MUH_GRUP.GRUPADI, SUM(LISTEFIYATI) AS LISTEFIYATI, SUM(ISNULL(LISTEFIYATI,0))-(SELECT SUM(ISNULL(TUTAR,0)) AS NETFIYAT FROM EMLAKTAKSIT WHERE EMLAKTAKSIT.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID) AS INDIRIM, 
				(SELECT SUM(TUTAR) AS NETFIYAT FROM EMLAKTAKSIT WHERE EMLAKTAKSIT.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID) AS NETFIYAT,(SELECT SUM(KOMISYONTUTAR) AS KOMISYON FROM EMLAKSATISKOM WHERE EMLAKSATISKOM.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID)
				AS KOMISYONTUTAR  FROM EMLAKSATIS LEFT JOIN MUH_GRUP ON PROJEID=GRUPID 
				WHERE TARIH BETWEEN '''+@TARIH+''' AND '''+@TARIH2+''' AND EMLAKSATIS.FIRMAID='+@FIRMAID+' AND ISNULL(EMLAKSATIS.SIL,0)=0 AND 1=1 '+@DOVIZPARAM+' 
				GROUP BY PROJEID,GRUPADI,EMLAKSATISID) AS TBL WHERE 1=1 GROUP BY PROJEID,GRUPADI'
				EXEC(@SQLCUMLE)
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKGORUSMELER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKGORUSMELER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKGORUSMELER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKKIRADOSYA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE  PROCEDURE [dbo].[PRL_EMLAKKIRADOSYA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKKIRADOSYA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKKIRALAMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[PRL_EMLAKKIRALAMA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKKIRALAMA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKKIRATAKSIT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[PRL_EMLAKKIRATAKSIT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKKIRATAKSIT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKKOMGOSTER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PRL_EMLAKKOMGOSTER]    @FIRMAID NVARCHAR(10), @MASMERADI NVARCHAR(20)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  * FROM FNCQ_EMLAKKOM  ('''+@FIRMAID+''','''+@MASMERADI+''')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKKOMGOSTER2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PRL_EMLAKKOMGOSTER2]    @FIRMAID NVARCHAR(10), @MASMERADI NVARCHAR(20), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  ALICIHESAPID, SUM(LISTEFIYATI) AS LISTEFIYATI, SUM(REELFIYAT) AS REELFIYAT, AVG(KOMISYONORAN) AS KOMORAN,
SUM(KOMISYONTUTAR) AS KOMISYONTUTAR, SUM(TAHSILEDILENKOM) AS TAHSILEDILENKOM, SUM(ODENENKOM) AS ODENENKOM, DOVIZ AS SATISDOVIZ 
FROM FNCQ_EMLAKKOM_DETAY  ('''+@FIRMAID+''','''+@MASMERADI+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY ALICIHESAPID,DOVIZ'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)

SET @PARAMETRE=REPLACE(@PARAMETRE,'ISNULL(SIL,0)','ISNULL(EMLAKSATIS.SIL,0)')
SET @PARAMETRE=REPLACE(@PARAMETRE,'PROJEADI','MG.GRUPADI')
SET @PARAMETRE=REPLACE(@PARAMETRE,'DAIREADI3','MG3.GRUPADI')
SET @PARAMETRE=REPLACE(@PARAMETRE,'DAIREADI2','MG2.GRUPADI')
SET @PARAMETRE=REPLACE(@PARAMETRE,'DAIREADI','MG1.GRUPADI')
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','EMLAKSATIS.FIRMAID')
SET @PARAMETRE=REPLACE(@PARAMETRE,'SUBEID','EMLAKSATIS.SUBEID')


SET @SQLCUMLE='SELECT TOP '+@LIMIT+' EMLAKSATIS.*, MG.GRUPADI AS PROJEADI, MG1.GRUPADI AS DAIREADI,
MG2.GRUPADI AS DAIREADI2, MG3.GRUPADI AS DAIREADI3
FROM EMLAKSATIS WITH (NOLOCK) LEFT JOIN MUH_GRUP AS MG WITH (NOLOCK) ON EMLAKSATIS.PROJEID=MG.GRUPID
LEFT JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON EMLAKSATIS.DAIREID=MG1.GRUPID 
LEFT JOIN MUH_GRUP AS MG2 WITH (NOLOCK) ON EMLAKSATIS.DAIREID2=MG2.GRUPID 
LEFT JOIN MUH_GRUP AS MG3 WITH (NOLOCK) ON EMLAKSATIS.DAIREID3=MG3.GRUPID 
WHERE 1=1 '+@PARAMETRE
--PRINT @SQLCUMLE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS_ANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS_ANALIZ] @FIRMAID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT '+' AS TUR,TARIH,NULL AS HESAPGRUBU, ISLEMGRUBU.GRUPADI AS ISLEMGRUBU, YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MG4.GRUPADI AS KAYNAK, SATICIADSOYAD,ALICIADSOYAD, MG.GRUPADI AS PROJE, MG1.GRUPADI AS DAIRE1, MG2.GRUPADI AS DAIRE2, MG3.GRUPADI AS DAIRE3, PROJEMAH, LISTEFIYATI,REELFIYAT,MUH_HESAP.ACIKLAMA AS KOMISYONHESABI, KOMISYONORAN,KOMISYONTUTAR,EMLAKSATIS.DOVIZ,TAKSITSAYISI,SONTAKSITVADE  
FROM EMLAKSATIS WITH (NOLOCK) LEFT JOIN MUH_GRUP AS MG WITH (NOLOCK) ON EMLAKSATIS.PROJEID=MG.GRUPID
LEFT JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON EMLAKSATIS.DAIREID=MG1.GRUPID
LEFT JOIN MUH_GRUP AS MG2 WITH (NOLOCK) ON EMLAKSATIS.DAIREID2=MG2.GRUPID
LEFT JOIN MUH_GRUP AS MG3 WITH (NOLOCK) ON EMLAKSATIS.DAIREID3=MG3.GRUPID
LEFT JOIN MUH_GRUP AS ISLEMGRUBU WITH (NOLOCK) ON EMLAKSATIS.ISLEMGRUPID1=ISLEMGRUBU.GRUPID
LEFT JOIN MUH_HESAP WITH (NOLOCK) ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID
LEFT JOIN MUH_GRUP AS MG4 WITH (NOLOCK) ON EMLAKSATIS.ISLEMGRUPID1=MG4.GRUPID
WHERE ISNULL(EMLAKSATIS.SIL,0)=0 AND EMLAKSATIS.FIRMAID=@FIRMAID AND EMLAKSATIS.TARIH BETWEEN @TARIH AND @TARIH2
UNION ALL
SELECT '-' AS TUR, TARIH,HESAPGRUBU.GRUPADI AS HESAPGRUBU,ISLEMGRUBU.GRUPADI AS ISLEMGRUBU,  YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, MG4.GRUPADI AS KAYNAK, SATICIADSOYAD,ALICIADSOYAD, MG.GRUPADI AS PROJE, MG1.GRUPADI AS DAIRE1, MG2.GRUPADI AS DAIRE2, MG3.GRUPADI AS DAIRE3, PROJEMAH, LISTEFIYATI,REELFIYAT,MUH_HESAP.ACIKLAMA AS KOMISYONHESABI, EMLAKSATISKOM.KOMISYONORAN,EMLAKSATISKOM.KOMISYONTUTAR*-1 AS KOMISYONTUTAR,EMLAKSATIS.DOVIZ,TAKSITSAYISI,SONTAKSITVADE  
FROM EMLAKSATISKOM WITH (NOLOCK) INNER JOIN EMLAKSATIS WITH (NOLOCK) ON EMLAKSATISKOM.EMLAKSATISID=EMLAKSATIS.EMLAKSATISID
LEFT JOIN MUH_GRUP AS MG WITH (NOLOCK) ON EMLAKSATIS.PROJEID=MG.GRUPID
LEFT JOIN MUH_GRUP AS MG1 WITH (NOLOCK) ON EMLAKSATIS.DAIREID=MG1.GRUPID
LEFT JOIN MUH_GRUP AS MG2 WITH (NOLOCK) ON EMLAKSATIS.DAIREID2=MG2.GRUPID
LEFT JOIN MUH_GRUP AS MG3 WITH (NOLOCK) ON EMLAKSATIS.DAIREID3=MG3.GRUPID
LEFT JOIN MUH_GRUP AS ISLEMGRUBU WITH (NOLOCK) ON EMLAKSATIS.ISLEMGRUPID1=ISLEMGRUBU.GRUPID
LEFT JOIN MUH_HESAP WITH (NOLOCK) ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID
LEFT JOIN MUH_GRUP AS HESAPGRUBU WITH (NOLOCK) ON MUH_HESAP.HESAPGRUPID1=HESAPGRUBU.GRUPID
LEFT JOIN MUH_GRUP AS MG4 WITH (NOLOCK) ON EMLAKSATIS.ISLEMGRUPID1=MG4.GRUPID
WHERE ISNULL(EMLAKSATIS.SIL,0)=0 AND  EMLAKSATIS.FIRMAID=@FIRMAID AND EMLAKSATIS.TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS_HESAPISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS_HESAPISL] @EMLAKSATISID INT
AS
IF (SELECT ISNULL(KOMDAHIL,0) FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID AND KOMDAHIL=1)>0
	BEGIN
		SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' AS ACIKLAMA, 0.00 AS BORC, 
		(CASE WHEN ISNULL(KOMDAHIL,0)=0 THEN ((LISTEFIYATI/100)*(100-KOMISYONORAN))*MBDOVIZSATIS ELSE LISTEFIYATI*MBDOVIZSATIS END) AS ALACAK, 0.00 AS DBORC, 
		(CASE WHEN ISNULL(KOMDAHIL,0)=0 THEN ((LISTEFIYATI/100)*(100-KOMISYONORAN)) ELSE LISTEFIYATI END) AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
		--İNŞAAT FIRMASI ALACAĞI
		UNION ALL
		--İNŞAAT FİRMASI HARİCİ KOMİSYON KISMINI BORCUNA YAZIYORUZ.
		SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS  AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
		UNION ALL
		--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
		SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' AS ACIKLAMA, TUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--EMLAK FIRMASININ KOMISYONU
		SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*MBDOVIZSATIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
		UNION ALL
		--EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI
		--SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		--FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		--LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		--WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		--UNION ALL
		--DİĞER KOMİSYONCULARIN ALACAĞI
		SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZSATIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--DİĞER KOMİSYONCULARIN GİDER AYAĞI
		SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
	END
ELSE
	BEGIN
		SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' AS ACIKLAMA, 0.00 AS BORC, 
		(CASE WHEN ISNULL(KOMDAHIL,0)=0 THEN ((LISTEFIYATI/100)*(100-KOMISYONORAN))*MBDOVIZSATIS ELSE LISTEFIYATI*MBDOVIZSATIS END) AS ALACAK, 0.00 AS DBORC, 
		(CASE WHEN ISNULL(KOMDAHIL,0)=0 THEN ((LISTEFIYATI/100)*(100-KOMISYONORAN)) ELSE LISTEFIYATI END) AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
		--İNŞAAT FIRMASI ALACAĞI
		UNION ALL
		--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
		SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' AS ACIKLAMA, TUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--EMLAK FIRMASININ KOMISYONU
		SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*MBDOVIZSATIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
		UNION ALL
		--EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI
		--SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		--FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		--LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		--WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		--UNION ALL
		--DİĞER KOMİSYONCULARIN ALACAĞI
		SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZSATIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--DİĞER KOMİSYONCULARIN GİDER AYAĞI
		SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
		WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
	END



GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS_HESAPISL2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS_HESAPISL2] @EMLAKSATISID INT, @KENDIMIZIN SMALLINT
AS
DECLARE @FIRMAID INT
DECLARE @SUBEID INT
DECLARE @MBDOVIZALIS FLOAT
DECLARE @TARIH SMALLDATETIME
DECLARE @DOVIZ NVARCHAR(5)
DECLARE @KURTIPI NVARCHAR(20)

IF (SELECT count(*) FROM EMLAKDAIRE WHERE EMLAKSATISID=@EMLAKSATISID)<=0
	BEGIN
		SELECT @FIRMAID=FIRMAID,@SUBEID=SUBEID,@TARIH=TARIH, @DOVIZ=DOVIZ FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID

		IF (SELECT count(*) FROM CONFIG  WHERE KEYNAME='Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID)<=0
		BEGIN
			INSERT INTO CONFIG (FIRMAID,SUBEID,PROGNAME,SECTIONSTR,KEYNAME,VALUESTR)
			VALUES(@FIRMAID,@SUBEID,'NOVABMS','Emlak','Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS','MBDOVIZALIS')
		END

		SELECT @KURTIPI=(SELECT TOP 1 ISNULL(VALUESTR,'MBDOVIZALIS') FROM CONFIG  WHERE KEYNAME='Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID) 

		IF @KURTIPI='DOVIZALIS' 
			BEGIN
				SELECT @MBDOVIZALIS=ISNULL((SELECT TOP 1 ISNULL(DOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ),(SELECT TOP 1 ISNULL(MAX(DOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DOVIZ))
			END
		IF @KURTIPI='DOVIZSATIS' 
			BEGIN
				SELECT @MBDOVIZALIS=ISNULL((SELECT TOP 1 ISNULL(DOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ),(SELECT TOP 1 ISNULL(MAX(DOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DOVIZ))
			END
		IF @KURTIPI='MBDOVIZALIS' 
			BEGIN
				SELECT @MBDOVIZALIS=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DOVIZ))
			END
		IF @KURTIPI='MBDOVIZSATIS' 
			BEGIN
				SELECT @MBDOVIZALIS=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DOVIZ))
			END

		IF @KENDIMIZIN=0
		BEGIN
		IF (SELECT ISNULL(KOMDAHIL,0) FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID AND KOMDAHIL=1)>0
			BEGIN
				/*İNŞAAT FIRMASI ALACAĞI */
				SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, (CAST (NULL AS INT)) AS MASMERID, (CAST (NULL AS INT)) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, REELFIYAT*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, REELFIYAT AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL

				/*İNŞAAT FİRMASI HARİCİ KOMİSYON KISMINI BORCUNA YAZIYORUZ. */
				SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, (CAST (NULL AS INT)) AS MASMERID,NULL AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*@MBDOVIZALIS  AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				WHERE   EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	

				UNION ALL
				/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
				SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, NULL AS MASMERID,  NULL AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
				WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				/*EMLAK FIRMASININ KOMISYONU */
				SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID,  MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
				WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
				UNION ALL
				/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
				/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
				/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
				/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
				/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

				/*UNION ALL */
				/*DİĞER KOMİSYONCULARIN ALACAĞI */
				SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID,  MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1,  EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
				WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
				SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
				WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
			END
		ELSE
			BEGIN
				IF (SELECT TOP 1 ISNULL(VALUESTR,'0') FROM CONFIG  WHERE KEYNAME='Komisyon Reel net Rakam üstünden hesaplansın 0  BRUT*0.85-REEL Hesaplansın' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID)='1' 
					BEGIN
						/*İNŞAAT FIRMASI ALACAĞI */
						SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, (CAST (NULL AS INT)) AS MASMERID,  (CAST (NULL AS INT)) AS ISLEMGRUPID1,  EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, ((LISTEFIYATI/100)*(100-KOMISYONORAN))*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((LISTEFIYATI/100)*(100-KOMISYONORAN)) AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	
						UNION ALL
						/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
						SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

						UNION ALL
						/*EMLAK FIRMASININ KOMISYONU */
						SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID,  MUH_HESAP.MASMERID,  MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID								
						WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
						UNION ALL
						/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
						/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
						/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
						/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
						/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

						/*UNION ALL */
						/*DİĞER KOMİSYONCULARIN ALACAĞI */
						SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID,  MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1,  EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
						LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID						
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

						UNION ALL
						/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
						SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
						INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
					END
				ELSE
					BEGIN
						/*İNŞAAT FIRMASI ALACAĞI */
						SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, ((REELFIYAT/100)*(100-KOMISYONORAN))*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((REELFIYAT/100)*(100-KOMISYONORAN)) AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	
						UNION ALL
						/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
						SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

						UNION ALL
						/*EMLAK FIRMASININ KOMISYONU */
						SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
						WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
						UNION ALL
						/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
						/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
						/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
						/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
						/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

						/*UNION ALL */
						/*DİĞER KOMİSYONCULARIN ALACAĞI */
						SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
						LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID						
						WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

						UNION ALL
						/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
						SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
						FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
						INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
						INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
						WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
					END
			END
		END
		ELSE IF @KENDIMIZIN=1
		BEGIN
			/*340 HESABIN ALACAĞI */
			SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID,  CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1,  EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, REELFIYAT*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, REELFIYAT AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
			SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
			WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*DİĞER KOMİSYONCULARIN ALACAĞI */
			SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5)) ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END)  AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
			LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID	
			WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
			SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, NULL AS MASMERID, NULL AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5))  ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
			INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
			WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
		END
	END
ELSE
	BEGIN
/*EMLAKDAIRE KISMI DOLU İSE 340 VE SATICI HESABINI HER DAİRE İÇİN ÇALIŞTIRMALIYIZ */
		UPDATE MUH_GRUP SET DURUM='SATILDI' WHERE FIRMAID=@FIRMAID AND GRUPID IN(SELECT ISNULL(DAIREID,0) FROM EMLAKDAIRE WHERE EMLAKSATISID=@EMLAKSATISID)
		SELECT @FIRMAID=FIRMAID,@SUBEID=SUBEID,@TARIH=TARIH, @DOVIZ=DOVIZ FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID

		IF (SELECT count(*) FROM CONFIG  WHERE KEYNAME='Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID)<=0
		BEGIN
			INSERT INTO CONFIG (FIRMAID,SUBEID,PROGNAME,SECTIONSTR,KEYNAME,VALUESTR)
			VALUES(@FIRMAID,@SUBEID,'NOVABMS','Emlak','Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS','MBDOVIZALIS')
		END

		SELECT @KURTIPI=(SELECT TOP 1 ISNULL(VALUESTR,'MBDOVIZALIS') FROM CONFIG  WHERE KEYNAME='Emlak Satış Sözleşmesi Kur Tipi DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID) 

		IF @KURTIPI='DOVIZALIS' 
			BEGIN
				SELECT @MBDOVIZALIS=(SELECT TOP 1 ISNULL(DOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ)
			END
		IF @KURTIPI='DOVIZSATIS' 
			BEGIN
				SELECT @MBDOVIZALIS=(SELECT TOP 1 ISNULL(DOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ)
			END
		IF @KURTIPI='MBDOVIZALIS' 
			BEGIN
				SELECT @MBDOVIZALIS=(SELECT TOP 1 ISNULL(MBDOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ)
			END
		IF @KURTIPI='MBDOVIZSATIS' 
			BEGIN
				SELECT @MBDOVIZALIS=(SELECT TOP 1 ISNULL(MBDOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ)
			END

		IF @KENDIMIZIN=0
		BEGIN
			IF (SELECT ISNULL(KOMDAHIL,0) FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID AND KOMDAHIL=1)>0
				BEGIN
					/*İNŞAAT FIRMASI ALACAĞI */
					SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,MULKSATICIHESAPID) AS HESAPID, ISNULL(EMLAKDAIRE.SATICIALTCARIID,MULKSATICIALTCARIID) AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' AS ACIKLAMA, 0.00 AS BORC, EMLAKDAIRE.REELFIYATI*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKDAIRE.REELFIYATI AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
					FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
					INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID
					WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

					UNION ALL

					/*İNŞAAT FİRMASI HARİCİ KOMİSYON KISMINI BORCUNA YAZIYORUZ. */
					SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,MULKSATICIHESAPID) AS HESAPID, ISNULL(EMLAKDAIRE.SATICIALTCARIID,MULKSATICIALTCARIID) AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKSATIS.PROJEID,EMLAKSATIS.DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' KOMISYON' AS ACIKLAMA, EMLAKSATIS.KOMISYONTUTAR*@MBDOVIZALIS  AS BORC, 0.00 AS ALACAK, EMLAKSATIS.KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
					FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
					INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID

					WHERE   EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	

					UNION ALL
					/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
					SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKTAKSIT.ACIKLAMA<>'' THEN EMLAKTAKSIT.ACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+'  SATISI' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
					FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
					INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
					WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

					UNION ALL
					/*EMLAK FIRMASININ KOMISYONU */
					SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKDAIRE.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKDAIRE.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKDAIRE.KOMISYONTUTAR AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
					FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
					INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
					LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
					WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
					UNION ALL
					/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
					/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
					/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
					/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
					/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

					/*UNION ALL */
					/*DİĞER KOMİSYONCULARIN ALACAĞI */
					SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
					FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
					INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
					LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID	
					WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

					UNION ALL
					/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
					SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
					FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
					INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
					INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
					WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
				END
			ELSE
				BEGIN
					IF (SELECT TOP 1 ISNULL(VALUESTR,'0') FROM CONFIG  WHERE KEYNAME='Komisyon Reel net Rakam üstünden hesaplansın 0  BRUT*0.85-REEL Hesaplansın' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID)='1' 
						BEGIN

							/*İNŞAAT FIRMASI ALACAĞI */
							SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,MULKSATICIHESAPID) AS HESAPID, ISNULL(EMLAKDAIRE.SATICIALTCARIID,MULKSATICIALTCARIID) AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' AS ACIKLAMA, 0.00 AS BORC, ((EMLAKDAIRE.LISTEFIYATI/100)*(100-EMLAKDAIRE.KOMISYONORAN))*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((EMLAKDAIRE.LISTEFIYATI/100)*(100-EMLAKDAIRE.KOMISYONORAN)) AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
							FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID 
							INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

							UNION ALL
							/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
							SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKTAKSIT.ACIKLAMA<>'' THEN EMLAKTAKSIT.ACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

							UNION ALL

							/*EMLAK FIRMASININ KOMISYONU */
							SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID,  MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(EMLAKDAIRE.REELFIYATI AS NVARCHAR(10))+' '+EMLAKDAIRE.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKDAIRE.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKDAIRE.KOMISYONTUTAR AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
							FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
							INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID
							LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
							WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
							UNION ALL
							/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
							/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
							/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
							/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
							/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

							/*UNION ALL */
							/*DİĞER KOMİSYONCULARIN ALACAĞI */
							SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID,  MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
							LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

							UNION ALL
							/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
							SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID,  CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
							INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
						END
					ELSE
						BEGIN
							/*İNŞAAT FIRMASI ALACAĞI */
							SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,MULKSATICIHESAPID) AS HESAPID, ISNULL(EMLAKDAIRE.SATICIALTCARIID,MULKSATICIALTCARIID) AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' AS ACIKLAMA, 0.00 AS BORC, ((EMLAKDAIRE.REELFIYATI/100)*(100-EMLAKDAIRE.KOMISYONORAN))*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((EMLAKDAIRE.REELFIYATI/100)*(100-EMLAKDAIRE.KOMISYONORAN)) AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
							FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
							INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID
							WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	
							UNION ALL
							/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
							SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKTAKSIT.ACIKLAMA<>'' THEN EMLAKTAKSIT.ACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+'  SATISI' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

							UNION ALL
							/*EMLAK FIRMASININ KOMISYONU */
							
							SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,EMLAKFIRMAHESAPID) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' AS ACIKLAMA, 0.00 AS BORC, EMLAKDAIRE.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKDAIRE.KOMISYONTUTAR AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
							FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
							INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID														
							LEFT JOIN MUH_HESAP ON EMLAKSATIS.EMLAKFIRMAHESAPID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
							WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
							UNION ALL
							/*EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI */
							/*SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS   */
							/*FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID */
							/*LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID */
							/*WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID */

							/*UNION ALL */
							/*DİĞER KOMİSYONCULARIN ALACAĞI */
							SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, MUH_HESAP.MASMERID,  MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS 
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
							LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
							WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

							UNION ALL
							/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
							SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
							FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
							INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
							INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
							WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
						END
				END
		END
		ELSE IF @KENDIMIZIN=1
		BEGIN
			/*340 HESABIN ALACAĞI */
			SELECT ISNULL(EMLAKDAIRE.SATICIHESAPID,MULKSATICIHESAPID) AS HESAPID, ISNULL(EMLAKDAIRE.SATICIALTCARIID,MULKSATICIALTCARIID) AS ALTCARIID, CAST(NULL AS INT) AS MASMERID,  CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, EMLAKDAIRE.PROJEID,EMLAKDAIRE.DAIREID, (CASE WHEN EMLAKDAIRE.DAIREACIKLAMA<>'' THEN EMLAKDAIRE.DAIREACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' END)  AS ACIKLAMA, 0.00 AS BORC, EMLAKDAIRE.REELFIYATI*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKDAIRE.REELFIYATI AS DALACAK,EMLAKDAIRE.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
			FROM EMLAKSATIS INNER JOIN EMLAKDAIRE ON EMLAKSATIS.EMLAKSATISID=EMLAKDAIRE.EMLAKSATISID
			INNER JOIN MUH_GRUP AS PROJE ON EMLAKDAIRE.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKDAIRE.DAIREID=OZELKOD.GRUPID
			WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU */
			SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKTAKSIT.ACIKLAMA<>'' THEN EMLAKTAKSIT.ACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' SATISI' END) AS ACIKLAMA, TUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS 
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
			WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*DİĞER KOMİSYONCULARIN ALACAĞI */
			SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID,  MUH_HESAP.MASMERID, MUH_HESAP.STDISLEMGRUBU1 AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5)) ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKSATIS.DOVIZ+' SATIS' END)  AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,EMLAKSATIS.DOVIZ,@MBDOVIZALIS  AS MBDOVIZSATIS
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
			LEFT JOIN MUH_HESAP ON EMLAKSATISKOM.KOMISYONCUID=MUH_HESAP.HESAPID AND MUH_HESAP.FIRMAID=@FIRMAID
			WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

			UNION ALL
			/*DİĞER KOMİSYONCULARIN GİDER AYAĞI */
			SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID,  CAST(NULL AS INT) AS MASMERID, CAST(NULL AS INT) AS ISLEMGRUPID1, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5))  ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*@MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,@MBDOVIZALIS AS MBDOVIZSATIS  
			FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
			INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
			INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
			WHERE  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
		END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS_HESAPISL2_YEDEK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS_HESAPISL2_YEDEK] @EMLAKSATISID INT, @KENDIMIZIN SMALLINT
AS
DECLARE @FIRMAID INT
DECLARE @SUBEID INT
DECLARE @MBDOVIZALIS FLOAT
DECLARE @TARIH SMALLDATETIME
DECLARE @DOVIZ NVARCHAR(5)
SELECT @FIRMAID=FIRMAID,@SUBEID=SUBEID,@TARIH=TARIH, @DOVIZ=DOVIZ FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID
SELECT @MBDOVIZALIS=(SELECT TOP 1 ISNULL(MBDOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DOVIZ)
IF @KENDIMIZIN=0
BEGIN
IF (SELECT ISNULL(KOMDAHIL,0) FROM EMLAKSATIS WHERE EMLAKSATISID=@EMLAKSATISID AND KOMDAHIL=1)>0
	BEGIN
		--İNŞAAT FIRMASI ALACAĞI
		SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, REELFIYAT*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, REELFIYAT AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		WHERE ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL

		--İNŞAAT FİRMASI HARİCİ KOMİSYON KISMINI BORCUNA YAZIYORUZ.
		SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZALIS  AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS  
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		WHERE   ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	

		UNION ALL
		--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
		SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
		WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--EMLAK FIRMASININ KOMISYONU
		SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS 
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		WHERE ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
		UNION ALL
		--EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI
		--SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
		--FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		--LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
		--WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		--UNION ALL
		--DİĞER KOMİSYONCULARIN ALACAĞI
		SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS 
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

		UNION ALL
		--DİĞER KOMİSYONCULARIN GİDER AYAĞI
		SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS
		FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
		LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
		INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
		INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
		WHERE   ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
	END
ELSE
	BEGIN
		IF (SELECT TOP 1 ISNULL(VALUESTR,'0') FROM CONFIG  WHERE KEYNAME='Komisyon Reel net Rakam üstünden hesaplansın 0  BRUT*0.85-REEL Hesaplansın' AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID)='1' 
			BEGIN
				--İNŞAAT FIRMASI ALACAĞI
				SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, ((LISTEFIYATI/100)*(100-KOMISYONORAN))*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((LISTEFIYATI/100)*(100-KOMISYONORAN)) AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS  
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				WHERE   ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	
				UNION ALL
				--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
				SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				--EMLAK FIRMASININ KOMISYONU
				SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
				UNION ALL
				--EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI
				--SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
				--FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				--LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
				--WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				--UNION ALL
				--DİĞER KOMİSYONCULARIN ALACAĞI
				SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				WHERE   ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				--DİĞER KOMİSYONCULARIN GİDER AYAĞI
				SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
			END
		ELSE
			BEGIN
				--İNŞAAT FIRMASI ALACAĞI
				SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, ((REELFIYAT/100)*(100-KOMISYONORAN))*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, ((REELFIYAT/100)*(100-KOMISYONORAN)) AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS  
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	
				UNION ALL
				--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
				SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				--EMLAK FIRMASININ KOMISYONU
				SELECT ISNULL(EMLAKFIRMAHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND  DOVIZISL.SUBEID=@SUBEID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID	
				UNION ALL
				--EMLAK FIRMASININ KOMISYONU SATICI BORÇ AYAĞI
				--SELECT MULKSATICIHESAPID AS HESAPID, EMLAKSATIS.TARIH AS VADE,PROJEID,DAIREID, PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' KOMISYON' AS ACIKLAMA, KOMISYONTUTAR*MBDOVIZSATIS AS BORC, 0.00 AS ALACAK, KOMISYONTUTAR AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZSATIS  
				--FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				--LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID
				--WHERE EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				--UNION ALL
				--DİĞER KOMİSYONCULARIN ALACAĞI
				SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS 
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

				UNION ALL
				--DİĞER KOMİSYONCULARIN GİDER AYAĞI
				SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS
				FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
				LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID 
				INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
				INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
				WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
			END
	END
END
ELSE IF @KENDIMIZIN=1
BEGIN
	--340 HESABIN ALACAĞI
	SELECT ISNULL(MULKSATICIHESAPID,-999) AS HESAPID, MULKSATICIALTCARIID AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, 0.00 AS BORC, REELFIYAT*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, REELFIYAT AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS 
	FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
	LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID 
	WHERE  ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	UNION ALL
	--ALICI / MÜŞTERİNİN TAKSITLERE GÖRE BORCU
	SELECT ISNULL(ALICIHESAPID,-999) AS HESAPID, ALICIALTCARIID AS ALTCARIID, EMLAKTAKSIT.TARIH AS VADE, PROJEID,DAIREID,(CASE WHEN EMLAKSATIS.TAKSITACIKLAMA<>'' THEN TAKSITACIKLAMA ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+EMLAKTAKSIT.DOVIZ+' SATIS' END) AS ACIKLAMA, TUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, TUTAR AS DBORC, 0.00 AS DALACAK,EMLAKTAKSIT.DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS 
	FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
	LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID
	INNER JOIN EMLAKTAKSIT ON EMLAKSATIS.EMLAKSATISID=EMLAKTAKSIT.EMLAKSATISID
	WHERE ISNULL(DOVIZISL.SIL,0)=0 AND EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	UNION ALL
	--DİĞER KOMİSYONCULARIN ALACAĞI
	SELECT ISNULL(KOMISYONCUID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE, PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5)) ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END)  AS ACIKLAMA, 0.00 AS BORC, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS ALACAK, 0.00 AS DBORC, EMLAKSATISKOM.KOMISYONTUTAR AS DALACAK,DOVIZ,MBDOVIZALIS  AS MBDOVIZSATIS
	FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
	LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID    
	INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
	WHERE ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID

	UNION ALL
	--DİĞER KOMİSYONCULARIN GİDER AYAĞI
	SELECT ISNULL(MUH_GRUP.KOMGIDERHESAPID,-999) AS HESAPID, NULL AS ALTCARIID, EMLAKSATIS.SONTAKSITVADE AS VADE,PROJEID,DAIREID, (CASE WHEN ISNULL(EMLAKSATISKOM.ACIKLAMA,'')<>'' THEN EMLAKSATISKOM.ACIKLAMA+' Komisyon %'+CAST(EMLAKSATISKOM.KOMISYONORAN AS NVARCHAR(5))  ELSE  PROJE.GRUPADI+' '+OZELKOD.GRUPADI+' '+CAST(REELFIYAT AS NVARCHAR(10))+' '+DOVIZ+' SATIS' END) AS ACIKLAMA, EMLAKSATISKOM.KOMISYONTUTAR*MBDOVIZALIS AS BORC, 0.00 AS ALACAK, EMLAKSATISKOM.KOMISYONTUTAR  AS DBORC, 0.00 AS DALACAK,DOVIZ,MBDOVIZALIS AS MBDOVIZSATIS  
	FROM EMLAKSATIS INNER JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID INNER JOIN MUH_GRUP AS OZELKOD ON EMLAKSATIS.DAIREID=OZELKOD.GRUPID
	LEFT JOIN DOVIZISL ON EMLAKSATIS.TARIH=DOVIZISL.TARIH AND EMLAKSATIS.DOVIZ=DOVIZISL.KODU AND EMLAKSATIS.FIRMAID=DOVIZISL.FIRMAID AND DOVIZISL.SUBEID=@SUBEID    
	INNER JOIN EMLAKSATISKOM ON EMLAKSATIS.EMLAKSATISID=EMLAKSATISKOM.EMLAKSATISID
	INNER JOIN MUH_GRUP ON EMLAKSATIS.PROJEID=MUH_GRUP.GRUPID
	WHERE   ISNULL(DOVIZISL.SIL,0)=0 AND  EMLAKSATIS.EMLAKSATISID=@EMLAKSATISID
END

GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATIS_IPTALFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_EMLAKSATIS_IPTALFIS] @FISID INT
AS
SELECT * FROM MUH_HESAPISL WHERE FISID=@FISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKSATISKOM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKSATISKOM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKSATISKOM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKTAKSIT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKTAKSIT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKTAKSIT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_EMLAKTIP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKTIP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_EMLAKTRANSFER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_EMLAKTRANSFER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM EMLAKTRANSFER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ENCOKSATAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ENCOKSATAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  TOP '+@LIMIT+' ADSSATIR.STOKID,STOK.ADI AS URUNADI, SUM(ADET) AS MIKTAR 
FROM ADISYON WITH (NOLOCK) INNER JOIN ADSSATIR WITH (NOLOCK) ON ADISYON.FISCOUNTER=ADSSATIR.FISCOUNTER
INNER JOIN STOK ON ADSSATIR.STOKID=STOK.STOKID
WHERE ISNULL(ADISYON.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY ADSSATIR.STOKID,STOK.ADI ORDER BY SUM(ADET) DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ENTEGRESQL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_ENTEGRESQL]  @SORGU NVARCHAR(MAX)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR 
(CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0) OR (CHARINDEX('DROP',@SORGU)>0) OR (CHARINDEX('NOVAUSER',@SORGU)>0) OR (CHARINDEX('NOVAUSERD',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE INSERT CREATE .. SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FARKHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FARKHESAPLA]  
@FIRMAID INT,
@SUBEID INT
AS
BEGIN
	UPDATE SAYIMFIS SET FARK=ISNULL(SAYIM,0)-ISNULL(KALAN,0) WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATAKTARIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATAKTARIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATAKTARIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATAKTARIM_FIRMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATAKTARIM_FIRMA] @FIRMAID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT FISHESAPID,CARIUNVAN FROM FATAKTARIM WHERE FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 GROUP BY FISHESAPID,CARIUNVAN
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATAKTARIM_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATAKTARIM_OZET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT GRUPID,STOKADI FROM FATAKTARIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE+' GROUP BY GRUPID,STOKADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATIRSALIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_FATIRSALIYE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATIRSALIYE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FATISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATISL_KOPYALA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATISL_KOPYALA] @YENIFATID INT, @KOPYAFATID INT
AS
INSERT INTO FATISL (FATID,STOKID,BARKOD,ACIKLAMA,HESAPID,ADET,BFIYAT,SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,SATIRINDT,FBIRIM,FADET,FBFIYAT,KDV,VADE,
ARATOPLAM,SILINDI,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,MASMERID,PROJEID,OZELKOD1,OZELKOD2,OZELKOD3,DFBFIYAT,DBFIYAT,DOVIZ,KUR,DTOPLAM,DOVIZKURU,
KDVTURU,TOPLAM,KDVLIFIYAT,BMALIYET,FBMALIYET,TEVKANUNACIKLAMA,TEVKANUNKODU,TEVORAN,OTV,OIV)
SELECT @YENIFATID,STOKID,BARKOD,ACIKLAMA,HESAPID,ADET,BFIYAT,SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,SATIRINDT,FBIRIM,FADET,FBFIYAT,KDV,VADE,
ARATOPLAM,SILINDI,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,MASMERID,PROJEID,OZELKOD1,OZELKOD2,OZELKOD3,DFBFIYAT,DBFIYAT,DOVIZ,KUR,DTOPLAM,DOVIZKURU,
KDVTURU,TOPLAM,KDVLIFIYAT,BMALIYET,FBMALIYET,TEVKANUNACIKLAMA,TEVKANUNKODU,TEVORAN,OTV,OIV FROM FATISL WHERE FATID=@KOPYAFATID
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATISLKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATISLKONTROL]  @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT COUNT(*) AS BAKIYE FROM FATISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATSTOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATSTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' STOKID,ADI,SFIYAT1,BIRIM,SFIYAT2,BIRIM2,SFIYAT3,BIRIM3,SDOVIZ1,SDOVIZ2,SDOVIZ3
 FROM STOK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE PROCEDURE [dbo].[PRL_FATURA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'FATID','FATURA.FATID')
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATURA.*,EFATNO,EFATTURU,EDEVLETDURUM,EFATURADURUM 
FROM FATURA WITH (NOLOCK) LEFT OUTER JOIN FATURADETAY WITH (NOLOCK) ON FATURA.FATID=FATURADETAY.FATID 
WHERE FISDURUMID IN(0,1,-2) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURA_ANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURA_ANALIZ] @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
DECLARE @SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT  ''01-Muhasebe'' as MODUL,TARIH,TURADI,CUNVANI AS UNVANI,convert(varchar, TARIH, 104)+'' : ''+CUNVANI AS UNVAN2, '''' AS ODEMESEKLI,VD,VDNO,EFATNO,FATNO,FATID,CARIID AS KNO, ACIKLAMA, ''00'' AS DEPT, '''' AS DEPADI, 
SGRUPADI AS GKODU, STOKADI AS GELIRGRUPADI,KDV,NTUTAR AS MATRAH, 
KDVTUTAR-TEVKDV AS KDVTUTARI,TEVORAN, TEVKDV,NTUTAR+(KDVTUTAR-TEVKDV) AS GTOPLAM  FROM [FNCQ_FATISL_ANALIZ] ('''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC(@SQLCUMLE)
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURA_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FATURA_DETAY]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT FT.BARKOD,S.ADI AS STOKADI, FBIRIM, SUM(FADET) AS MIKTAR, 
NULLIF(SUM(FADET*FBFIYAT),0)/NULLIF(SUM(FADET),0) AS FBFIYAT, SUM(FADET*FBFIYAT) AS TOPLAM 
FROM FATISL AS FT WITH (NOLOCK) INNER JOIN STOK AS S WITH (NOLOCK) ON FT.STOKID=S.STOKID INNER JOIN 
FATURA AS F ON FT.FATID=F.FATID WHERE 1=1 '+@PARAMETRE+'
GROUP BY FT.BARKOD,S.ADI,FBIRIM 
ORDER BY S.ADI '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURA_FATNO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURA_FATNO]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT FISHESAPID,FATID,FATNO FROM FATURA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURADAN_IRSALIYE_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURADAN_IRSALIYE_UPDATE] @FATID INT
AS
UPDATE IRSALIYE SET IRSALIYE.BFIYAT=FATISL.BFIYAT, IRSALIYE.FBFIYAT=FATISL.FBFIYAT, IRSALIYE.SATIRIND=FATISL.SATIRIND, IRSALIYE.ARATOPLAM=FATISL.ARATOPLAM,
IRSALIYE.SATIRIND2=FATISL.SATIRIND2, IRSALIYE.KDV=FATISL.KDV FROM FATISL AS IRSALIYE INNER JOIN FATISL ON IRSALIYE.IRSISLID=FATISL.FATID AND IRSALIYE.STOKID=FATISL.STOKID
WHERE ISNULL(IRSALIYE.FBFIYAT,0)=0 AND IRSALIYE.IRSISLID=@FATID
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURADETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_FATURADETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATURADETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURADVZ_TOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURADVZ_TOPLAM] @FATID INT
AS
SELECT FATID, DOVIZSATIR,ABS(SUM(TOPLAM)) TLTOPLAM, ABS(SUM(TOPLAM/100*(100+KDV))) AS KDVLITLTOPLAM, ABS(SUM(TOPLAM/KURSATIR)) AS DVZTOPLAM, 
ABS(SUM((TOPLAM/100*(100+KDV))/KURSATIR)) AS KDVLIDVZTOPLAM FROM [FNCQ_STOKISLON_EFATISL] (@FATID) GROUP BY FATID,DOVIZSATIR
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURAKDV]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURAKDV] @FATID NVARCHAR(10)
AS
SELECT FATID,KDV, SUM(NTUTAR) AS MATRAH, SUM(KDVTUTAR) AS KDVTUTAR FROM [FNCQ_FATISL] (@FATID) group by FATID,KDV
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURANOKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURANOKONTROL] @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(10), @FATURANO NVARCHAR(30)
AS
SELECT COUNT(*) AS SAY FROM FATURA WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND FISHESAPID=@HESAPID AND FATNO=@FATURANO
GO
/****** Object:  StoredProcedure [dbo].[PRL_FATURAVERGI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FATURAVERGI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATURAVERGI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FAVORIEKRAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FAVORIEKRAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FAVORIEKRAN WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FIRMABARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FIRMABARKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FIRMABARKOD WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FIRMAKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FIRMAKONTROL] 
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT MAX(ISNULL(KAYITTARIHI,''01.01.2000'')) AS SONTARIH FROM EFATURA_FIRMA'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FIRMALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FIRMALAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FIRMALAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FIRMAMODUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FIRMAMODUL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FIRMAMODUL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FIRMATASI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_FIRMATASI] @FIRMAID NVARCHAR(10)
AS
DECLARE @SQL NVARCHAR(4000)
DECLARE @SQL2 NVARCHAR(4000)
SET @SQL='
SELECT * INTO AKTARIMDB.DBO.SUBELER'+@FIRMAID+' FROM  SUBELER WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.MUH_FIS'+@FIRMAID+' FROM  MUH_FIS WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.MUH_HESAPISL'+@FIRMAID+' FROM  MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.MUH_HESAP'+@FIRMAID+' FROM  MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.MUH_HESAP_ALTCARI'+@FIRMAID+' FROM  MUH_HESAP_ALTCARI WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.MUH_GRUP'+@FIRMAID+''+@FIRMAID+' FROM  MUH_GRUP WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.FATURA'+@FIRMAID+' FROM  FATURA WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.FATISL'+@FIRMAID+' FROM  FATISL WHERE FATID IN(SELECT FATID FROM FATURA WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.TUKETIMFIS'+@FIRMAID+' FROM  TUKETIMFIS WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.TUKETIMFISISL'+@FIRMAID+' FROM TUKETIMFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.SATISODEME'+@FIRMAID+' FROM SATISODEME WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.ADISYON'+@FIRMAID+' FROM  ADISYON WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.ADSSATIR'+@FIRMAID+' FROM  ADSSATIR WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.ADSODEME'+@FIRMAID+' FROM  ADSODEME WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.STOK'+@FIRMAID+' FROM  STOK WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.SGRUP'+@FIRMAID+' FROM  SGRUP WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.DEPOFIS'+@FIRMAID+' FROM  DEPOFIS WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.DEPOFISISL'+@FIRMAID+' FROM  DEPOFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.CEKLER'+@FIRMAID+' FROM  CEKLER WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.CEKKARNESI'+@FIRMAID+' FROM  CEKKARNESI WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.CEKKARNEDETAY'+@FIRMAID+' FROM  CEKKARNEDETAY WHERE CEKKARNESIID IN(SELECT CEKKARNESIID FROM CEKKARNESI WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.SATISTEMSILCI'+@FIRMAID+' FROM  SATISTEMSILCI WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.EMLAKSATIS'+@FIRMAID+' FROM  EMLAKSATIS WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.EMLAKSATISKOM'+@FIRMAID+' FROM  EMLAKSATISKOM WHERE EMLAKSATISID IN(SELECT EMLAKSATISID FROM EMLAKSATIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.EMLAKTAKSIT'+@FIRMAID+' FROM  EMLAKTAKSIT WHERE EMLAKSATISID IN(SELECT EMLAKSATISID FROM EMLAKSATIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.EMLAKDAIRE'+@FIRMAID+' FROM  EMLAKDAIRE WHERE EMLAKSATISID IN(SELECT EMLAKSATISID FROM EMLAKSATIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.EMLAKDOSYA'+@FIRMAID+' FROM  EMLAKDOSYA WHERE EMLAKSATISID IN(SELECT EMLAKSATISID FROM EMLAKSATIS WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.NOVAUSER'+@FIRMAID+' FROM  NOVAUSER WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.NOVAUSERD'+@FIRMAID+' FROM  NOVAUSERD WHERE NOVAUSERID IN(SELECT NOVAUSERID FROM NOVAUSER WHERE FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.FIRMAMODUL'+@FIRMAID+' FROM  FIRMAMODUL WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.EKRANLAR'+@FIRMAID+' FROM  EKRANLAR 
SELECT * INTO AKTARIMDB.DBO.CONFIG'+@FIRMAID+' FROM  CONFIG WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.DEPO'+@FIRMAID+' FROM  DEPO WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.DEPART'+@FIRMAID+' FROM  DEPART WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.MASALAR'+@FIRMAID+' FROM  MASALAR WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.GARSON'+@FIRMAID+' FROM  GARSON WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.POSYAZICITIP'+@FIRMAID+' FROM  POSYAZICITIP WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.DEPYAZICI'+@FIRMAID+' FROM  DEPYAZICI WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.SBIRIM'+@FIRMAID+' FROM  SBIRIM WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.BARKOD'+@FIRMAID+' FROM  BARKOD WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.SAYIMFIS'+@FIRMAID+' FROM  SAYIMFIS WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.SAYIMFISARSIV'+@FIRMAID+' FROM  SAYIMFISARSIV WHERE FIRMAID='+@FIRMAID
SET @SQL2='
SELECT * INTO AKTARIMDB.DBO.MUHDONEM'+@FIRMAID+' FROM  MUHDONEM WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.RAPORLAR'+@FIRMAID+' FROM  RAPORLAR WHERE FIRMAID='+@FIRMAID+'
SELECT * INTO AKTARIMDB.DBO.USERGRID'+@FIRMAID+' FROM  USERGRID WHERE USERID IN(SELECT NOVAUSERID FROM NOVAUSER WHERE  FIRMAID='+@FIRMAID+')
SELECT * INTO AKTARIMDB.DBO.BELGELER'+@FIRMAID+' FROM  BELGELER WHERE FIRMAID='+@FIRMAID+'
UPDATE AKTARIMDB.DBO.MUH_FIS'+@FIRMAID+' SET VADE=NULL WHERE VADE<''2000-01-01''
UPDATE AKTARIMDB.DBO.RAPORLAR'+@FIRMAID+' SET SILME=NULL
UPDATE AKTARIMDB.DBO.MUH_HESAPISL'+@FIRMAID+' SET VADE=NULL WHERE VADE<''2000-01-01''
UPDATE AKTARIMDB.DBO.DEPOFIS'+@FIRMAID+' SET GERCEKTARIH=NULL WHERE GERCEKTARIH<''2000-01-01''
UPDATE AKTARIMDB.DBO.TUKETIMFIS'+@FIRMAID+' SET GERCEKTARIH=NULL WHERE GERCEKTARIH<''2000-01-01'''
EXEC(@SQL)
EXEC(@SQL2)



GO
/****** Object:  StoredProcedure [dbo].[PRL_FISDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_FISDURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISDURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISKONTROL] @FIRMAID INT,@FISID INT
AS
SELECT FISID,FISTURID,OZELKOD3 FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND FISID=@FISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISKURDUZELT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISKURDUZELT] @FIRMAID INT
AS
UPDATE MUH_HESAPISL SET BIRIMFIYAT=KUR WHERE TUTAR>0 AND DTUTAR>0 AND DOVIZ<>'TL' AND  ROUND(NULLIF(ISNULL(TUTAR,1),1)/NULLIF(ISNULL(DTUTAR,1),1),4)<>ROUND(KUR,4) AND 
FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)

UPDATE MUH_HESAPISL SET KUR=TUTAR/DTUTAR WHERE TUTAR>0 AND DTUTAR>0 AND DOVIZ<>'TL' AND  ROUND(NULLIF(ISNULL(TUTAR,1),1)/NULLIF(ISNULL(DTUTAR,1),1),4)<>ROUND(KUR,4) AND 
FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)

UPDATE MUH_FIS SET MUH_FIS.KUR=MUH_HESAPISL.KUR FROM MUH_FIS INNER JOIN MUH_HESAPISL ON MUH_FIS.FISID=MUH_HESAPISL.FISID WHERE MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.FISID IN(SELECT FISID FROM MUH_HESAPISL
WHERE BIRIMFIYAT>0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID))
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISNOVER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISNOVER]  @SUBEID NVARCHAR(50), @FISTURU NVARCHAR(150), @TARIH NVARCHAR(20)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT DBO.FNMUH_FISNO_VER('''+@SUBEID+''','''+@FISTURU+''','''+@TARIH+''') AS FISNO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISTUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISTUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISTUR_FATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISTUR_FATURA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTUR WITH (NOLOCK) WHERE FISTURID>=50 AND FISTURID<=64 AND  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISTUR_IRSALIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FISTUR_IRSALIYE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTURIRS WITH (NOLOCK) WHERE FISTURID>=50 AND FISTURID<=64 AND  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISTUR_MUSTAHSIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISTUR_MUSTAHSIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTUR WITH (NOLOCK) WHERE FISTURID=67 AND  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FISTUR_SMM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FISTUR_SMM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_FISTUR WITH (NOLOCK) WHERE FISTURID=66 AND  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FNCQ_MUHFIS_FISID]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FNCQ_MUHFIS_FISID]  @FISID NVARCHAR(10), @FIRMAID NVARCHAR(10)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_MUHFIS_FISID ('''+@FISID+''','''+@FIRMAID+''')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FTPBILGILERI_AKTIF]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FTPBILGILERI_AKTIF] @YUKLEMETURU SMALLINT
AS
SELECT FIRMAID,SUBEID,SUNUCU,KULLANICI,SIFRE,PORT,FTPKLASOR,INDIRMEKLASOR,TUMSISTEMICIN,YUKLEMETURU 
FROM FTPBILGI WHERE FIRMAID=1 and ISNULL(SIL,0)=0 AND YUKLEMETURU=@YUKLEMETURU
/*YUKLEMETURU=0 zipli =1 normal hali */
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_BUTCEANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FU_BUTCEANALIZ]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FU_BUTCEANALIZ WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_MUHGRUPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FU_MUHGRUPTIP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_MUHGRUPTIP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_PERBUTCEANALIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FU_PERBUTCEANALIZ]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FU_PERBUTCEANALIZ WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_RBGRUBU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FU_RBGRUBU]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_RBGRUBU WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_STOKTURU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_FU_STOKTURU]
AS
BEGIN
SELECT * FROM FU_STOKTURU
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_FU_UCHESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_FU_UCHESAP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FU_UCHESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GARSON]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_GARSON]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM GARSON WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GARSONSATIS_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_GARSONSATIS_MOBIL] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT GARSON.GADI, SUM(ADET) AS MIKTAR, SUM( (ADET*BIRIMFIYAT)/100*(100-ADISYON.INDORAN)) AS TOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
LEFT JOIN GARSON ON ADSSATIR.GARSONID=GARSON.GARSONID
WHERE   ISNULL(ADSSATIR.SIL,0)=0 AND ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GROUP BY GARSON.GADI ORDER BY GARSON.GADI
GO
/****** Object:  StoredProcedure [dbo].[PRL_GELIRGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_GELIRGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM GELIRGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GENELNOT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_GENELNOT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM GENELNOT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GRUPFIRMALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_GRUPFIRMALAR]  @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT FIRMAID,FIRMAKODU,UNVANI,GRUPFIRMAMI from FIRMALAR WITH (NOLOCK) WHERE ISNULL(GRUPFIRMAMI,0)=1 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GRUPFIRMALARIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_GRUPFIRMALARIM] @FIRMAID NVARCHAR(10)
AS
SELECT FIRMAID,FIRMAKODU,UNVANI FROM FIRMALAR WHERE GRUPFIRMAID IN (SELECT GRUPFIRMAID FROM FIRMALAR WHERE FIRMAID=@FIRMAID)
GO
/****** Object:  StoredProcedure [dbo].[PRL_GUNSONU]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_GUNSONU]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(450)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM GUNSONU WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GUNSONU_ODEMETAHSILAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_GUNSONU_ODEMETAHSILAT]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,UNVANI,ACIKLAMA, SUM(BORC) AS ODEMELER, SUM(ALACAK) AS TAHSILAT  FROM FNCQ_CARIISLEM ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY TARIH,UNVANI,ACIKLAMA'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GUNSONUOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_GUNSONUOZET]  @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(4000)
SET @SQLCUMLE='SELECT TARIH,''Adisyon Analiz'' as DURUM,''Satış'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''SATIS'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Ödenmez'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''ODENMEZ'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Personel'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''PERSONEL'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Diğer'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''DIGER'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Toplam Ciro'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Açık Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO NOT LIKE''Z%'' AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Adisyon Analiz'' as DURUM,''Kapalı Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO LIKE''Z%'' AND 1=1 '+@PARAMETRE+' GROUP BY TARIH
UNION ALL
SELECT TARIH,''Tahsilat Analiz'' as DURUM,ODEMETURU,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR 
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(ADISYON.SIL,0)=0  AND TUR=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID
UNION ALL
SELECT TARIH,''Kasa Analiz'' AS DURUM, ''Kasadan Ödemeler'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%ÖDEME%'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH
UNION ALL
SELECT TARIH,''Kasa Analiz'' AS DURUM, ''Kasaya Tahsilatlar'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%TAHSİLAT%'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_GUNSONUOZET_MOBIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_GUNSONUOZET_MOBIL]  @PARAMETRE NVARCHAR(400)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(3500)
SET @SQLCUMLE='SELECT ''Adisyon Analiz'' as DURUM,''Satış'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''SATIS'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Ödenmez'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''ODENMEZ'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Personel'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''PERSONEL'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Diğer'' AS ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE TUR=''DIGER'' AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Toplam Ciro'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Açık Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO NOT LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Adisyon Analiz'' as DURUM,''Kapalı Masa'' as ISLEM, SUM(TOPLAM/100*(100-ISNULL(INDORAN,0))) AS TOPLAM 
FROM ADISYON WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND MASANO LIKE''Z%'' AND 1=1 '+@PARAMETRE+'  
UNION ALL
SELECT ''Tahsilat Analiz'' as DURUM,ODEMETURU,SUM(TUTAR) AS TUTAR 
FROM  ADSODEME WITH (NOLOCK) INNER JOIN ADISYON WITH (NOLOCK) ON ADSODEME.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(ADISYON.SIL,0)=0  AND TUR=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY  ODEMETURU,ODEMETURID
UNION ALL
SELECT ''Kasa Analiz'' AS DURUM, ''Kasadan Ödemeler'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%ÖDEME%'' AND 1=1 '+@PARAMETRE+'
 
UNION ALL
SELECT ''Kasa Analiz'' AS DURUM, ''Kasaya Tahsilatlar'' AS ISLEM, SUM(TLTUTAR) AS TUTAR 
FROM KASAMUH AS ADISYON WITH (NOLOCK) WHERE ISLEMTURU LIKE''%TAHSİLAT%'' AND 1=1 '+@PARAMETRE+'
 '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAP_CARI_BUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAP_CARI_BUL] @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ''HESAPID'' AS TIP, HESAPID, 0 AS ALTCARIID FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+' AND KODU='''+@KODU+'''
UNION ALL
SELECT ''ALTCARIID'' AS TIP, HESAPID, ALTCARIID FROM MUH_HESAP_ALTCARI WHERE FIRMAID='+@FIRMAID+' AND KODU='''+@KODU+''''
EXEC(@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPANALIZ_PIVOT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPANALIZ_PIVOT] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPANALIZ_PIVOT2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_HESAPANALIZ_PIVOT2] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT2 ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPANALIZ_PIVOT3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HESAPANALIZ_PIVOT3] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3 ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPANALIZ_PIVOT4]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_HESAPANALIZ_PIVOT4] @TEMSILCILI NVARCHAR(5), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
IF @TEMSILCILI='EVET'
	BEGIN
		SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3 ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3_OZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
	END
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPANALIZ_PIVOT5]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPANALIZ_PIVOT5] @VADE NVARCHAR(5), @TEMSILCILI NVARCHAR(5), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(2000)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(4000)
IF @VADE='HAYIR'
	BEGIN
		IF @TEMSILCILI='EVET'
			BEGIN
				SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3 ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3_OZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
			END
	END
ELSE
	BEGIN
		IF @TEMSILCILI='EVET'
			BEGIN
				SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3_VADE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPANALIZ_PIVOT3_OZET_VADE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
			END
	END
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPBAKIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_HESAPBAKIYE]  @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT HESAPKODU, HESAPADI, SUM(BORC) AS TBORC, SUM(ALACAK) AS TALACAK, SUM(BORC)-SUM(ALACAK) AS BAKIYE,
 (CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN ''BORCLU'' WHEN SUM(BORC)-SUM(ALACAK)<0 THEN ''ALACAKLI'' ELSE '''' END) AS BA 
 FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
 GROUP BY HESAPKODU, HESAPADI
 ORDER BY HESAPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@KODU NVARCHAR(20),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' ORDER BY TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_DEVIRLI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_DEVIRLI]   @DEVIRLI INT, @DONEMBASI NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@KODU NVARCHAR(20),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		NULL,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM FNCQ_HESAPDETAY ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM FNCQ_HESAPDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_DEVIRLI2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_DEVIRLI2]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		NULL,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_DEVIRLI3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_DEVIRLI3]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@IDMI NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @IDMI='EVET'
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY_HESAPID'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
	END
ELSE
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
	END
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		NULL,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		ORDER BY TARIH'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_DOVIZOZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_DOVIZOZET]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@IDMI NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @IDMI='EVET'
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY_HESAPID'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
	END
ELSE
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
	END
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT DOVIZ, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK, SUM(DBORC)-SUM(DALACAK) AS DBAKIYE
		FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE ISNULL(DOVIZ,''TL'')<>''TL'' AND 1=1 '+@PARAMETRE+' 
		 GROUP BY DOVIZ 
		UNION ALL
		SELECT DOVIZ, SUM(BORC) AS DBORC, SUM(ALACAK) AS DALACAK, SUM(BORC)-SUM(ALACAK) AS DBAKIYE
		FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE ISNULL(DOVIZ,''TL'')=''TL'' AND 1=1 '+@PARAMETRE+' 
		GROUP BY DOVIZ  ORDER BY DOVIZ'
		EXEC(@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT DOVIZ, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,SUM(DBORC)-SUM(DALACAK) AS DBAKIYE 
		FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE ISNULL(DOVIZ,''TL'')<>''TL'' AND 1=1 '+@PARAMETRE+' 
		GROUP BY DOVIZ 
		UNION ALL
		SELECT DOVIZ, SUM(BORC) AS DBORC, SUM(ALACAK) AS DALACAK,SUM(BORC)-SUM(ALACAK) AS DBAKIYE 
		FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE ISNULL(DOVIZ,''TL'')=''TL'' AND 1=1 '+@PARAMETRE+' 
		GROUP BY DOVIZ ORDER BY DOVIZ'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_ORDER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_ORDER]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@IDMI NVARCHAR(5),
@ORDER NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @IDMI='EVET'
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY_HESAPID'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
	END
ELSE
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
	END
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		UNION ALL
		SELECT 0 AS FISID,NULL,NULL,NULL,0 AS ISLEMID,NULL,'''+@TARIHD+''' AS TARIH,NULL,NULL,NULL,''DEVIR'',NULL,
		NULL,NULL,''DEVIR'' AS BELGENO,NULL,NULL,NULL,SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL, 
		'''' AS DOVIZ,SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,''Önceki Dönem Devri'',NULL AS BELGEACIKLAMA,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		''DEVIR'' AS FISTURADI,1,SUBEID,SUBEKODU,SUBEADI,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
		NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIHD+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+'
		GROUP BY SUBEID,SUBEKODU,SUBEADI '   /*+@ORDER */
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT * FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' '+@ORDER
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPHAREKET_SUBEZOET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_HESAPHAREKET_SUBEZOET]   
@DEVIRLI INT, 
@DONEMBASI NVARCHAR(10), 
@TARIH NVARCHAR(10), 
@TARIH2 NVARCHAR(10), 
@FIRMAID NVARCHAR(10),
@KODU NVARCHAR(20),
@PARAMETRE NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@IDMI NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800),
@FONKSIYONADI NVARCHAR(30),
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10)
IF @IDMI='EVET'
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY_HESAPID'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA_HESAPID'
	END
ELSE
	BEGIN
		IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_HESAPDETAY'
		IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_HESAPDETAY_FATURA'
	END
IF @DEVIRLI=1
	BEGIN
		SET @TARIHX=CAST(@TARIH AS DATETIME)
		SET @TARIHX=@TARIHX-1
		SET @TARIHD=convert(varchar, @TARIHX, 23)

		SET @SQLCUMLE='SELECT SUBEID, SUBEKODU,SUBEADI, SUM(BORC) AS TBORC, SUM(ALACAK) AS TALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK, HESAPDOVIZ  
		FROM '+@FONKSIYONADI+' ('''+@DONEMBASI+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		 GROUP BY SUBEID, SUBEKODU,SUBEADI,HESAPDOVIZ ORDER BY SUBEKODU'
		EXEC(@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT SUBEID, SUBEKODU,SUBEADI, SUM(BORC) AS TBORC, SUM(ALACAK) AS TALACAK, SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK, HESAPDOVIZ 
		FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''') WHERE 1=1 '+@PARAMETRE+' 
		GROUP BY  SUBEID,SUBEKODU,SUBEADI,HESAPDOVIZ ORDER BY SUBEKODU'
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPISL_KOPYALA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPISL_KOPYALA] @YENIFISID INT, @KOPYAFISID INT
AS
INSERT INTO MUH_HESAPISL (FISID, HESAPID,FISUUID,ACIKLAMA,ACIKLAMA2,DOVIZ,KUR,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,MASMERID,PROJEID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,
OZELKOD1,OZELKOD2,OZELKOD3,BABSTUTAR,VADE,KAPANAN,BUTCEID,SILINDI,CEKID,KDV,BELGENO,BELGEACIKLAMA,BELGETARIH,TEVKIFATKODU,TEVKIFATYUZDE,KISISAYI,
BANKAID,BANKAEKSTREDETAYID,ALTCARIID,SSIRA,BELGETURU,ODEMEYONTEMI,GERCEKLESTIID,MIKTAR,BIRIM,BIRIMFIYAT,OZELKODID,CKARSIHESAPID)
SELECT  @YENIFISID, HESAPID,FISUUID,ACIKLAMA,ACIKLAMA2,DOVIZ,KUR,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,MASMERID,PROJEID,ISLEMGRUPID1,ISLEMGRUPID2,ISLEMGRUPID3,
OZELKOD1,OZELKOD2,OZELKOD3,BABSTUTAR,VADE,KAPANAN,BUTCEID,SILINDI,CEKID,KDV,BELGENO,BELGEACIKLAMA,BELGETARIH,TEVKIFATKODU,TEVKIFATYUZDE,KISISAYI,
BANKAID,BANKAEKSTREDETAYID,ALTCARIID,SSIRA,BELGETURU,ODEMEYONTEMI,GERCEKLESTIID,MIKTAR,BIRIM,BIRIMFIYAT,OZELKODID,CKARSIHESAPID FROM MUH_HESAPISL WHERE FISID=@KOPYAFISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPSTOKHAREKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPSTOKHAREKET]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@HESAPID NVARCHAR(10), @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,FATNO,CARIKODU,CARIUNVANI,FATID,STOKVADE,FISTIPI,DEPOKODU,DEPOADI,ISLEM,GRUPKODU,GRUPADI,BARKOD,STOKKODU,
STOKADI,KDVORAN,BIRIM,GCADET,FADET,FBIRIM,FBFIYAT,NFIYAT,BIRIMMALIYET,TOPLAMMALIYET FROM FNCQ_HESAPSTOKISLEMLER2 
('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','+@HESAPID+') WHERE 1=1 '+@PARAMETRE+' ORDER BY FATID,TARIH,SATIRKNO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESAPTIP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HESAPTIP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM QMUH_HESAPTIP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HESPLAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_HESPLAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HIZMET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HIZMET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK WITH (NOLOCK) WHERE TURU=''HIZMET'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HIZMETGRUP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_HIZMETGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SGRUP WITH (NOLOCK) WHERE GRUPTURU=''HIZMET'' and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSFIRMA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HSFIRMA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSFIRMA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSPAKET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HSPAKET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSPAKET WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSPAKETFIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_HSPAKETFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSPAKETFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSPAKETFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HSPAKETFIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSPAKETFIYAT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSPAKETSATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HSPAKETSATIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSPAKETSATIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_HSUSER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_HSUSER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM HSUSER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMDURUM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMDURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMDURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMKATILIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMKATILIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMKATILIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMKATILIM_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMKATILIM_DETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMKATILIM_DETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMPLAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMPLAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMPLAN WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMPLAN_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMPLAN_DETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMPLAN_DETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMTANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKEGITIMTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMTANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKEGITIMYER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKEGITIMYER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKEGITIMYER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKFAZLAMESAI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_IKFAZLAMESAI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKFAZLAMESAI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKFAZLAMESAI_DETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKFAZLAMESAI_DETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKFAZLAMESAI_DETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKFAZLAMESAITANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_IKFAZLAMESAITANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKFAZLAMESAITANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKMESAIKULLANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKMESAIKULLANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKMESAIKULLANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKMESAIMAIL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_IKMESAIMAIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKMESAIMAIL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKPERSONEL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKPERSONEL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKPERSONEL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKPERSONEL_EGITIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKPERSONEL_EGITIM]  @FIRMAID INT, @PSICILID INT
AS
BEGIN
SELECT TARIH, IKEGITIMTANIM.EGITIMADI, E.PSICILID, IKPERSONEL.AD,IKPERSONEL.SOYAD, E.IKEGITIMKATILIMID,E.DURUM,E.DURUMID FROM IKEGITIMKATILIM_DETAY AS E 
INNER JOIN IKEGITIMKATILIM AS K ON E.IKEGITIMKATILIMID=K.IKEGITIMKATILIMID
INNER JOIN IKPERSONEL ON E.PSICILID=IKPERSONEL.PSICILID INNER JOIN IKEGITIMTANIM ON K.IKEGITIMTANIMID=IKEGITIMTANIM.IKEGITIMTANIMID WHERE K.FIRMAID=@FIRMAID AND 
E.PSICILID=@PSICILID AND IKPERSONEL.FIRMAID=@FIRMAID  ORDER BY TARIH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKPERSONEL_TEMP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKPERSONEL_TEMP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKPERSONEL_TEMP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKPERSONEL_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_IKPERSONEL_UPDATE]  @FIRMAID INT
AS
BEGIN
	UPDATE IKPERSONEL_TEMP SET MAXMESAI=78, IKPERSONEL_TEMP.DEPARTMANID=PERDEPART.PERDEPARTMANID 
	FROM IKPERSONEL_TEMP INNER JOIN PERDEPART ON IKPERSONEL_TEMP.DEPKODU=PERDEPART.ELKDEPKODU
	WHERE PERDEPART.FIRMAID=@FIRMAID AND IKPERSONEL_TEMP.FIRMAID=@FIRMAID

	UPDATE IKPERSONEL_TEMP SET IKPERSONEL_TEMP.SUBEID=SUBELER.SUBEID FROM IKPERSONEL_TEMP INNER JOIN SUBELER ON IKPERSONEL_TEMP.FIRMA=SUBELER.IKSUBEID 
	WHERE SUBELER.FIRMAID=@FIRMAID AND IKPERSONEL_TEMP.FIRMAID=@FIRMAID

	INSERT INTO IKPERSONEL (FIRMAID,SUBEID,FIRMA,PSICILID,AD,SOYAD,ADSOYAD,ISEGIRIS,ISTENAYRILIS,UNVANID,DEPARTMANID,DEPKODU,CALISIYOR,GOREVI,TCKIMLIKNO)
	SELECT FIRMAID,SUBEID,FIRMA,PSICILID,AD,SOYAD,ADSOYAD,ISEGIRIS,ISTENAYRILIS,UNVANID,DEPARTMANID,DEPKODU,CALISIYOR,GOREVI,TCKIMLIKNO FROM IKPERSONEL_TEMP 
	WHERE FIRMAID=@FIRMAID AND PSICILID NOT IN(SELECT ISNULL(PSICILID,0) FROM IKPERSONEL WHERE FIRMAID=@FIRMAID)

	UPDATE IKPERSONEL SET IKPERSONEL.FIRMA=IKPERSONEL_TEMP.FIRMA, IKPERSONEL.AD=IKPERSONEL_TEMP.AD, IKPERSONEL.SOYAD=IKPERSONEL_TEMP.SOYAD,
	IKPERSONEL.ADSOYAD=IKPERSONEL_TEMP.ADSOYAD, IKPERSONEL.ISEGIRIS=IKPERSONEL_TEMP.ISEGIRIS, IKPERSONEL.ISTENAYRILIS=IKPERSONEL_TEMP.ISTENAYRILIS,
	IKPERSONEL.DEPARTMANID=IKPERSONEL_TEMP.DEPARTMANID, IKPERSONEL.DEPKODU=IKPERSONEL_TEMP.DEPKODU, IKPERSONEL.CALISIYOR=IKPERSONEL_TEMP.CALISIYOR,
	IKPERSONEL.GOREVI=IKPERSONEL_TEMP.GOREVI, IKPERSONEL.TCKIMLIKNO=IKPERSONEL_TEMP.TCKIMLIKNO FROM IKPERSONEL INNER JOIN IKPERSONEL_TEMP ON IKPERSONEL.PSICILID=IKPERSONEL_TEMP.PSICILID 
	WHERE IKPERSONEL.FIRMAID=@FIRMAID AND IKPERSONEL_TEMP.FIRMAID=@FIRMAID

	TRUNCATE TABLE IKPERSONEL_TEMP
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKVARDIYA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKVARDIYA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKVARDIYA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKVARDIYACOGALT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKVARDIYACOGALT] @IKVARDIYAID INT, @COGALTID INT
AS
INSERT INTO IKVARDIYADETAY (IKVARDIYAID,IKVARDIYATANIMID,PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7,CALISMAGUN,DIGERGUN,ISEGIRIS,ISTENAYRILIS)
SELECT @IKVARDIYAID,IKVARDIYATANIMID,PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7,CALISMAGUN,DIGERGUN,ISEGIRIS,ISTENAYRILIS FROM IKVARDIYADETAY WHERE IKVARDIYAID=@COGALTID
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKVARDIYACOGALT2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_IKVARDIYACOGALT2] @IKVARDIYAID INT, @COGALTID INT, @HAFTABASI NVARCHAR(10), @HAFTASONU NVARCHAR(10), 
@FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DEPARTMANID NVARCHAR(10)
AS
INSERT INTO IKVARDIYADETAY (IKVARDIYAID,IKVARDIYATANIMID,PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7,CALISMAGUN,DIGERGUN,ISEGIRIS,ISTENAYRILIS)
SELECT @IKVARDIYAID,IKVARDIYATANIMID,PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7,CALISMAGUN,DIGERGUN,ISEGIRIS,ISTENAYRILIS FROM IKVARDIYADETAY 
WHERE IKVARDIYAID=@COGALTID AND ISEGIRIS<=@HAFTABASI AND (ISTENAYRILIS IS NULL OR ISTENAYRILIS>@HAFTASONU)
UNION ALL
SELECT @IKVARDIYAID,NULL,PSICILID,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,ISEGIRIS,ISTENAYRILIS FROM IKPERSONEL WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID
        AND ISNULL(SIL,0)=0 AND ISNULL(CALISIYOR,1)=1 and DEPARTMANID=@DEPARTMANID
        and ISEGIRIS<=@HAFTABASI AND (ISTENAYRILIS IS NULL OR ISTENAYRILIS>@HAFTASONU) AND PSICILID NOT IN(SELECT PSICILID FROM IKVARDIYADETAY WHERE IKVARDIYAID=@COGALTID)


UPDATE IKVARDIYADETAY SET IKVARDIYADETAY.ISTENAYRILIS=IKPERSONEL.ISTENAYRILIS FROM IKVARDIYADETAY INNER JOIN IKPERSONEL ON IKVARDIYADETAY.PSICILID=
IKPERSONEL.PSICILID WHERE IKVARDIYADETAY.IKVARDIYAID=@IKVARDIYAID AND FIRMAID=@FIRMAID and SUBEID=@SUBEID
        AND IKPERSONEL.DEPARTMANID=@DEPARTMANID
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKVARDIYADETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IKVARDIYADETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKVARDIYADETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IKVARDIYATANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IKVARDIYATANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM IKVARDIYATANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_INDIRIMBUL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_INDIRIMBUL]  @TARIH DATETIME, @FIRMAID INT, @SUBEID INT, @DEPOID INT, @STOKID INT
AS
BEGIN
SELECT STOKINDIRIMDETAYID,ILKTARIH,SONTARIH,SD.STOKINDIRIMID,SD.STOKID,INDORAN,NETFIYAT FROM STOKINDIRIM AS S INNER JOIN STOKINDIRIMDETAY AS SD
ON S.STOKINDIRIMID=SD.STOKINDIRIMID WHERE ILKTARIH<=@TARIH AND SONTARIH>=@TARIH AND INDORAN>0 AND ISNULL(S.SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID
AND DEPOID=@DEPOID AND STOKID=@STOKID ORDER BY STOKINDIRIMDETAYID DESC
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IRSALIYE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_IRSALIYE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATURA.*,EFATNO,EFATTURU,EDEVLETDURUM,EFATURADURUM 
FROM FATURA WITH (NOLOCK) LEFT OUTER JOIN FATURADETAY WITH (NOLOCK) ON FATURA.FATID=FATURADETAY.FATID 
WHERE FISDURUMID=-1 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IRSALIYEDETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IRSALIYEDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATURADETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IRSISL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_IRSISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IRSISL_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_IRSISL_OZET]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(850)
SET @SQLCUMLE='SELECT BARKOD,STOKID, SUM(ADET) AS ADET, NULLIF(ISNULL(SUM(ADET*BFIYAT),0),0)/NULLIF(ISNULL(SUM(ADET),0),0) AS BFIYAT, 
AVG(SATIRIND) AS SATIRIND, AVG(SATIRIND2) AS SATIRIND2, FBIRIM, SUM(FADET) AS FADET, NULLIF(ISNULL(SUM(FADET*FBFIYAT),0),0)/NULLIF(ISNULL(SUM(FADET),0),0) AS FBFIYAT,KDV,
SUM(ARATOPLAM) AS ARATOPLAM, AVG(FBMALIYET) AS FBMALIYET,AVG(BKATSAYI) AS BKATSAYI,KDVDAHIL
FROM FATISL WHERE FATID IN('+@PARAMETRE+') GROUP BY BARKOD,STOKID,FBIRIM,KDV,KDVDAHIL'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_IRSISL_UPDATE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_IRSISL_UPDATE]  @FATID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='UPDATE FATISL SET IRSISLID='+@FATID+' WHERE FATID IN('+@PARAMETRE+')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KALANHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_KALANHESAPLA]  
@FIRMAID INT,
@SUBEID INT,
@BARKODAGORE NVARCHAR(5)
AS
BEGIN
IF @BARKODAGORE='HAYIR'
	BEGIN
			UPDATE SAYIMFIS SET ORTFIYAT=(SELECT SUM(GCADET*NFIYAT)/SUM(GCADET) FROM FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM WHERE QM.SUBEID=SAYIMFIS.SUBEID
			 AND QM.DEPOID=SAYIMFIS.DEPOID AND QM.STOKID=SAYIMFIS.STOKID AND QM.TARIH<=SAYIMFIS.TARIH AND GCADET>0), KALAN=(SELECT SUM(GCADET) FROM FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM WHERE QM.SUBEID=SAYIMFIS.SUBEID
			 AND QM.DEPOID=SAYIMFIS.DEPOID AND QM.STOKID=SAYIMFIS.STOKID AND QM.TARIH<=SAYIMFIS.TARIH) FROM SAYIMFIS
			INNER JOIN FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM ON QM.SUBEID=SAYIMFIS.SUBEID AND QM.DEPOID=SAYIMFIS.DEPOID WHERE SAYIMFIS.FIRMAID=@FIRMAID AND SAYIMFIS.SUBEID=@SUBEID
	END
ELSE
	BEGIN
			UPDATE SAYIMFIS SET KALAN=(SELECT SUM(GCADET) FROM FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM WHERE QM.SUBEID=SAYIMFIS.SUBEID
			 AND QM.DEPOID=SAYIMFIS.DEPOID AND QM.STOKID=SAYIMFIS.STOKID AND QM.RENKID=SAYIMFIS.RENKID AND QM.BEDENID=SAYIMFIS.BEDENID AND QM.TARIH<=SAYIMFIS.TARIH) FROM SAYIMFIS
			INNER JOIN FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM ON QM.SUBEID=SAYIMFIS.SUBEID AND QM.DEPOID=SAYIMFIS.DEPOID AND
			QM.STOKID=SAYIMFIS.STOKID  WHERE SAYIMFIS.FIRMAID=@FIRMAID  and SAYIMFIS.SUBEID=@SUBEID
	END

	UPDATE SAYIMFIS SET FARK=ISNULL(SAYIM,0)-ISNULL(KALAN,0), FARKTUTARI=(ISNULL(SAYIM,0)-ISNULL(KALAN,0))*ORTFIYAT  WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KALANHESAPLA_19042021]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_KALANHESAPLA_19042021]  
@FIRMAID INT,
@SUBEID INT,
@BARKODAGORE NVARCHAR(5)
AS
BEGIN
IF @BARKODAGORE='HAYIR'
	BEGIN
			UPDATE SAYIMFIS SET KALAN=(SELECT SUM(GCADET) FROM FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM WHERE QM.SUBEID=SAYIMFIS.SUBEID
			 AND QM.DEPOID=SAYIMFIS.DEPOID AND QM.STOKID=SAYIMFIS.STOKID AND QM.ISLEMTARIH<=SAYIMFIS.TARIH) FROM SAYIMFIS
			INNER JOIN FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM ON QM.SUBEID=SAYIMFIS.SUBEID AND QM.DEPOID=SAYIMFIS.DEPOID AND
			QM.STOKID=SAYIMFIS.STOKID WHERE SAYIMFIS.FIRMAID=@FIRMAID AND SAYIMFIS.SUBEID=@SUBEID
	END
ELSE
	BEGIN
			UPDATE SAYIMFIS SET KALAN=(SELECT SUM(GCADET) FROM FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM WHERE QM.SUBEID=SAYIMFIS.SUBEID
			 AND QM.DEPOID=SAYIMFIS.DEPOID AND QM.STOKID=SAYIMFIS.STOKID AND QM.BARKOD=SAYIMFIS.BARKOD AND QM.ISLEMTARIH<=SAYIMFIS.TARIH) FROM SAYIMFIS
			INNER JOIN FNCQ_STOKBAKIYE ('2000-01-01', '2030-01-01', @FIRMAID) AS QM ON QM.SUBEID=SAYIMFIS.SUBEID AND QM.DEPOID=SAYIMFIS.DEPOID AND
			QM.STOKID=SAYIMFIS.STOKID  WHERE SAYIMFIS.FIRMAID=@FIRMAID  and SAYIMFIS.SUBEID=@SUBEID
	END

	UPDATE SAYIMFIS SET FARK=ISNULL(SAYIM,0)-ISNULL(KALAN,0) WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KAPANISFISI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KAPANISFISI] (@FIRMAID INT,  @SUBEID INT,@TARIH NVARCHAR(10), @DONEMBASI NVARCHAR(10), @DONEMSONU NVARCHAR(10), @FISUUID uniqueidentifier,  
@EKLEYENID INT, @ALTCARIMI INT, @ACIKLAMA NVARCHAR(100)) 
AS
BEGIN
DECLARE @FISID INT
DECLARE @HATA INT
BEGIN TRANSACTION
		IF @ALTCARIMI=0
			BEGIN
				INSERT INTO MUH_FIS (FISUUID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, FIRMAID, SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
				VALUES (@FISUUID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Kapanış', 41, @ACIKLAMA,@FIRMAID,@SUBEID,'KAPANIS',0, @EKLEYENID,GETDATE(), 0, 1,'R')

				SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID

				INSERT INTO MUH_HESAPISL(FISID,HESAPID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
				SELECT @FISID,  HESAPID, @ACIKLAMA, ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))) AS TUTAR,CASE WHEN  DOVIZ='TL' THEN 0 ELSE ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))) END AS DTUTAR,   
				CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0   THEN 0 ELSE SUM(ISNULL(ALACAK,0))-SUM(ISNULL(BORC,0)) END AS BORC, 
				CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0 THEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)) ELSE 0 END AS ALACAK,   
				CASE WHEN SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0)) END AS DBORC, 
				CASE WHEN SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)) END AS DALACAK,   
				CASE WHEN ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))< 0.01 OR DOVIZ='TL' THEN 0 ELSE   
				ABS((SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))/(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))) END AS KUR,ISNULL(DOVIZ,'TL'),0  
				FROM FNCQ_QMUHMIZAN (@DONEMBASI, @DONEMSONU, @FIRMAID) AS QMUH_HESAPISL WHERE SUBEID=@SUBEID GROUP BY HESAPID,DOVIZ HAVING ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))>0.009


				UPDATE MUH_FIS SET FISTURID=48 WHERE FISID=@FISID
				UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID

			END
		ELSE IF @ALTCARIMI=1
			BEGIN
				INSERT INTO MUH_FIS (FISUUID, TARIH, FISNO, FISTURU, FISTURID, ACIKLAMA, FIRMAID,SUBEID, ENTKAYNAK,ENTKAYNAKID, ADD_USERID, ADD_DATE, PASIF, FISDURUMID,OZELKOD1) 
				VALUES (@FISUUID,@TARIH,(SELECT DBO.FNMUH_FISNO_VER(@SUBEID,'Mahsup',@TARIH) AS FISNO), 'Kapanış', 41, @ACIKLAMA,@FIRMAID,@SUBEID,'KAPANIS',0, @EKLEYENID,GETDATE(), 0, 1,'R')

				SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID

				INSERT INTO MUH_HESAPISL(FISID,HESAPID,ALTCARIID,ACIKLAMA,TUTAR,DTUTAR,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,BELGETURU)  
				SELECT @FISID,  HESAPID,ALTCARIID, @ACIKLAMA, ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))) AS TUTAR,CASE WHEN  DOVIZ='TL' THEN 0 ELSE ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))) END AS DTUTAR,   
				CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0   THEN 0 ELSE SUM(ISNULL(ALACAK,0))-SUM(ISNULL(BORC,0)) END AS BORC, 
				CASE WHEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0))>0 THEN SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)) ELSE 0 END AS ALACAK,   
				CASE WHEN SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0)) END AS DBORC, 
				CASE WHEN SUM(ISNULL(DALACAK,0))-SUM(ISNULL(DBORC,0))>0 OR DOVIZ='TL' THEN 0 ELSE SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)) END AS DALACAK,   
				CASE WHEN ABS(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))< 0.01 OR DOVIZ='TL' THEN 0 ELSE   ABS((SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))/(SUM(ISNULL(DBORC,0))-SUM(ISNULL(DALACAK,0)))) END AS KUR,
				ISNULL(DOVIZ,'TL'),0  FROM FNCQ_QMUHMIZAN (@DONEMBASI, @DONEMSONU, @FIRMAID) AS QMUH_HESAPISL WHERE SUBEID=@SUBEID GROUP BY HESAPID,ALTCARIID,DOVIZ HAVING ABS(SUM(ISNULL(BORC,0))-SUM(ISNULL(ALACAK,0)))>0.009

				UPDATE MUH_FIS SET FISTURID=48 WHERE FISID=@FISID
				UPDATE MUH_FIS SET TOPLAM = (SELECT SUM(HI.BORC ) FROM MUH_HESAPISL HI WHERE HI.FISID=MUH_FIS.FISID)  WHERE FISID = @FISID
				UPDATE MUH_HESAPISL SET ALTCARIID=NULL WHERE ALTCARIID=0 AND FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID)
			END
SET @HATA=@@ERROR
IF @HATA > 0 
	BEGIN
		ROLLBACK TRANSACTION
	END
ELSE
	BEGIN
		COMMIT TRANSACTION
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KASABANKA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_KASABANKA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' HESAPID,KODU,ACIKLAMA,HESAPTIPID,SIL 
FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND HESAPTIPID IN(100,102,108) AND 1=1'+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KASABANKA_ALTCARI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_KASABANKA_ALTCARI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' HESAPID,ALTCARIID,KODU,UNVANI,DOVIZ
FROM MUH_HESAP_ALTCARI WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1'+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KASAGIRISCIKIS_SATIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KASAGIRISCIKIS_SATIS] @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
DECLARE @SQL NVARCHAR(MAX)
SET @SQL='SELECT ''01-Nakit Satışlar'' AS ISLEM, ''Nakit'' AS ACIKLAMA, SUM(NAKIT) AS TUTAR FROM TUKETIMFIS WHERE ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+'
AND TARIH BETWEEN '''+@TARIH1+''' AND '''+@TARIH2+''' AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''02-Kredi Kartı Satışlar'' AS ISLEM, ''Kredi Kartı'' AS ACIKLAMA, SUM(KKARTI) AS TUTAR FROM TUKETIMFIS WHERE ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+' 
AND TARIH BETWEEN '''+@TARIH1+''' AND '''+@TARIH2+''' AND 1=1 '+@PARAMETRE+'
UNION ALL
SELECT ''03-Açık Hesap Satışlar'' AS ISLEM, FUNVANI AS ACIKLAMA, SUM(ACIK) AS TUTAR FROM TUKETIMFIS WHERE ABS(ACIK)>0 AND ISLEM=''SATIS'' AND  FIRMAID='+@FIRMAID+' 
AND TARIH BETWEEN '''+@TARIH1+''' AND '''+@TARIH2+''' AND 1=1 '+@PARAMETRE+' GROUP BY FUNVANI
UNION ALL
SELECT ''04-Tahsilatlar'' as ISLEM, KARSIHESAPADI+'' : ''+ACIKLAMA AS ACIKLAMA,BORC AS TUTAR 
FROM FNCQ_HESAPDETAY_SATIS ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''',''100'') WHERE FISTURADI LIKE''%Tahs%'' and BORC>0
UNION ALL 
SELECT ''05-Ödemeler'' AS ISLEM,KARSIHESAPADI+'' : ''+ACIKLAMA AS ACIKLAMA,ALACAK*-1 AS TUTAR 
FROM FNCQ_HESAPDETAY_SATIS ('''+@TARIH1+''','''+@TARIH2+''','''+@FIRMAID+''',''100'')  WHERE FISTURADI LIKE''%ödeme%'' and   ALACAK>0'
EXEC(@SQL)
GO
/****** Object:  StoredProcedure [dbo].[PRL_KASAMUH]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_KASAMUH]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KASAMUH WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KASATESLIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KASATESLIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KASATESLIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KDVMUAFTANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KDVMUAFTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KDVMUAFTANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KDVTANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KDVTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KDVTANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KDVTANIMTEVKIFAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KDVTANIMTEVKIFAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KDVTANIMTEVKIFAT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KREDI_KONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_KREDI_KONTROL] @BANKAKREDIID INT
AS
SELECT * FROM BANKAKREDIDETAY WITH (NOLOCK) WHERE MUHFISID>0 AND BANKAKREDIID=@BANKAKREDIID
GO
/****** Object:  StoredProcedure [dbo].[PRL_KREDI_TOPLAM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KREDI_TOPLAM] @BANKAKREDIID INT
AS
SELECT SUM(TAKSITTUTARI) AS TUTAR FROM BANKAKREDIDETAY WITH (NOLOCK) WHERE BANKAKREDIID=@BANKAKREDIID
GO
/****** Object:  StoredProcedure [dbo].[PRL_KREDIHESAPLA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KREDIHESAPLA] (@BANKAKREDIID INT,@KREDITARIHI SMALLDATETIME,@KREDITUTAR FLOAT,@TAKSITSAYISI INT,@FAIZORAN FLOAT,@KKDFORAN FLOAT,@BSMVORAN FLOAT) AS
BEGIN
DECLARE 
@TAKSITTUTAR FLOAT,
@ANAPARATUTAR FLOAT,
@FAIZTUTAR FLOAT,
@KKDFTUTAR FLOAT,
@BSMVTUTAR FLOAT,
@KALANANAPARA FLOAT,
@TAKSITTARIH SMALLDATETIME,
@FAIZTOPLAMORAN FLOAT,
@SAYAC INT																					
																							
SET @SAYAC=1
SET @FAIZTOPLAMORAN=(@FAIZORAN+(@FAIZORAN*@KKDFORAN)+(@FAIZORAN*@BSMVORAN))/100
while @SAYAC<@TAKSITSAYISI+1
	BEGIN
		 
		SET @TAKSITTUTAR =  @KREDITUTAR * (@FAIZTOPLAMORAN*POWER((1+@FAIZTOPLAMORAN),@TAKSITSAYISI))  / (POWER((1+@FAIZTOPLAMORAN),@TAKSITSAYISI)-1);
		IF @SAYAC=1 SET @FAIZTUTAR = (@KREDITUTAR *@FAIZORAN*1)/100
		IF @SAYAC=1 SET @KKDFTUTAR = (@FAIZTUTAR * @KKDFORAN)
		IF @SAYAC=1 SET @BSMVTUTAR = (@FAIZTUTAR * @BSMVORAN)
		IF @SAYAC=1 SET @ANAPARATUTAR = @TAKSITTUTAR-(@FAIZTUTAR+@KKDFTUTAR+@BSMVTUTAR)
		
		IF @SAYAC=1 SET @KALANANAPARA = @KREDITUTAR-@ANAPARATUTAR


		IF @SAYAC<>1 SET @FAIZTUTAR = (@KALANANAPARA *@FAIZORAN*1)/100
		IF @SAYAC<>1 SET @KKDFTUTAR = (@FAIZTUTAR * @KKDFORAN)
		IF @SAYAC<>1 SET @BSMVTUTAR = (@FAIZTUTAR * @BSMVORAN)
		IF @SAYAC<>1 SET @ANAPARATUTAR = @TAKSITTUTAR-(@FAIZTUTAR+@KKDFTUTAR+@BSMVTUTAR)
		
		IF @SAYAC<>1 SET @KALANANAPARA = @KALANANAPARA-@ANAPARATUTAR

		SET @TAKSITTARIH=DATEADD(MONTH,+@SAYAC,@KREDITARIHI)
		INSERT INTO BANKAKREDIDETAY (BANKAKREDIID,TAKSITNO, TARIH, TAKSITTUTARI,FAIZ,KKDF,BSMV,ANAPARA,KALANANAPARA) SELECT @BANKAKREDIID AS BANKAKREDIID,@SAYAC AS TAKSIT, @TAKSITTARIH AS TARIH, @TAKSITTUTAR AS TAKSITTUTAR, @FAIZTUTAR AS FAIZTUTAR, @KKDFTUTAR AS KKDFTUTAR, @BSMVTUTAR AS BSMVTUTAR, @ANAPARATUTAR AS ANAPARATUTRA, @KALANANAPARA AS KALANANAPARA

		SET @SAYAC = @SAYAC + 1
	END
--UPDATE BANKAKREDIDETAY SET TAKSITTUTARI=(SELECT @KREDITUTAR+SUM(FAIZ)+SUM(KKDF)+SUM(BSMV) FROM BANKAKREDIDETAY WHERE BANKAKREDIID=@BANKAKREDIID)/@TAKSITSAYISI WHERE BANKAKREDIID=@BANKAKREDIID		
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KREDITUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KREDITUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KREDITUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KULLANICI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KULLANICI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' SELECT NOVAUSERID, KODU,ADSOYAD,SIFRESI,
SUBEID,DEPOID,MASMERID,MOBILYETKISEVIYE,FIYATDEGISTIR FROM NOVAUSER  WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_KURDEGERLEME]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_KURDEGERLEME] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @TLBAKIYE NVARCHAR(5), 
@DVZBAKIYE NVARCHAR(5), @ALTCARI NVARCHAR(5), @MASMER NVARCHAR(5), @TUMSUBE NVARCHAR(5), @SUBEID NVARCHAR(10), @ILKKOD NVARCHAR(30), @SONKOD NVARCHAR(30),
@DOVIZ NVARCHAR(5), @DOVIZKURU FLOAT, @MASMERID nvarchar(10), @ISLEMGRUBU NVARCHAR(10), @OZELKODID NVARCHAR(5)
AS
IF ISNULL(@MASMERID,'')=''
	BEGIN
			IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='')  AND (@ALTCARI='') AND (@ISLEMGRUBU='')
				BEGIN
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI,NULL AS ISLEMGRUPID1, CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='') AND (@ISLEMGRUBU='')
				BEGIN
			/*TL BAKIYE VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='EVET') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='') AND (@ISLEMGRUBU='')
				BEGIN
			/*DVZ BAKIYE FİYATLAR */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)))>0.005)
				END
			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET') AND (@ISLEMGRUBU='')
				BEGIN
			/*ALT CARI BAZINDA TL BAKIYELI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)	
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET') AND (@ISLEMGRUBU='')
				BEGIN
			/*ALT CARI BAZINDA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='EVET') AND (@TUMSUBE='') AND (@ALTCARI='EVET')  AND (@ISLEMGRUBU='')
				BEGIN
			/*MASRAF MERKEZINE GÖRE ALTCARI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,MASMERADI,MASMERID, NULL AS OZELKODID 
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  ,MASMERADI,MASMERID 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )

				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='EVET') AND (@TUMSUBE='') AND (@ALTCARI='')  AND (@ISLEMGRUBU='')
				BEGIN
			/*MASRAF MERKEZINE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,MASMERADI,MASMERID, NULL AS OZELKODID 
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  ,MASMERADI,MASMERID 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END

			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@ISLEMGRUBU='EVET') AND (@OZELKODID='') AND (@TUMSUBE='') AND (@ALTCARI='EVET') AND (@MASMER='')
				BEGIN
			/*ISLEMGRUPID1  GÖRE ALTCARI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI  ,ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID 
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN,ISLEMGRUPID1
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )

				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@ISLEMGRUBU='EVET') AND (@OZELKODID='') AND (@TUMSUBE='') AND (@ALTCARI='') AND (@MASMER='')
				BEGIN
			/*ISLEMGRUPID1 GORE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID  
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ,ISLEMGRUPID1 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@ISLEMGRUBU='EVET') AND (@OZELKODID='EVET') AND (@TUMSUBE='') AND (@ALTCARI='') AND (@MASMER='')
				BEGIN
			/*ISLEMGRUPID1 VE OZELKODID GORE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, OZELKODID  
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ,ISLEMGRUPID1,OZELKODID 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END

			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*TÜM ŞUBELERE GÖRE ALTCARI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ,ALTCARIID,ALTCARIUNVAN  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END

			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*TÜM ŞUBELERE GÖRE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE  HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END


			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*TÜM ŞUBELERE GÖRE ALTCARI TL VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN AS ALTCARIUNVANI,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ,ALTCARIID,ALTCARIUNVAN   
			HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)
				END

			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*TÜM ŞUBELERE GÖRE TL VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE  HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL'
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)
				END
	END
ELSE
	BEGIN
			IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*TL BAKIYE VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50)) AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='EVET') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*DVZ BAKIYE FİYATLAR */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)))>0.005)
				END
			ELSE IF (@TLBAKIYE='EVET') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*ALT CARI BAZINDA TL BAKIYELI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 ) AND (ABS(SUM(BORC-ALACAK))>0.005)	
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*ALT CARI BAZINDA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='EVET') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*MASRAF MERKEZINE GÖRE ALTCARI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,ALTCARIID,ALTCARIUNVAN  ,NULL AS ISLEMGRUPID1,MASMERADI,MASMERID , NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ ,ALTCARIID,ALTCARIUNVAN  ,MASMERADI,MASMERID 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )

				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='EVET') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*MASRAF MERKEZINE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,MASMERADI,MASMERID, NULL AS OZELKODID 
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE SUBEID=@SUBEID AND HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  ,MASMERADI,MASMERID 
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*TÜM ŞUBELERE GÖRE ALTCARI */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END

			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*TÜM ŞUBELERE GÖRE  */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE  HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ  AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END


			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='EVET')
				BEGIN
			/*TÜM ŞUBELERE GÖRE ALTCARI TL VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END

			ELSE IF (@TLBAKIYE='') AND (@DVZBAKIYE='') AND (@MASMER='') AND (@TUMSUBE='') AND (@ALTCARI='')
				BEGIN
			/*TÜM ŞUBELERE GÖRE TL VARSA */
					SELECT HESAPID,HESAPKODU,HESAPADI,DOVIZ,SUBSTRING(HESAPKODU,1,3) AS ANAHESAP , SUM( BORC-ALACAK ) AS BAKIYE
					, SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS DBAKIYE
					, CAST(@DOVIZKURU AS FLOAT) as KUR ,CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) AS GUNCELTLBAKIYE
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) > SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) - SUM( BORC-ALACAK ),2) ELSE 0 END AS BORCB
					, CASE WHEN CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)) < SUM( BORC-ALACAK ) THEN DBO.FN_ROUNDBANKER( SUM( BORC-ALACAK ) - CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2)),2) ELSE 0 END AS ALACAKB
					 ,NULL AS ALTCARIID,CAST('' AS NVARCHAR(50))  AS ALTCARIUNVANI  ,NULL AS ISLEMGRUPID1,CAST('' AS NVARCHAR(50)) AS MASMERADI,NULL MASMERID, NULL AS OZELKODID
					 FROM FNCQ_QMUHMIZAN_FATURA (@TARIH, @TARIH2, @FIRMAID)  QMUH_HESAPISL
					 WHERE  HESAPKODU>=@ILKKOD AND HESAPKODU<=@SONKOD AND DOVIZ=@DOVIZ AND ISNULL(HESAPDOVIZ,'')<>'TL' AND MASMERID=@MASMERID
					 GROUP BY HESAPID,HESAPKODU, HESAPADI, DOVIZ  
					 HAVING (ABS(DBO.FN_ROUNDBANKER(SUM( BORC-ALACAK ) - (CAST(@DOVIZKURU AS FLOAT) * SUM(dbo.fn_roundbanker(DBORC,2)-dbo.fn_roundbanker(DALACAK,2))),2))>0.005 )
				END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKCARIKART]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKCARIKART]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' CARIID,KODU,HESAPID,KARTNO,FIRMAID,SUBEID,UNVANI,ADRES1,VD,VDNO,CEPTEL,KARTTURU,TIP,CGRUBU,STDIND FROM CARIKART WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKDEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LKDEPO]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' DEPOID,KODU,DEPOADI,ANADEPO,FIRMAID,SUBEID FROM DEPO WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKFATURADETAY]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKFATURADETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATID,EFATTURU,EFATURADURUM,EDEVLETDURUM FROM FATURADETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKMUH_HESAP]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKMUH_HESAP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,TEL1,GSM,SUBEID,HESAPID,KODU,ACIKLAMA, KODU+'' : ''+ACIKLAMA AS KODUADI, DOVIZ,UCHESAP,HESAPTIPID,UNVANI,ADRES1,ADRES2,VD,VDNO,
SEHIR,ILCE,PKODU,EMAIL,STDISLEMGRUBU1,ANLASMAOKU,VADEGUN,SORUNSEBEBI,KAMU,ALTCARIKULLANIR,SOZLESMESIVAR,
ISLEMGRUPID1ZORUNLU,OZELKODIDZORUNLU,PROJEZORUNLU,MMZORUNLU,ENG_HESAPADI,RUS_HESAPADI,STDISLEMGRUBU2,MASMERID
FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKMUH_HESAP_ALTCARI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_LKMUH_HESAP_ALTCARI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID,HESAPID,ALTCARIID,KODU,DOVIZ,VADEGUN,UNVANI,HESAPTIPID,ADRES1,ADRES2,VD,VDNO,SEHIR FROM MUH_HESAP_ALTCARI WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKMUH_HESAP2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKMUH_HESAP2]   @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT FIRMAID,SUBEID,HESAPID,KODU,ACIKLAMA,UNVANI,DOVIZ,UCHESAP,HESAPTIPID,
VD,VDNO,KAMU,ALTCARIKULLANIR,SOZLESMESIVAR,ISLEMGRUPID1ZORUNLU,OZELKODIDZORUNLU,PROJEZORUNLU,MMZORUNLU,
ENG_HESAPADI,RUS_HESAPADI,STDISLEMGRUBU1,STDISLEMGRUBU2,MASMERID
FROM MUH_HESAP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKSTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ISNULL(ALISKDV,SATISKDV) AS ALISKDV,SATISKDV,FATURABIRIMI,RECETEBIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,SURE,OIV,OTV,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,ETERAZI,PLUNO,POSTURU,TURU,SATISIND,INDVERILIR,MARKAID,URETICIID,GGRUP,AMIKTAR
FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_DEPO]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKSTOK_DEPO]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','STOK.FIRMAID')
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' STOK.FIRMAID,STOK.SUBEID, STOK.STOKID,GRUPID,ADI,BIRIM,SUBEFIYAT.SFIYAT1 AS FIYAT,
SUBEFIYAT.SFIYAT1,SUBEFIYAT.SFIYAT2,SUBEFIYAT.SFIYAT3,SUBEFIYAT.SFIYAT4,SUBEFIYAT.SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,ETERAZI,PLUNO,POSTURU,TURU,SATISIND,INDVERILIR
FROM SUBEFIYAT WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON SUBEFIYAT.STOKID=STOK.STOKID WHERE STOK.TURU=''Hammadde'' and ISNULL(STOK.SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_F]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LKSTOK_F]  @FIRMAID INT
AS
SELECT FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,ETERAZI,PLUNO,POSTURU,TURU,SATISIND,INDVERILIR
FROM STOK WITH (NOLOCK) WHERE TURU='Hammadde' and ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_FATURA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_LKSTOK_FATURA]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,RECETEBIRIMI,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SFIYAT1KDV,TURU FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_FATURA2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LKSTOK_FATURA2]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT STOKID,ADI,BIRIM,SFIYAT1,TURU FROM STOK WITH (NOLOCK) WHERE ISNULL(KKALDIR,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_FIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_LKSTOK_FIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, STOKID,SFIYAT1,STOKRESIM
FROM STOK WITH (NOLOCK) WHERE TURU=''Hammadde'' and ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_HFIYAT]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKSTOK_HFIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,ALISIND,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,ETERAZI,PLUNO,POSTURU,TURU,
SATISIND,INDVERILIR,ASGARI,OPTIMAL,AGIRLIK,KGFIYATI,MARKAID,URETICIID,STOKGRUPID,EDIT_DATE,EDIT_USERID,GGRUP,AMIKTAR
FROM STOK WITH (NOLOCK) WHERE TURU=''Hammadde'' and ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOK_TEST]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LKSTOK_TEST]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, STOKID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SALISFIYAT,
BARKOD,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SFIYAT1KDV
FROM STOK WITH (NOLOCK) WHERE TURU=''Hammadde'' and ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOKBARKOD]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKSTOKBARKOD]  
@FIRMAID INT
AS
BEGIN
	SELECT ISNULL(B.BARKOD,S.BARKOD) AS BARKOD, PLUNO, GRUPID, GRUPADI, S.STOKID AS STOKID, ISNULL(S.ETERAZI,0) AS ETERAZI, S.KODU AS SKODU, S.ADI AS STOKADI, 
	R.RENKADI AS RENK, BD.BEDEN AS BEDEN, S.ALISKDV, S.SATISKDV, S.SERILOTVAR, 
	ISNULL(B.BIRIM,S.BIRIM) AS BIRIM, ISNULL(S.FATURABIRIMI,S.BIRIM) AS FATURABIRIMI, 
	S.BIRIM AS ANABIRIM
	FROM STOK AS S WITH (NOLOCK) LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON S.STOKID=B.STOKID AND  B.FIRMAID=@FIRMAID  
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID 
	LEFT JOIN SGRUP WITH (NOLOCK) ON  S.GRUPID=SGRUP.SGRUPID
	WHERE  S.FIRMAID=@FIRMAID AND ISNULL(KKALDIR,0)=0 AND ISNULL(S.SIL,0)=0
	--AND ISNULL(S.DSATIS,0)=1
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSTOKURUN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKSTOKURUN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' STOKID,ADI,BIRIM,SFIYAT1,SALISFIYAT,
BARKOD,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,TURU 
FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKSUBELER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LKSUBELER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID,SUBEKODU,SUBEADI,YAZUNVANI,ADRES1,ADRES2,TEL,SUBEIL,SUBEILCE,TSICILNO,MERSISNO,SUBEVD,SUBEVDNO,
KILITTARIHI,SAYIMKILITTARIHI FROM SUBELER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LKURUN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LKURUN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' STOKID,GRUPID,HLISTE,KODU,BARKOD,ADI,BIRIM,SFIYAT1,SDOVIZ1,POSYAZICIID1,POSYAZICIID2 
FROM STOK WITH (NOLOCK) WHERE TURU=''Mamul'' and ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LOGEKLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LOGEKLE] @FIRMAID INT, @SUBEID INT, @TARIH SMALLDATETIME, @SAAT DATETIME, 
@KAYNAK NVARCHAR(30), @KULLANICIID INT, @ISLEM NVARCHAR(20), @ISLEMID INT, @ACIKLAMA NVARCHAR(150)
AS
BEGIN
INSERT INTO NOVALOG (FIRMAID,SUBEID,TARIH,SAAT,KAYNAK,KULLANICIID,ISLEM,ISLEMID,ACIKLAMA)
VALUES(@FIRMAID,@SUBEID,@TARIH,@SAAT,@KAYNAK,@KULLANICIID,@ISLEM,@ISLEMID,@ACIKLAMA)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LOGEKLE2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_LOGEKLE2] @FIRMAID INT, @SUBEID INT, @TARIH SMALLDATETIME, @SAAT DATETIME, 
@BILGISAYARADI NVARCHAR(30), @KAYNAK NVARCHAR(30), @KULLANICIID INT, @ISLEM NVARCHAR(20), @ISLEMID INT, @ACIKLAMA NVARCHAR(150)
AS
BEGIN
INSERT INTO NOVALOG (FIRMAID,SUBEID,TARIH,SAAT,BILGISAYARADI,KAYNAK,KULLANICIID,ISLEM,ISLEMID,ACIKLAMA)
VALUES(@FIRMAID,@SUBEID,@TARIH,@SAAT,@BILGISAYARADI,@KAYNAK,@KULLANICIID,@ISLEM,@ISLEMID,@ACIKLAMA)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_LOGEKLE3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_LOGEKLE3] @FIRMAID INT, @SUBEID INT, @TARIH SMALLDATETIME, @SAAT DATETIME, 
@BILGISAYARADI NVARCHAR(30), @KAYNAK NVARCHAR(30), @KULLANICIID INT, @ISLEM NVARCHAR(20), @ISLEMID INT, @ACIKLAMA NVARCHAR(800), @MACADRES NVARCHAR(20), @IPADRES NVARCHAR(20)
AS
BEGIN
INSERT INTO NOVALOG (FIRMAID,SUBEID,TARIH,SAAT,BILGISAYARADI,KAYNAK,KULLANICIID,ISLEM,ISLEMID,ACIKLAMA,MACADRES,IPADRES)
VALUES(@FIRMAID,@SUBEID,@TARIH,@SAAT,@BILGISAYARADI,@KAYNAK,@KULLANICIID,@ISLEM,@ISLEMID,@ACIKLAMA,@MACADRES,@IPADRES)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKASADOVIZ]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETKASADOVIZ]  @PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,ODEMETURU,ODEMETURID,SUM(TUTAR*ISNULL(KUR,1)) AS TUTAR, SUM(TUTAR) AS DVZTUTAR, ISNULL(SATISODEME.DOVIZ,''TL'') AS DOVIZ  
FROM  SATISODEME WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON SATISODEME.DEPOFISID=TUKETIMFIS.DEPOFISID
WHERE ISNULL(SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,ODEMETURU,ODEMETURID,SATISODEME.DOVIZ
ORDER BY ODEMETURID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKASAISLE]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETKASAISLE] @TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DETAYLI NVARCHAR(5)
AS
IF @DETAYLI='EVET'
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH,YETKILI
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,TUTAR,DOVIZ,KUR,TLTUTAR)
				SELECT TARIH,YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0 FROM 
				TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH,YETKILI
			END
	END
ELSE
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				SELECT TARIH,'GENEL' AS YETKILI, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,TUTAR,DOVIZ,KUR,TLTUTAR)
				SELECT TARIH,'GENEL' AS YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0 FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKASAISLE2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETKASAISLE2] @TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DETAYLI NVARCHAR(5)
AS
IF @DETAYLI='EVET'
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				UPDATE KASATESLIM SET NAKITT=NAKIT, KKARTIT=KKARTI, ACIKHESAP=ACIK, TUTAR=TOPLAM FROM KASATESLIM INNER JOIN  (SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, 
				SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS
				WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH GROUP BY TARIH,YETKILI) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.YETKILI
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, ADSOYAD, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, NOVAUSER.ADSOYAD, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS INNER JOIN NOVAUSER  ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,NOVAUSER.ADSOYAD,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH, ADSOYAD) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.ADSOYAD
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH,YETKILI
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,NAKITT,KKARTIT,ACIKHESAP,TUTAR,DOVIZ,KUR,NAKITA,KKARTIA,TLTUTAR)
				SELECT TARIH,YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0,0,0 FROM 
				TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH,YETKILI

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, ADSOYAD, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, NOVAUSER.ADSOYAD, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS INNER JOIN NOVAUSER  ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,NOVAUSER.ADSOYAD,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH, ADSOYAD) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.ADSOYAD
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
			END
	END
ELSE
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				UPDATE KASATESLIM SET NAKITT=NAKIT, KKARTIT=KKARTI, ACIKHESAP=ACIK, TUTAR=TOPLAM FROM KASATESLIM INNER JOIN  (SELECT TARIH,'GENEL' AS YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, 
				SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,  SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH


				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS  WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				SELECT TARIH,'GENEL' AS YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,NAKITT,KKARTIT,ACIKHESAP,TUTAR,DOVIZ,KUR,NAKITA,KKARTIA,TLTUTAR)
				SELECT TARIH,'GENEL' AS YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0,0,0 FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS  WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKASAISLE3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETKASAISLE3] @TARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DETAYLI NVARCHAR(5), @RESMI BIT
AS
IF @DETAYLI='EVET'
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				IF @RESMI=0
					BEGIN
						UPDATE KASATESLIM SET NAKITT=NAKIT, KKARTIT=KKARTI, ACIKHESAP=ACIK, TUTAR=TOPLAM FROM KASATESLIM INNER JOIN  (SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, 
						SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS
						WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH GROUP BY TARIH,YETKILI) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.YETKILI
						WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
					END
				ELSE
					BEGIN
						UPDATE KASATESLIM SET NAKITT=NAKIT, KKARTIT=KKARTI, ACIKHESAP=ACIK, TUTAR=TOPLAM FROM KASATESLIM INNER JOIN  (SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, 
						SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS
						WHERE OKCFISNO<>'' and ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH GROUP BY TARIH,YETKILI) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.YETKILI
						WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
					END

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, ADSOYAD, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, NOVAUSER.ADSOYAD, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS INNER JOIN NOVAUSER  ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,NOVAUSER.ADSOYAD,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH, ADSOYAD) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.ADSOYAD
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				SELECT TARIH,YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH,YETKILI
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				IF @RESMI=0
					BEGIN
						INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,NAKITT,KKARTIT,ACIKHESAP,TUTAR,DOVIZ,KUR,NAKITA,KKARTIA,TLTUTAR)
						SELECT TARIH,YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0,0,0 FROM 
						TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
						GROUP BY TARIH,YETKILI
					END
				ELSE
					BEGIN
						INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,NAKITT,KKARTIT,ACIKHESAP,TUTAR,DOVIZ,KUR,NAKITA,KKARTIA,TLTUTAR)
						SELECT TARIH,YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0,0,0 FROM 
						TUKETIMFIS WHERE OKCFISNO<>'' AND ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
						GROUP BY TARIH,YETKILI
					END

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, ADSOYAD, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, NOVAUSER.ADSOYAD, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS INNER JOIN NOVAUSER  ON MUH_FIS.ADD_USERID=NOVAUSER.NOVAUSERID WHERE MUH_FIS.FIRMAID=@FIRMAID AND MUH_FIS.SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,NOVAUSER.ADSOYAD,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH, ADSOYAD) AS TBL ON KASATESLIM.TARIH=TBL.TARIH AND KASATESLIM.YETKILI=TBL.ADSOYAD
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
			END
	END
ELSE
	BEGIN
		IF (SELECT COUNT(*) FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND TLTUTAR>0)>0 
			BEGIN
				UPDATE KASATESLIM SET NAKITT=NAKIT, KKARTIT=KKARTI, ACIKHESAP=ACIK, TUTAR=TOPLAM FROM KASATESLIM INNER JOIN  (SELECT TARIH,'GENEL' AS YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, 
				SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,  SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH


				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS  WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				SELECT TARIH,'GENEL' AS YETKILI, SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH
			END
		ELSE
			BEGIN
				DELETE FROM KASATESLIM WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH
				INSERT INTO KASATESLIM (TARIH,YETKILI,FIRMAID,SUBEID,ISLEM,NAKITT,KKARTIT,ACIKHESAP,TUTAR,DOVIZ,KUR,NAKITA,KKARTIA,TLTUTAR)
				SELECT TARIH,'GENEL' AS YETKILI, @FIRMAID, @SUBEID,'KASA TESLİM',SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK,SUM(ISNULL(NAKIT,0))+SUM(ISNULL(KKARTI,0)) AS TOPLAM,'TL',1,0,0,0 FROM TUKETIMFIS WHERE ISNULL(SIL,0)=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH
				GROUP BY TARIH

				UPDATE KASATESLIM SET CNAKITTAHSILAT=NAKITTAHSILAT, CNAKITODEME=NAKITODEME, CKKARTITAHSILAT=KKARTITAHSILAT, CKKARTIODEME=KKARTIODEME
				FROM KASATESLIM INNER JOIN (SELECT TARIH, SUM(NAKITTAHSILAT) AS NAKITTAHSILAT, SUM(KKARTITAHSILAT) AS KKARTITAHSILAT,
				SUM(NAKITODEME) AS NAKITODEME, SUM(KKARTIODEME) AS KKARTIODEME FROM (SELECT TARIH, 
				(CASE WHEN FISTURID=1 THEN SUM(TOPLAM) ELSE 0.00 END) AS NAKITTAHSILAT,
				(CASE WHEN FISTURID=3 THEN SUM(TOPLAM) ELSE 0.00 END) AS KKARTITAHSILAT,
				(CASE WHEN FISTURID=2 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS NAKITODEME,
				(CASE WHEN FISTURID=4 THEN SUM(TOPLAM)*-1 ELSE 0.00 END) AS KKARTIODEME
				FROM MUH_FIS  WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH=@TARIH AND OZELKOD2='SATIS' AND ISNULL(MUH_FIS.SIL,0)=0
				GROUP BY TARIH,FISTURID) AS TBL WHERE 1=1 GROUP BY TARIH) AS TBL ON KASATESLIM.TARIH=TBL.TARIH
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH

				UPDATE KASATESLIM SET TUTAR=ISNULL(NAKITT,0)+ISNULL(KKARTIT,0)+ISNULL(CNAKITTAHSILAT,0)+ISNULL(CKKARTITAHSILAT,0)+ISNULL(CNAKITODEME,0)+ISNULL(CKKARTIODEME,0)
				WHERE KASATESLIM.FIRMAID=@FIRMAID AND KASATESLIM.SUBEID=@SUBEID AND KASATESLIM.TARIH=@TARIH
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKASIYER_OZET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETKASIYER_OZET] @FIRMAID INT, @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT TARIH,NOVAUSER.ADSOYAD, SUM(ISNULL(NAKIT,0)) AS NAKIT, SUM(ISNULL(KKARTI,0)) AS KKARTI, SUM(ISNULL(ACIK,0)) AS ACIK, SUM(ISNULL(TOPLAM,0)) AS TOPLAM 
FROM TUKETIMFIS LEFT JOIN NOVAUSER ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID
WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2 AND ISNULL(TUKETIMFIS.SIL,0)=0
GROUP BY TARIH,NOVAUSER.ADSOYAD ORDER BY ADSOYAD
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETKUR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MARKETKUR]   @FIRMAID INT
AS
BEGIN
	SELECT (SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='EURO' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS EURO,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='USD' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS USD,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='GBP' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS GBP,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='RUB' AND TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS RUB,
	(SELECT TOP 1 DOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU='TL'  AND  TARIH=(SELECT MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID)) AS TL
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MARKETSATIS_KDV]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MARKETSATIS_KDV] @DEPOFISID INT
AS
SELECT * FROM [FNCQ_MARKETSATIS_FISKDV] (@DEPOFISID) ORDER BY KDVORAN
GO
/****** Object:  StoredProcedure [dbo].[PRL_MASALAR]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MASALAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MASALAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MESAIKONTROL]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MESAIKONTROL]  @YIL NVARCHAR(4), @AY NVARCHAR(2), @IKFAZLAMESAIID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  * FROM [FNCQ_MESAIKONTROL] ('+@YIL+','+@AY+','+@IKFAZLAMESAIID+')   WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MIZAN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MIZAN]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@HESAPADI NVARCHAR(200),
@HESAPTIPID NVARCHAR(200)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
DECLARE @SQL2 NVARCHAR(MAX)
DECLARE @SQLPARAM NVARCHAR(MAX)
SET @SQLPARAM=''


SET @SQL1='IF OBJECT_ID(''tempdb..#MUH_HESAP'') IS NOT NULL    DROP TABLE #MUH_HESAP
SELECT * INTO #MUH_HESAP FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT HESAPID,HESAPKODU,HESAPADI,
 HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,
 KODUZUNLUK,
 SUM(TBORC) TBORC,SUM(TALACAK) TALACAK,SUM(UCBORCT) UCBORCT,
 SUM(UCALACAKT) UCALACAKT,SUM(TDBORC) TDBORC,SUM(TDALACAK) TDALACAK,
 SUM(UCTBORC) UCTBORC,SUM(UCTALACAK) UCTALACAK,SUM(UCTDBORC) UCTDBORC,SUM(UCTDALACAK)
 UCTDALACAK,SUM(SONAYTBORC) SONAYTBORC,SUM(SONAYTALACAK) SONAYTALACAK
 ,SUM(SONAYTDBORC) SONAYTDBORC,SUM(SONAYTDALACAK) SONAYTDALACAK
 FROM (
 SELECT  M.HESAPID,M.KODU HESAPKODU,M.ACIKLAMA AS HESAPADI,M.DOVIZ HESAPDOVIZ,M.SEVIYE HESAPSEVIYE,M.HESAPTIPID,
 M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) KODUZUNLUK ,
 U.TBORC,U.TALACAK,U.SONAYTBORC,U.SONAYTALACAK,U.SONAYTDBORC,U.SONAYTDALACAK,CASE 
 WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDBORC END TDBORC,CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0
 ELSE U.TDALACAK END TDALACAK,
 CASE WHEN LEN(M.KODU)=3  THEN TBORC ELSE 0 END    AS UCTBORC,
 CASE WHEN LEN(M.KODU)=3  THEN TALACAK ELSE 0 END  AS UCTALACAK,
 UCBORCT AS UCBORCT,    
 UCALACAKT AS UCALACAKT,
 CASE WHEN LEN(M.KODU)=3 
 THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE 
 U.TDBORC END ) ELSE 0 END AS UCTDBORC,
 CASE WHEN LEN(M.KODU)=3  THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDALACAK END ) ELSE 0 END AS UCTDALACAK
 FROM (
 SELECT * FROM (  SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD6)+2)),HESAPKODU) KOD7 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD5)+2)),HESAPKODU) KOD6 FROM ( 
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD4)+2)),HESAPKODU) KOD5 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD3)+2)),HESAPKODU) KOD4 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD2)+2)),HESAPKODU) KOD3
 FROM (SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD1)+2)),HESAPKODU) KOD2
 FROM (   SELECT HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
, SUM(BORC)   AS  TBORC, 
 SUM(ALACAK) AS  TALACAK,
 CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN (SUM(BORC)-SUM(ALACAK)) ELSE 0 END   AS  UCBORCT,  
 CASE WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN (SUM(ALACAK)-SUM(BORC)) ELSE 0 END   AS  UCALACAKT,
 SUM(DBORC)  AS TDBORC,                                                    
 SUM(DALACAK) AS TDALACAK,                          SUM(BORC)   AS  UCTBORC,
 SUM(ALACAK) AS  UCTALACAK,
 SUM(DBORC) AS UCTDBORC,
 SUM(DALACAK) AS UCTDALACAK,0.00 SONAYTBORC,0.00 SONAYTALACAK ,0.00 SONAYTDBORC,0.00 SONAYTDALACAK,
 LEFT(HESAPKODU,1) KOD_1,LEFT(HESAPKODU,2) KOD_2,
 NULLIF(LEFT(HESAPKODU+''.'', CHARINDEX(''.'',HESAPKODU+''.'')),HESAPKODU) KOD1
 FROM  FNCQ_QMUHMIZAN('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  
 WHERE  1=1 '+@MASMERID+@PROJEID+@KODARALIK+@SUBEID+@HESAPADI+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
(TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')'

SET @SQL2='GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
   ) T) T) T) T) T) T
) U
 INNER JOIN (SELECT KODU FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+') AS M ON (M.KODU = U.HESAPKODU)
 OR (M.KODU = CASE WHEN U.KOD1 IS NULL OR U.KOD1='''' THEN NULL ELSE LEFT(U.KOD1,LEN(U.KOD1)-1) END)
 OR (M.KODU = CASE WHEN U.KOD2 IS NULL OR U.KOD2='''' THEN NULL ELSE LEFT(U.KOD2,LEN(U.KOD2)-1) END)
 OR (M.KODU = CASE WHEN U.KOD3 IS NULL OR U.KOD3='''' THEN NULL ELSE LEFT(U.KOD3,LEN(U.KOD3)-1) END)
 OR (M.KODU = CASE WHEN U.KOD4 IS NULL OR U.KOD4='''' THEN NULL ELSE LEFT(U.KOD4,LEN(U.KOD4)-1) END)
 OR (M.KODU = CASE WHEN U.KOD5 IS NULL OR U.KOD5='''' THEN NULL ELSE LEFT(U.KOD5,LEN(U.KOD5)-1) END)
 OR (M.KODU = CASE WHEN U.KOD6 IS NULL OR U.KOD6='''' THEN NULL ELSE LEFT(U.KOD6,LEN(U.KOD6)-1) END)
 OR (M.KODU = CASE WHEN U.KOD7 IS NULL OR U.KOD7='''' THEN NULL ELSE LEFT(U.KOD7,LEN(U.KOD7)-1) END)
 OR (M.KODU = U.KOD_2)      
 OR (M.KODU = U.KOD_1)) AS U
INNER                                                  
 JOIN (SELECT * FROM #MUH_HESAP) AS M ON M.KODU = U.KODU
) U
 WHERE 1=1
GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
 ORDER BY HESAPKODU'
EXEC (@SQL1+@SQLPARAM+@SQL2)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MIZAN2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MIZAN2]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@HESAPADI NVARCHAR(200),
@HESAPTIPID NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
DECLARE @SQL2 NVARCHAR(MAX)
DECLARE @SQLPARAM NVARCHAR(MAX)
SET @SQLPARAM=''

SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'

SET @SQL1='IF OBJECT_ID(''tempdb..#MUH_HESAP'') IS NOT NULL    DROP TABLE #MUH_HESAP
SELECT * INTO #MUH_HESAP FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT HESAPID,HESAPKODU,HESAPADI,
 HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,
 KODUZUNLUK,
 SUM(TBORC) TBORC,SUM(TALACAK) TALACAK,SUM(UCBORCT) UCBORCT,
 SUM(UCALACAKT) UCALACAKT,SUM(TDBORC) TDBORC,SUM(TDALACAK) TDALACAK,
 SUM(UCTBORC) UCTBORC,SUM(UCTALACAK) UCTALACAK,SUM(UCTDBORC) UCTDBORC,SUM(UCTDALACAK)
 UCTDALACAK,SUM(SONAYTBORC) SONAYTBORC,SUM(SONAYTALACAK) SONAYTALACAK
 ,SUM(SONAYTDBORC) SONAYTDBORC,SUM(SONAYTDALACAK) SONAYTDALACAK
 FROM (
 SELECT  M.HESAPID,M.KODU HESAPKODU,M.ACIKLAMA AS HESAPADI,M.DOVIZ HESAPDOVIZ,M.SEVIYE HESAPSEVIYE,M.HESAPTIPID,
 M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) KODUZUNLUK ,
 U.TBORC,U.TALACAK,U.SONAYTBORC,U.SONAYTALACAK,U.SONAYTDBORC,U.SONAYTDALACAK,CASE 
 WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDBORC END TDBORC,CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0
 ELSE U.TDALACAK END TDALACAK,
 CASE WHEN LEN(M.KODU)=3  THEN TBORC ELSE 0 END    AS UCTBORC,
 CASE WHEN LEN(M.KODU)=3  THEN TALACAK ELSE 0 END  AS UCTALACAK,
 UCBORCT AS UCBORCT,    
 UCALACAKT AS UCALACAKT,
 CASE WHEN LEN(M.KODU)=3 
 THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE 
 U.TDBORC END ) ELSE 0 END AS UCTDBORC,
 CASE WHEN LEN(M.KODU)=3  THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDALACAK END ) ELSE 0 END AS UCTDALACAK
 FROM (
 SELECT * FROM (  SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD6)+2)),HESAPKODU) KOD7 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD5)+2)),HESAPKODU) KOD6 FROM ( 
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD4)+2)),HESAPKODU) KOD5 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD3)+2)),HESAPKODU) KOD4 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD2)+2)),HESAPKODU) KOD3
 FROM (SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD1)+2)),HESAPKODU) KOD2
 FROM (   SELECT HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
, SUM(BORC)   AS  TBORC, 
 SUM(ALACAK) AS  TALACAK,
 CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN (SUM(BORC)-SUM(ALACAK)) ELSE 0 END   AS  UCBORCT,  
 CASE WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN (SUM(ALACAK)-SUM(BORC)) ELSE 0 END   AS  UCALACAKT,
 SUM(DBORC)  AS TDBORC,                                                    
 SUM(DALACAK) AS TDALACAK,                          SUM(BORC)   AS  UCTBORC,
 SUM(ALACAK) AS  UCTALACAK,
 SUM(DBORC) AS UCTDBORC,
 SUM(DALACAK) AS UCTDALACAK,0.00 SONAYTBORC,0.00 SONAYTALACAK ,0.00 SONAYTDBORC,0.00 SONAYTDALACAK,
 LEFT(HESAPKODU,1) KOD_1,LEFT(HESAPKODU,2) KOD_2,
 NULLIF(LEFT(HESAPKODU+''.'', CHARINDEX(''.'',HESAPKODU+''.'')),HESAPKODU) KOD1
 FROM  '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  
 WHERE  1=1 '+@MASMERID+@PROJEID+@KODARALIK+@SUBEID+@HESAPADI+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
(TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')'

SET @SQL2='GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
   ) T) T) T) T) T) T
) U
 INNER JOIN (SELECT KODU FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+') AS M ON (M.KODU = U.HESAPKODU)
 OR (M.KODU = CASE WHEN U.KOD1 IS NULL OR U.KOD1='''' THEN NULL ELSE LEFT(U.KOD1,LEN(U.KOD1)-1) END)
 OR (M.KODU = CASE WHEN U.KOD2 IS NULL OR U.KOD2='''' THEN NULL ELSE LEFT(U.KOD2,LEN(U.KOD2)-1) END)
 OR (M.KODU = CASE WHEN U.KOD3 IS NULL OR U.KOD3='''' THEN NULL ELSE LEFT(U.KOD3,LEN(U.KOD3)-1) END)
 OR (M.KODU = CASE WHEN U.KOD4 IS NULL OR U.KOD4='''' THEN NULL ELSE LEFT(U.KOD4,LEN(U.KOD4)-1) END)
 OR (M.KODU = CASE WHEN U.KOD5 IS NULL OR U.KOD5='''' THEN NULL ELSE LEFT(U.KOD5,LEN(U.KOD5)-1) END)
 OR (M.KODU = CASE WHEN U.KOD6 IS NULL OR U.KOD6='''' THEN NULL ELSE LEFT(U.KOD6,LEN(U.KOD6)-1) END)
 OR (M.KODU = CASE WHEN U.KOD7 IS NULL OR U.KOD7='''' THEN NULL ELSE LEFT(U.KOD7,LEN(U.KOD7)-1) END)
 OR (M.KODU = U.KOD_2)      
 OR (M.KODU = U.KOD_1)) AS U
INNER                                                  
 JOIN (SELECT * FROM #MUH_HESAP) AS M ON M.KODU = U.KODU
) U
 WHERE 1=1
GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
 ORDER BY HESAPKODU'
EXEC (@SQL1+@SQLPARAM+@SQL2)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MIZAN3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MIZAN3]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ISLEMGRUPID1 NVARCHAR(100),
@ISLEMGRUPID2 NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@HESAPADI NVARCHAR(200),
@HESAPTIPID NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
DECLARE @SQL2 NVARCHAR(MAX)
DECLARE @SQLPARAM NVARCHAR(MAX)
SET @SQLPARAM=''

SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'

SET @SQL1='IF OBJECT_ID(''tempdb..#MUH_HESAP'') IS NOT NULL    DROP TABLE #MUH_HESAP
SELECT * INTO #MUH_HESAP FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT HESAPID,HESAPKODU,HESAPADI,
 HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,
 KODUZUNLUK,
 SUM(TBORC) TBORC,SUM(TALACAK) TALACAK,SUM(UCBORCT) UCBORCT,
 SUM(UCALACAKT) UCALACAKT,SUM(TDBORC) TDBORC,SUM(TDALACAK) TDALACAK,
 SUM(UCTBORC) UCTBORC,SUM(UCTALACAK) UCTALACAK,SUM(UCTDBORC) UCTDBORC,SUM(UCTDALACAK)
 UCTDALACAK,SUM(SONAYTBORC) SONAYTBORC,SUM(SONAYTALACAK) SONAYTALACAK
 ,SUM(SONAYTDBORC) SONAYTDBORC,SUM(SONAYTDALACAK) SONAYTDALACAK, sum(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK
 FROM (
 SELECT  M.HESAPID,M.KODU HESAPKODU,M.ACIKLAMA AS HESAPADI,M.DOVIZ HESAPDOVIZ,M.SEVIYE HESAPSEVIYE,M.HESAPTIPID,
 M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) KODUZUNLUK ,
 U.TBORC,U.TALACAK,U.RBORC,U.RALACAK,U.SONAYTBORC,U.SONAYTALACAK,U.SONAYTDBORC,U.SONAYTDALACAK,CASE 
 WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDBORC END TDBORC,CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0
 ELSE U.TDALACAK END TDALACAK,
 CASE WHEN LEN(M.KODU)=3  THEN TBORC ELSE 0 END    AS UCTBORC,
 CASE WHEN LEN(M.KODU)=3  THEN TALACAK ELSE 0 END  AS UCTALACAK,
 UCBORCT AS UCBORCT,    
 UCALACAKT AS UCALACAKT,
 CASE WHEN LEN(M.KODU)=3 
 THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE 
 U.TDBORC END ) ELSE 0 END AS UCTDBORC,
 CASE WHEN LEN(M.KODU)=3  THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDALACAK END ) ELSE 0 END AS UCTDALACAK
 FROM (
 SELECT * FROM (  SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD6)+2)),HESAPKODU) KOD7 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD5)+2)),HESAPKODU) KOD6 FROM ( 
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD4)+2)),HESAPKODU) KOD5 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD3)+2)),HESAPKODU) KOD4 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD2)+2)),HESAPKODU) KOD3
 FROM (SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD1)+2)),HESAPKODU) KOD2
 FROM (   SELECT HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
, SUM(BORC)   AS  TBORC, 
 SUM(ALACAK) AS  TALACAK,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,
 CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN (SUM(BORC)-SUM(ALACAK)) ELSE 0 END   AS  UCBORCT,  
 CASE WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN (SUM(ALACAK)-SUM(BORC)) ELSE 0 END   AS  UCALACAKT,
 SUM(DBORC)  AS TDBORC,                                                    
 SUM(DALACAK) AS TDALACAK,                          SUM(BORC)   AS  UCTBORC,
 SUM(ALACAK) AS  UCTALACAK,
 SUM(DBORC) AS UCTDBORC,
 SUM(DALACAK) AS UCTDALACAK,0.00 SONAYTBORC,0.00 SONAYTALACAK ,0.00 SONAYTDBORC,0.00 SONAYTDALACAK,
 LEFT(HESAPKODU,1) KOD_1,LEFT(HESAPKODU,2) KOD_2,
 NULLIF(LEFT(HESAPKODU+''.'', CHARINDEX(''.'',HESAPKODU+''.'')),HESAPKODU) KOD1
 FROM  '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  
 WHERE  1=1 '+@MASMERID+@PROJEID+@ISLEMGRUPID1+@ISLEMGRUPID2+@KODARALIK+@SUBEID+@HESAPADI+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
(TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')'

SET @SQL2='GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
   ) T) T) T) T) T) T
) U
 INNER JOIN (SELECT KODU FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+') AS M ON (M.KODU = U.HESAPKODU)
 OR (M.KODU = CASE WHEN U.KOD1 IS NULL OR U.KOD1='''' THEN NULL ELSE LEFT(U.KOD1,LEN(U.KOD1)-1) END)
 OR (M.KODU = CASE WHEN U.KOD2 IS NULL OR U.KOD2='''' THEN NULL ELSE LEFT(U.KOD2,LEN(U.KOD2)-1) END)
 OR (M.KODU = CASE WHEN U.KOD3 IS NULL OR U.KOD3='''' THEN NULL ELSE LEFT(U.KOD3,LEN(U.KOD3)-1) END)
 OR (M.KODU = CASE WHEN U.KOD4 IS NULL OR U.KOD4='''' THEN NULL ELSE LEFT(U.KOD4,LEN(U.KOD4)-1) END)
 OR (M.KODU = CASE WHEN U.KOD5 IS NULL OR U.KOD5='''' THEN NULL ELSE LEFT(U.KOD5,LEN(U.KOD5)-1) END)
 OR (M.KODU = CASE WHEN U.KOD6 IS NULL OR U.KOD6='''' THEN NULL ELSE LEFT(U.KOD6,LEN(U.KOD6)-1) END)
 OR (M.KODU = CASE WHEN U.KOD7 IS NULL OR U.KOD7='''' THEN NULL ELSE LEFT(U.KOD7,LEN(U.KOD7)-1) END)
 OR (M.KODU = U.KOD_2)      
 OR (M.KODU = U.KOD_1)) AS U
INNER                                                  
 JOIN (SELECT * FROM #MUH_HESAP) AS M ON M.KODU = U.KODU
) U
 WHERE 1=1
GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
 ORDER BY HESAPKODU'
EXEC (@SQL1+@SQLPARAM+@SQL2)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MIZAN4]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MIZAN4]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ISLEMGRUPID1 NVARCHAR(100),
@ISLEMGRUPID2 NVARCHAR(100),
@HESAPGRUPID1 NVARCHAR(100),
@HESAPGRUPID2 NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@HESAPADI NVARCHAR(200),
@HESAPTIPID NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
DECLARE @SQL2 NVARCHAR(MAX)
DECLARE @SQLPARAM NVARCHAR(MAX)
SET @SQLPARAM=''

SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'

SET @SQL1='IF OBJECT_ID(''tempdb..#MUH_HESAP'') IS NOT NULL    DROP TABLE #MUH_HESAP
SELECT * INTO #MUH_HESAP FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT HESAPID,HESAPKODU,HESAPADI,
 HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,
 KODUZUNLUK,
 SUM(TBORC) TBORC,SUM(TALACAK) TALACAK,SUM(UCBORCT) UCBORCT,
 SUM(UCALACAKT) UCALACAKT,SUM(TDBORC) TDBORC,SUM(TDALACAK) TDALACAK,
 SUM(UCTBORC) UCTBORC,SUM(UCTALACAK) UCTALACAK,SUM(UCTDBORC) UCTDBORC,SUM(UCTDALACAK)
 UCTDALACAK,SUM(SONAYTBORC) SONAYTBORC,SUM(SONAYTALACAK) SONAYTALACAK
 ,SUM(SONAYTDBORC) SONAYTDBORC,SUM(SONAYTDALACAK) SONAYTDALACAK, sum(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK
 FROM (
 SELECT  M.HESAPID,M.KODU HESAPKODU,M.ACIKLAMA AS HESAPADI,M.DOVIZ HESAPDOVIZ,M.SEVIYE HESAPSEVIYE,M.HESAPTIPID,
 M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) KODUZUNLUK ,
 U.TBORC,U.TALACAK,U.RBORC,U.RALACAK,U.SONAYTBORC,U.SONAYTALACAK,U.SONAYTDBORC,U.SONAYTDALACAK,CASE 
 WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDBORC END TDBORC,CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0
 ELSE U.TDALACAK END TDALACAK,
 CASE WHEN LEN(M.KODU)=3  THEN TBORC ELSE 0 END    AS UCTBORC,
 CASE WHEN LEN(M.KODU)=3  THEN TALACAK ELSE 0 END  AS UCTALACAK,
 UCBORCT AS UCBORCT,    
 UCALACAKT AS UCALACAKT,
 CASE WHEN LEN(M.KODU)=3 
 THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE 
 U.TDBORC END ) ELSE 0 END AS UCTDBORC,
 CASE WHEN LEN(M.KODU)=3  THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDALACAK END ) ELSE 0 END AS UCTDALACAK
 FROM (
 SELECT * FROM (  SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD6)+2)),HESAPKODU) KOD7 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD5)+2)),HESAPKODU) KOD6 FROM ( 
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD4)+2)),HESAPKODU) KOD5 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD3)+2)),HESAPKODU) KOD4 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD2)+2)),HESAPKODU) KOD3
 FROM (SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD1)+2)),HESAPKODU) KOD2
 FROM (   SELECT HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
, SUM(BORC)   AS  TBORC, 
 SUM(ALACAK) AS  TALACAK,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,
 CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN (SUM(BORC)-SUM(ALACAK)) ELSE 0 END   AS  UCBORCT,  
 CASE WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN (SUM(ALACAK)-SUM(BORC)) ELSE 0 END   AS  UCALACAKT,
 SUM(DBORC)  AS TDBORC,                                                    
 SUM(DALACAK) AS TDALACAK,                          SUM(BORC)   AS  UCTBORC,
 SUM(ALACAK) AS  UCTALACAK,
 SUM(DBORC) AS UCTDBORC,
 SUM(DALACAK) AS UCTDALACAK,0.00 SONAYTBORC,0.00 SONAYTALACAK ,0.00 SONAYTDBORC,0.00 SONAYTDALACAK,
 LEFT(HESAPKODU,1) KOD_1,LEFT(HESAPKODU,2) KOD_2,
 NULLIF(LEFT(HESAPKODU+''.'', CHARINDEX(''.'',HESAPKODU+''.'')),HESAPKODU) KOD1
 FROM  '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  
 WHERE  1=1 '+@MASMERID+@PROJEID+@ISLEMGRUPID1+@ISLEMGRUPID2++@HESAPGRUPID1+@HESAPGRUPID2+@KODARALIK+@SUBEID+@HESAPADI+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
(TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')'

SET @SQL2='GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
   ) T) T) T) T) T) T
) U
 INNER JOIN (SELECT KODU FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+') AS M ON (M.KODU = U.HESAPKODU)
 OR (M.KODU = CASE WHEN U.KOD1 IS NULL OR U.KOD1='''' THEN NULL ELSE LEFT(U.KOD1,LEN(U.KOD1)-1) END)
 OR (M.KODU = CASE WHEN U.KOD2 IS NULL OR U.KOD2='''' THEN NULL ELSE LEFT(U.KOD2,LEN(U.KOD2)-1) END)
 OR (M.KODU = CASE WHEN U.KOD3 IS NULL OR U.KOD3='''' THEN NULL ELSE LEFT(U.KOD3,LEN(U.KOD3)-1) END)
 OR (M.KODU = CASE WHEN U.KOD4 IS NULL OR U.KOD4='''' THEN NULL ELSE LEFT(U.KOD4,LEN(U.KOD4)-1) END)
 OR (M.KODU = CASE WHEN U.KOD5 IS NULL OR U.KOD5='''' THEN NULL ELSE LEFT(U.KOD5,LEN(U.KOD5)-1) END)
 OR (M.KODU = CASE WHEN U.KOD6 IS NULL OR U.KOD6='''' THEN NULL ELSE LEFT(U.KOD6,LEN(U.KOD6)-1) END)
 OR (M.KODU = CASE WHEN U.KOD7 IS NULL OR U.KOD7='''' THEN NULL ELSE LEFT(U.KOD7,LEN(U.KOD7)-1) END)
 OR (M.KODU = U.KOD_2)      
 OR (M.KODU = U.KOD_1)) AS U
INNER                                                  
 JOIN (SELECT * FROM #MUH_HESAP) AS M ON M.KODU = U.KODU
) U
 WHERE 1=1
GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
 ORDER BY HESAPKODU'
EXEC (@SQL1+@SQLPARAM+@SQL2)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MIZAN5]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MIZAN5]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ISLEMGRUPID1 NVARCHAR(100),
@ISLEMGRUPID2 NVARCHAR(100),
@HESAPGRUPID1 NVARCHAR(100),
@HESAPGRUPID2 NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@HESAPADI NVARCHAR(200),
@HESAPTIPID NVARCHAR(200),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30),
@KAPANISACILISDAHIL NVARCHAR(50)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
DECLARE @SQL2 NVARCHAR(MAX)
DECLARE @SQLPARAM NVARCHAR(MAX)
SET @SQLPARAM=''

SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'

SET @SQL1='IF OBJECT_ID(''tempdb..#MUH_HESAP'') IS NOT NULL    DROP TABLE #MUH_HESAP
SELECT * INTO #MUH_HESAP FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+'
SELECT HESAPID,HESAPKODU,HESAPADI,
 HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,
 KODUZUNLUK,
 SUM(TBORC) TBORC,SUM(TALACAK) TALACAK,SUM(UCBORCT) UCBORCT,
 SUM(UCALACAKT) UCALACAKT,SUM(TDBORC) TDBORC,SUM(TDALACAK) TDALACAK,
 SUM(UCTBORC) UCTBORC,SUM(UCTALACAK) UCTALACAK,SUM(UCTDBORC) UCTDBORC,SUM(UCTDALACAK)
 UCTDALACAK,SUM(SONAYTBORC) SONAYTBORC,SUM(SONAYTALACAK) SONAYTALACAK
 ,SUM(SONAYTDBORC) SONAYTDBORC,SUM(SONAYTDALACAK) SONAYTDALACAK, sum(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK
 FROM (
 SELECT  M.HESAPID,M.KODU HESAPKODU,M.ACIKLAMA AS HESAPADI,M.DOVIZ HESAPDOVIZ,M.SEVIYE HESAPSEVIYE,M.HESAPTIPID,
 M.UCHESAP,M.CALISMASEKLI,LEN(M.KODU) KODUZUNLUK ,
 U.TBORC,U.TALACAK,U.RBORC,U.RALACAK,U.SONAYTBORC,U.SONAYTALACAK,U.SONAYTDBORC,U.SONAYTDALACAK,CASE 
 WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDBORC END TDBORC,CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0
 ELSE U.TDALACAK END TDALACAK,
 CASE WHEN LEN(M.KODU)=3  THEN TBORC ELSE 0 END    AS UCTBORC,
 CASE WHEN LEN(M.KODU)=3  THEN TALACAK ELSE 0 END  AS UCTALACAK,
 UCBORCT AS UCBORCT,    
 UCALACAKT AS UCALACAKT,
 CASE WHEN LEN(M.KODU)=3 
 THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE 
 U.TDBORC END ) ELSE 0 END AS UCTDBORC,
 CASE WHEN LEN(M.KODU)=3  THEN (CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL'' THEN 0 ELSE  U.TDALACAK END ) ELSE 0 END AS UCTDALACAK
 FROM (
 SELECT * FROM (  SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD6)+2)),HESAPKODU) KOD7 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD5)+2)),HESAPKODU) KOD6 FROM ( 
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD4)+2)),HESAPKODU) KOD5 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD3)+2)),HESAPKODU) KOD4 FROM (
 SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD2)+2)),HESAPKODU) KOD3
 FROM (SELECT *, NULLIF(LEFT(HESAPKODU,CHARINDEX(''.'',HESAPKODU+''.'',LEN(KOD1)+2)),HESAPKODU) KOD2
 FROM (   SELECT HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
, SUM(BORC)   AS  TBORC, 
 SUM(ALACAK) AS  TALACAK,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,
 CASE WHEN (SUM(BORC)-SUM(ALACAK))>0 THEN (SUM(BORC)-SUM(ALACAK)) ELSE 0 END   AS  UCBORCT,  
 CASE WHEN (SUM(BORC)-SUM(ALACAK))<0 THEN (SUM(ALACAK)-SUM(BORC)) ELSE 0 END   AS  UCALACAKT,
 SUM(DBORC)  AS TDBORC,                                                    
 SUM(DALACAK) AS TDALACAK,                          SUM(BORC)   AS  UCTBORC,
 SUM(ALACAK) AS  UCTALACAK,
 SUM(DBORC) AS UCTDBORC,
 SUM(DALACAK) AS UCTDALACAK,0.00 SONAYTBORC,0.00 SONAYTALACAK ,0.00 SONAYTDBORC,0.00 SONAYTDALACAK,
 LEFT(HESAPKODU,1) KOD_1,LEFT(HESAPKODU,2) KOD_2,
 NULLIF(LEFT(HESAPKODU+''.'', CHARINDEX(''.'',HESAPKODU+''.'')),HESAPKODU) KOD1
 FROM  '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  
 WHERE  1=1 '+@MASMERID+@PROJEID+@ISLEMGRUPID1+@ISLEMGRUPID2++@HESAPGRUPID1+@HESAPGRUPID2+@KODARALIK+@SUBEID+@HESAPADI+@HESAPTIPID+@KAPANISACILISDAHIL+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
(TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')'

SET @SQL2='GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
   ) T) T) T) T) T) T
) U
 INNER JOIN (SELECT KODU FROM MUH_HESAP WHERE FIRMAID='+@FIRMAID+') AS M ON (M.KODU = U.HESAPKODU)
 OR (M.KODU = CASE WHEN U.KOD1 IS NULL OR U.KOD1='''' THEN NULL ELSE LEFT(U.KOD1,LEN(U.KOD1)-1) END)
 OR (M.KODU = CASE WHEN U.KOD2 IS NULL OR U.KOD2='''' THEN NULL ELSE LEFT(U.KOD2,LEN(U.KOD2)-1) END)
 OR (M.KODU = CASE WHEN U.KOD3 IS NULL OR U.KOD3='''' THEN NULL ELSE LEFT(U.KOD3,LEN(U.KOD3)-1) END)
 OR (M.KODU = CASE WHEN U.KOD4 IS NULL OR U.KOD4='''' THEN NULL ELSE LEFT(U.KOD4,LEN(U.KOD4)-1) END)
 OR (M.KODU = CASE WHEN U.KOD5 IS NULL OR U.KOD5='''' THEN NULL ELSE LEFT(U.KOD5,LEN(U.KOD5)-1) END)
 OR (M.KODU = CASE WHEN U.KOD6 IS NULL OR U.KOD6='''' THEN NULL ELSE LEFT(U.KOD6,LEN(U.KOD6)-1) END)
 OR (M.KODU = CASE WHEN U.KOD7 IS NULL OR U.KOD7='''' THEN NULL ELSE LEFT(U.KOD7,LEN(U.KOD7)-1) END)
 OR (M.KODU = U.KOD_2)      
 OR (M.KODU = U.KOD_1)) AS U
INNER                                                  
 JOIN (SELECT * FROM #MUH_HESAP) AS M ON M.KODU = U.KODU
) U
 WHERE 1=1
GROUP BY HESAPID,HESAPKODU,HESAPADI,HESAPDOVIZ,HESAPSEVIYE,HESAPTIPID,UCHESAP,CALISMASEKLI,KODUZUNLUK
 ORDER BY HESAPKODU'
EXEC (@SQL1+@SQLPARAM+@SQL2)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUAVIN]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--EXEC PRL_MUAVIN ' AND SUBEID IN(1)','1','','','2020-01-01','2020-01-30','AND KODU>=''100'' AND KODU<=''322''','','','HESAPKODU'

CREATE PROCEDURE [dbo].[PRL_MUAVIN]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@ALTCARIKODU NVARCHAR(100),
@HESAPTIPID NVARCHAR(200),
@SIRALAMA NVARCHAR(20)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
SET @SQL1='SELECT HESAPKODU,HESAPADI,TARIH,VADE,FISTURU,FISNO,BELGENO,ACIKLAMA,FISID,
			BORC,ALACAK,DOVIZ,DBORC,DALACAK,KUR,SUBEADI,MASMERKODU,MASMERADI,FISTURID,KARSIHESAPADI,
			PROJEKODU,PROJEADI,KARSIHESAPKODU,ALTCARIKODU,ALTCARIID,ALTCARIUNVAN FROM ( SELECT  HESAPID,
                 HESAPKODU, HESAPADI, TARIH, VADE,
                 FISTURU, FISNO, BELGENO, ACIKLAMA,
                 FISID, BORC, ALACAK, DOVIZ, DBORC, DALACAK,
                 KUR, SUBEADI, MASMERKODU, 
                 MASMERADI, FISTURID, 
                 KARSIHESAPADI, 
                 PROJEKODU, PROJEADI, KARSIHESAPKODU,
                 ALTCARIKODU,ALTCARIID,
                 ALTCARIUNVAN
                 FROM FNCQ_QMUHMIZAN('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''') 
                 WHERE 1=1 '+@ALTCARIKODU+'  '+@MASMERID+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
                 (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')
                 UNION ALL SELECT HESAPID,HESAPKODU, HESAPADI, '''+@ILKTARIH+''' AS TARIH,
                 NULL AS VADE, NULL AS FISTURU, NULL AS FISNO, NULL AS BELGENO, 
                 ''Devir'' AS ACIKLAMA,  null as FISID,
                 sum(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL AS DOVIZ,
                 SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL AS KUR,
                 SUBEADI, NULL AS MASMERKODU,NULL AS MASMERADI,
                 NULL AS FISTURID, 
                 NULL AS KARSIHESAPADI, NULL AS PROJEKODU,
                 NULL AS PROJEADI, NULL AS KARSIHESAPKODU,NULL AS ALTCARIKODU,NULL AS ALTCARIID,NULL AS ALTCARIUNVAN 
                 FROM FNCQ_QMUHMIZAN('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  WHERE 1=1  '+@ALTCARIKODU+'  '+@MASMERID+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  TARIH<'''+@ILKTARIH+'''
                 GROUP BY HESAPID,
                 HESAPKODU, HESAPADI,
                 SUBEADI)  TBL  ORDER BY '+@SIRALAMA+' TARIH,FISID'
EXEC (@SQL1)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUAVIN2]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



--EXEC PRL_MUAVIN ' AND SUBEID IN(1)','1','','','2020-01-01','2020-01-30','AND KODU>=''100'' AND KODU<=''322''','','','HESAPKODU'

CREATE PROCEDURE [dbo].[PRL_MUAVIN2]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@ALTCARIKODU NVARCHAR(100),
@HESAPTIPID NVARCHAR(200),
@SIRALAMA NVARCHAR(20),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'

SET @SQL1='SELECT HESAPKODU,HESAPADI,TARIH,VADE,FISTURU,FISNO,BELGENO,ACIKLAMA,FISID,
			BORC,ALACAK,DOVIZ,DBORC,DALACAK,KUR,SUBEADI,MASMERKODU,MASMERADI,FISTURID,KARSIHESAPADI,
			PROJEKODU,PROJEADI,KARSIHESAPKODU,ALTCARIKODU,ALTCARIID,ALTCARIUNVAN FROM ( SELECT  HESAPID,
                 HESAPKODU, HESAPADI, TARIH, VADE,
                 FISTURU, FISNO, BELGENO, ACIKLAMA,
                 FISID, BORC, ALACAK, DOVIZ, DBORC, DALACAK,
                 KUR, SUBEADI, MASMERKODU, 
                 MASMERADI, FISTURID, 
                 KARSIHESAPADI, 
                 PROJEKODU, PROJEADI, KARSIHESAPKODU,
                 ALTCARIKODU,ALTCARIID,
                 ALTCARIUNVAN
                 FROM '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''') 
                 WHERE 1=1 '+@ALTCARIKODU+'  '+@MASMERID+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
                 (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')
                 UNION ALL SELECT HESAPID,HESAPKODU, HESAPADI, '''+@ILKTARIH+''' AS TARIH,
                 NULL AS VADE, NULL AS FISTURU, NULL AS FISNO, NULL AS BELGENO, 
                 ''Devir'' AS ACIKLAMA,  null as FISID,
                 sum(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL AS DOVIZ,
                 SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL AS KUR,
                 SUBEADI, NULL AS MASMERKODU,NULL AS MASMERADI,
                 NULL AS FISTURID, 
                 NULL AS KARSIHESAPADI, NULL AS PROJEKODU,
                 NULL AS PROJEADI, NULL AS KARSIHESAPKODU,NULL AS ALTCARIKODU,NULL AS ALTCARIID,NULL AS ALTCARIUNVAN 
                 FROM '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  WHERE 1=1  '+@ALTCARIKODU+'  '+@MASMERID+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  TARIH<'''+@ILKTARIH+'''
                 GROUP BY HESAPID,
                 HESAPKODU, HESAPADI,
                 SUBEADI)  TBL  ORDER BY '+@SIRALAMA+' TARIH,FISID'
EXEC (@SQL1)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUAVIN3]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUAVIN3]  
@SUBEID NVARCHAR(100),
@FIRMAID NVARCHAR(100),
@MASMERID NVARCHAR(100),
@PROJEID NVARCHAR(100),
@ISLEMGRUPID1 NVARCHAR(100),
@ISLEMGRUPID2 NVARCHAR(100),
@ILKTARIH NVARCHAR(100),
@SONTARIH NVARCHAR(100),
@KODARALIK NVARCHAR(100),
@ALTCARIKODU NVARCHAR(100),
@HESAPTIPID NVARCHAR(200),
@SIRALAMA NVARCHAR(50),
@FATURADAHIL NVARCHAR(1),
@FONKSIYONADI NVARCHAR(30)
AS
BEGIN
DECLARE @SQL1 NVARCHAR(MAX)
IF @FATURADAHIL='0' SET @FONKSIYONADI='FNCQ_QMUHMIZAN'
IF @FATURADAHIL='1' SET @FONKSIYONADI='FNCQ_QMUHMIZAN_FATURA'

SET @SQL1='SELECT HESAPGRUPID1,HESAPGRUPID2,HESAPGRUPADI,HESAPKODU,HESAPADI,TARIH,VADE,FISTURU,FISNO,BELGENO,ACIKLAMA,FISID,
			BORC,ALACAK,DOVIZ,DBORC,DALACAK,RDOVIZ,RBORC,RALACAK,KUR,SUBEADI,MASMERKODU,MASMERADI,FISTURID,KARSIHESAPADI,
			PROJEKODU,PROJEADI,KARSIHESAPKODU,ALTCARIKODU,ALTCARIID,ALTCARIUNVAN,HESAPKODU+'' : ''+HESAPADI AS HESAPKODUveADI FROM ( SELECT HESAPGRUPID1,HESAPGRUPID2,HESAPGRUPADI, HESAPID,
                 HESAPKODU, HESAPADI, TARIH, VADE,
                 FISTURU, FISNO, BELGENO, ACIKLAMA,
                 FISID, BORC, ALACAK, DOVIZ, DBORC, DALACAK,RDOVIZ,RBORC,RALACAK,
                 KUR, SUBEADI, MASMERKODU, 
                 MASMERADI, FISTURID, 
                 KARSIHESAPADI, 
                 PROJEKODU, PROJEADI, KARSIHESAPKODU,
                 ALTCARIKODU,ALTCARIID,
                 ALTCARIUNVAN,HESAPKODU+'' : ''+HESAPADI AS HESAPKODUveADI
                 FROM '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''') 
                 WHERE 1=1 '+@ALTCARIKODU+'  '+@MASMERID+@PROJEID+@ISLEMGRUPID1+@ISLEMGRUPID2+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')  AND
                 (TARIH BETWEEN '''+@ILKTARIH+''' AND '''+@SONTARIH+''')
                 UNION ALL SELECT NULL,NULL,null,HESAPID,HESAPKODU, HESAPADI, '''+@ILKTARIH+''' AS TARIH,
                 NULL AS VADE, NULL AS FISTURU, NULL AS FISNO, NULL AS BELGENO, 
                 ''Devir'' AS ACIKLAMA,  null as FISID,
                 sum(BORC) AS BORC, SUM(ALACAK) AS ALACAK, NULL AS DOVIZ,
                 SUM(DBORC) AS DBORC, SUM(DALACAK) AS DALACAK,NULL,SUM(RBORC) AS RBORC, SUM(RALACAK) AS RALACAK,NULL AS KUR,
                 SUBEADI, NULL AS MASMERKODU,NULL AS MASMERADI,
                 NULL AS FISTURID, 
                 NULL AS KARSIHESAPADI, NULL AS PROJEKODU,
                 NULL AS PROJEADI, NULL AS KARSIHESAPKODU,NULL AS ALTCARIKODU,NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,HESAPKODU+'' : ''+HESAPADI AS HESAPKODUveADI 
                 FROM '+@FONKSIYONADI+'('''+@ILKTARIH+''','''+@SONTARIH+''','''+@FIRMAID+''')  WHERE 1=1  '+@ALTCARIKODU+'  '+@MASMERID+@PROJEID+@ISLEMGRUPID1+@ISLEMGRUPID2+' '+@KODARALIK+' '+@SUBEID+' '+@HESAPTIPID+' AND  TARIH<'''+@ILKTARIH+'''
                 GROUP BY HESAPID,
                 HESAPKODU, HESAPADI,
                 SUBEADI)  TBL  ORDER BY '+@SIRALAMA+', TARIH,FISID'
EXEC (@SQL1)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_BANKATANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUH_BANKATANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_BANKATANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_ENTDATA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO








CREATE PROCEDURE [dbo].[PRL_MUH_ENTDATA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_ENTDATA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_ENTTANIM]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO








CREATE PROCEDURE [dbo].[PRL_MUH_ENTTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_ENTTANIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUH_FIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE FISTURID BETWEEN 1 AND 49 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_BANKA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUH_FIS_BANKA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=4 AND FISTURID BETWEEN 3 AND 4 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_CARI]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUH_FIS_CARI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=2 AND FISTURID BETWEEN 1 AND 36 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_CEKSENET]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUH_FIS_CEKSENET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=5 AND FISTURID BETWEEN 21 AND 36 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_DIGER]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUH_FIS_DIGER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE FISTURID BETWEEN 1 AND 36 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_KASA]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUH_FIS_KASA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=3 AND FISTURID BETWEEN 1 AND 2 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_KASA_01022021]    Script Date: 17.07.2026 15:19:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUH_FIS_KASA_01022021]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=3 AND FISTURID BETWEEN 1 AND 2 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_MOBIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUH_FIS_MOBIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FISID, FIRMAID, SUBEID,MASMERID,FISTURID,FISDURUMID,TARIH,VADE,FISTURU,ACIKLAMA,BELGENO,
FISHESAPID,DOVIZ,KUR,TOPLAM,OZELKOD1,ISLEMGRUPID1,ADD_DATE,ADD_USERID,
KARSIHESAPID,DETAYLIENTEGRE,AKTARIMSTATUID,SIL FROM MUH_FIS WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_MUH]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUH_FIS_MUH]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_MUH_02042021]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


create PROCEDURE [dbo].[PRL_MUH_FIS_MUH_02042021]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=1 AND FISTURID BETWEEN 41 AND 49 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_FIS_PERSONEL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUH_FIS_PERSONEL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_FIS WITH (NOLOCK) WHERE MODULID=11 AND FISTURID BETWEEN 1 AND 9 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_HESAPISL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUH_HESAPISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAPISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_HESAPISL_MOBIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUH_HESAPISL_MOBIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FISID,HESAPID,MASMERID,ACIKLAMA,DOVIZ,KUR,TUTAR,DTUTAR,BORC,ALACAK,
ISLEMGRUPID1,OZELKOD1,BELGENO FROM MUH_HESAPISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUH_HESAPYANSITMA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUH_HESAPYANSITMA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAPYANSITMA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUHCARI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP_ALTCARI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_ALICI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUHCARI_ALICI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID=120 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_BANKA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUHCARI_BANKA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID IN (102,108) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_CARI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUHCARI_CARI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID IN(120,320,340,159) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_CEK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUHCARI_CEK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID IN (101,103) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_DIGER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHCARI_DIGER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP_ALTCARI WITH (NOLOCK) WHERE HESAPTIPID NOT IN(100,102,101,103,120,320,335,340,159) AND AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_GIDER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHCARI_GIDER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP_ALTCARI WITH (NOLOCK) WHERE HESAPTIPID=7 AND AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_KASA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUHCARI_KASA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID=100 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHCARI_PERSONEL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_MUHCARI_PERSONEL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_HESAP WITH (NOLOCK) WHERE HESAPTIPID IN(196,335) AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHDONEM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUHDONEM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUHDONEM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUHGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_DEPARTMAN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_DEPARTMAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=9 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_HESAPGRUBU1]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_HESAPGRUBU1]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=1 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_HESAPGRUBU2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_HESAPGRUBU2]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=2 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_ISLEMGRUBU1]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_ISLEMGRUBU1]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=3 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_ISLEMGRUBU2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_ISLEMGRUBU2]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=4 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_ISLEMGRUBU3]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUHGRUP_ISLEMGRUBU3]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=5 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_MMERKEZI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUHGRUP_MMERKEZI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=6 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_OZELKOD]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUHGRUP_OZELKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=8 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUHGRUP_PROJEKODU]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUHGRUP_PROJEKODU]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=7 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUSTAHSIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUSTAHSIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATURA.*,EFATNO,EFATTURU,EDEVLETDURUM,EFATURADURUM 
FROM FATURA WITH (NOLOCK) LEFT OUTER JOIN FATURADETAY WITH (NOLOCK) ON FATURA.FATID=FATURADETAY.FATID 
WHERE FISDURUMID=3 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUSTERIDAIRE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_MUSTERIDAIRE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM MUH_GRUP WITH (NOLOCK) WHERE TIPID=8 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUSTISL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUSTISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FATISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUTABAKAT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_MUTABAKAT]
@FIRMAID NVARCHAR(10),
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10)
AS
BEGIN
SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEM, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEMSONU, 

 SUM(CASE WHEN TARIH>@SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS SONRAKIDONEM, 

 SUM(BORC-ALACAK) AS SONBAKIYE, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END) AS DONCEKIDONEM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN DBORC-DALACAK ELSE 0 END) AS DDONEM, 

 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DDONEMSONU, 

 SUM(CASE WHEN TARIH>@SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DSONRAKIDONEM, 

 SUM(DBORC-DALACAK) AS DSONBAKIYE, 

  

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
 FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL2        
 INNER JOIN 
 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
       AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
	   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
	   WHERE 1=1  AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUTABAKAT2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_MUTABAKAT2]
@FIRMAID NVARCHAR(10),
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10),
@FATURADAHIL NVARCHAR(1)
AS
BEGIN
IF @FATURADAHIL='0'
	BEGIN
			SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
			CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
			SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS SONRAKIDONEM, 

			 SUM(BORC-ALACAK) AS SONBAKIYEAA, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END) AS DONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN DBORC-DALACAK ELSE 0 END) AS DDONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DDONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DSONRAKIDONEM, 

			 SUM(DBORC-DALACAK) AS DSONBAKIYE, 

  

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
			 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
			 FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL2        
			 INNER JOIN 
			 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
			 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
				   AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
				   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
				   WHERE 1=1  AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
	END
ELSE
	BEGIN
			SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
			CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
			SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS SONRAKIDONEM, 

			 SUM(BORC-ALACAK) AS SONBAKIYE, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END) AS DONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN DBORC-DALACAK ELSE 0 END) AS DDONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DDONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DSONRAKIDONEM, 

			 SUM(DBORC-DALACAK) AS DSONBAKIYE, 

  

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
			 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
			 FROM FNCQ_QMUHMIZAN_FATURA(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL2        
			 INNER JOIN 
			 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
			 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
				   AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
				   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
				   WHERE 1=1  AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_MUTABAKAT3]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_MUTABAKAT3]
@FIRMAID NVARCHAR(10),
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10),
@FATURADAHIL NVARCHAR(1),
@ILKKOD NVARCHAR(20),
@SONKOD NVARCHAR(20)
AS
BEGIN
IF @ILKKOD='' SET @ILKKOD='0';
IF @SONKOD='' SET @SONKOD='999';
IF @FATURADAHIL='0'
	BEGIN
			SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
			CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
			SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS DONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN ISNULL(BORC,0)-ISNULL(ALACAK,0) ELSE 0 END) AS DONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH  THEN BORC-ALACAK ELSE 0 END) AS SONRAKIDONEM, 

			 SUM(BORC)-SUM(ALACAK) AS SONBAKIYE, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END) AS DONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN DBORC-DALACAK ELSE 0 END) AS DDONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN DBORC-DALACAK ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DDONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH THEN DBORC-DALACAK ELSE 0 END) AS DSONRAKIDONEM, 

			 SUM(DBORC)-SUM(DALACAK) AS DSONBAKIYE, 

  

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
			 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
			 FROM FNCQ_QMUHMIZAN(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL2        
			 INNER JOIN 
			 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
			 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
				   AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
				   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
				   WHERE 1=1  AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
	END
ELSE
	BEGIN
			SELECT * FROM  (SELECT  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1, 
			CAST(@ILKTARIH AS DATETIME)  AS BASTARIH ,CAST(@SONTARIH AS DATETIME)  AS SONTARIH, 
			SUM(CASE WHEN TARIH<@ILKTARIH THEN BORC-ALACAK ELSE 0 END) AS ONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN ISNULL(BORC,0)-ISNULL(ALACAK,0) ELSE 0 END) AS DONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN ISNULL(BORC,0)-ISNULL(ALACAK,0) ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN ISNULL(BORC,0)-ISNULL(ALACAK,0) ELSE 0 END) AS DONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH  THEN ISNULL(BORC,0)-ISNULL(ALACAK,0) ELSE 0 END) AS SONRAKIDONEM, 

			 SUM(BORC)-SUM(ALACAK) AS SONBAKIYE, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH THEN 1 ELSE 0 END) AS DONEMISLEMADET, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END) AS DONCEKIDONEM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END) AS DDONEM, 

			 SUM(CASE WHEN TARIH<@ILKTARIH THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END)+SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND  @SONTARIH THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END) AS DDONEMSONU, 

			 SUM(CASE WHEN TARIH>@SONTARIH THEN ISNULL(DBORC,0)-ISNULL(DALACAK,0) ELSE 0 END) AS DSONRAKIDONEM, 

			 SUM(DBORC)-SUM(DALACAK) AS DSONBAKIYE, 

  

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN 1 ELSE 0 END) AS DONEM_ALISFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH  AND FISTURID IN (52,54,62,64) THEN 1 ELSE 0 END) AS DONEM_SATFAT_ADET, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_ALISFAT_TOPLAM_DOVIZ, 

			 SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN DBORC+DALACAK ELSE 0 END) AS DONEM_SATFAT_TOPLAM_DOVIZ, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (51,53,61,63,65,66,67,68) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BA, 

			 CASE WHEN (SUM(CASE WHEN TARIH BETWEEN @ILKTARIH AND @SONTARIH AND FISTURID IN (52,54,62,64) THEN BORC+ALACAK ELSE 0 END))>5000 THEN 1 ELSE 0 END AS BS  FROM      
			 (SELECT  QMUH_HESAPISL2.HESAPID   HESAPID ,M.KODU HESAPKODU,M.ACIKLAMA HESAPADI,M.VD,M.VDNO,M.DOVIZ,M.TEL1,M.TEL2,M.FAX,M.EMAIL,M.YETKILI,'' OZELKOD1 ,TARIH,FISTURID,BORC,ALACAK,DBORC,DALACAK 
			 FROM FNCQ_QMUHMIZAN_FATURA(@ILKTARIH,@SONTARIH,@FIRMAID) AS QMUH_HESAPISL2        
			 INNER JOIN 
			 (SELECT HESAPID HID,KODU,ACIKLAMA,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI FROM MUH_HESAP (NOLOCK)) AS M  ON  QMUH_HESAPISL2.HESAPID  =M.HID        
			 WHERE QMUH_HESAPISL2.HESAPTIPID IN (120,320) 
				   AND (QMUH_HESAPISL2.TARIH  BETWEEN @ILKTARIH AND @SONTARIH)      ) TBL    
				   GROUP BY  HESAPID,HESAPKODU,HESAPADI,VD,VDNO,DOVIZ,TEL1,TEL2,FAX,EMAIL,YETKILI,OZELKOD1  ) AS ANATBL  
				   WHERE 1=1 AND (DONEMISLEMADET>0 OR DONEMSONU<>0) ORDER BY HESAPKODU
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAERISIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_NOVAERISIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVAERISIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAEXE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_NOVAEXE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVAEXE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAHATA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_NOVAHATA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVAHATA WITH (NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVALOG]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_NOVALOG]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVALOG WITH (NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAUSER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_NOVAUSER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVAUSER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAUSERD]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_NOVAUSERD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM NOVAUSERD WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAVERSIYON]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_NOVAVERSIYON]
AS
select VERSIYONNO,YAYINNO from NOVAVERSIYON
GO
/****** Object:  StoredProcedure [dbo].[PRL_NOVAYETKIDUZELT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_NOVAYETKIDUZELT] @USERID NVARCHAR(10), @FIRMAID NVARCHAR(10), @YETKI NVARCHAR(10)
AS
BEGIN
	DECLARE @SQLCUMLE NVARCHAR(500)
	IF @YETKI='SIL-'    SET @SQLCUMLE='UPDATE NOVAUSERD SET SIL=0 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='SIL+'    SET @SQLCUMLE='UPDATE NOVAUSERD SET SIL=1 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='DUZELT-' SET @SQLCUMLE='UPDATE NOVAUSERD SET DUZELT=0 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='DUZELT+' SET @SQLCUMLE='UPDATE NOVAUSERD SET DUZELT=1 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='EKLE-'   SET @SQLCUMLE='UPDATE NOVAUSERD SET YENI=0 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='EKLE+'   SET @SQLCUMLE='UPDATE NOVAUSERD SET YENI=1 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='EKRAN-'   SET @SQLCUMLE='UPDATE NOVAUSERD SET EKRANAC=0 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	IF @YETKI='EKRAN+'   SET @SQLCUMLE='UPDATE NOVAUSERD SET EKRANAC=1 WHERE NOVAUSERID='+@USERID+' AND FIRMAID='+@FIRMAID
	EXEC(@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ODEMELOG]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ODEMELOG]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ODEMELOG WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_OIVTANIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OIVTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KDVMUAFTANIM WITH (NOLOCK) WHERE TIP=4 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_OKC_TUKETIMFIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OKC_TUKETIMFIS] @FIRMAID INT, @DEPOFISID INT,@OKCMARKA NVARCHAR(20)
AS
IF @OKCMARKA='BEKO'
	BEGIN
		SELECT TARIH,FIRMAID,SUBEID,DEPOFISID,INDORAN,INDTUTAR,TTUTAR,TOPLAM,ACIK,NAKIT,KKARTI,TICKET1,FUNVANI,FVDNO,OKCFISNO,SIL FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND DEPOFISID=@DEPOFISID
	END
ELSE IF @OKCMARKA='INPOS'
	BEGIN
		SELECT TARIH,FIRMAID,SUBEID,DEPOFISID,INDORAN,INDTUTAR,TTUTAR*100 as TTUTAR,TOPLAM*100 AS TOPLAM,ACIK*100 AS ACIK,NAKIT*100 AS NAKIT,KKARTI*100 AS KKARTI,TICKET1*100 AS TICKET1,FUNVANI,FVDNO,OKCFISNO,SIL FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND DEPOFISID=@DEPOFISID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_OKCFIS2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OKCFIS2]  
@DEPOFISID INT,
@MARKA NVARCHAR(15),
@SATISMODUL NVARCHAR(20),
@DETAYLIMI NVARCHAR(5),
@FIRMAID NVARCHAR(10)
AS
BEGIN
IF @DETAYLIMI='HAYIR'
	BEGIN
		IF (@SATISMODUL='SATIS') and (@MARKA='HUGIN')
			BEGIN	
				SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				SUBSTRING(ISNULL(GG.ADI,GG2.ADI),1,20) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID  AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID  
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID  GROUP BY
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0
			END
		IF (@SATISMODUL='SATIS') and (@MARKA='BEKO')
			BEGIN	
				SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				DBO.FN_TURKCELE(SUBSTRING(ISNULL(GG.ADI,GG2.ADI),1,20)) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID 
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID 
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID  GROUP BY   /*3084122 */
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0
			END
		IF (@SATISMODUL='SATIS') and (@MARKA='INPOS')  /*İNPOS X100 2 SIFIR DAHA EKLİYORUZ */
			BEGIN	
				SELECT DEPOFISID,OKCKDVID,GELIRKODU,GELIRADI,KDVORAN, 1000.00 AS MIKTAR, SUM(BFIYAT) AS BFIYAT,
				SUM(TOPLAM) AS TOPLAM FROM (SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				DBO.FN_TURKCELE(SUBSTRING(ISNULL(GG.ADI,GG2.ADI),1,12)) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, AVG(1000) AS MIKTAR, 
				SUM(FMIKTAR*((FBFIYAT*ISNULL(DKURU,1))/100*(100-INDORAN)))*100 AS BFIYAT,  
				SUM(FMIKTAR*((FBFIYAT*ISNULL(DKURU,1))/100*(100-INDORAN)))*100 AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID  AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU  AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU  AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID   GROUP BY   /*3084122 */
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV  HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0) AS TBL
				GROUP BY DEPOFISID,OKCKDVID,GELIRKODU,GELIRADI,KDVORAN
			END
		IF (@SATISMODUL='POSSATIS') AND (@MARKA='HUGIN')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID  
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE TI.FISCOUNTER=@DEPOFISID  GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
		IF (@SATISMODUL='POSSATIS_PARCALI') AND (@MARKA='HUGIN')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID 
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE TI.FISCOUNTER=@DEPOFISID  GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
		IF (@SATISMODUL='POSSATIS') AND (@MARKA='BEKO')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
				WHERE TI.FISCOUNTER=@DEPOFISID AND S.FIRMAID=@FIRMAID AND SG.FIRMAID=@FIRMAID AND GG.FIRMAID=@FIRMAID AND GG2.FIRMAID=@FIRMAID GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
	END
ELSE
	BEGIN
	/*STOK DETAYLI */

		IF (@SATISMODUL='SATIS') and (@MARKA='HUGIN')
			BEGIN	
				SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				SUBSTRING(ISNULL(GG.ADI,GG2.ADI),1,20) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID  AND S.FIRMAID=@FIRMAID 
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU  AND GG.FIRMAID=@FIRMAID 
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID  GROUP BY
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0
			END
		IF (@SATISMODUL='SATIS') and (@MARKA='BEKO')
			BEGIN	
				SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				DBO.FN_TURKCELE(SUBSTRING(ISNULL(S.ADI,GG2.ADI),1,20)) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN))) AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU  AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID  GROUP BY   /*3084122 */
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,S.ADI,GG2.ADI,GG.KDV,GG2.KDV HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0 
			END
		IF (@SATISMODUL='SATIS') and (@MARKA='INPOS') /*X100 2 SIFIR DAHA */
			BEGIN	
				SELECT TI.DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				DBO.FN_TURKCELE(SUBSTRING(ISNULL(S.ADI,GG2.ADI),1,12)) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, SUM(FMIKTAR)*1000 AS MIKTAR, 
				AVG(((FBFIYAT*ISNULL(DKURU,1))/100*(100-INDORAN)))*100 AS BFIYAT,  
				SUM(FMIKTAR*((FBFIYAT*ISNULL(DKURU,1))/100*(100-INDORAN)))*100 AS TOPLAM FROM TUKETIMFISISL AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID 
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE ISNULL(TI.SILINDI,0)=0 AND  DEPOFISID=@DEPOFISID  GROUP BY   /*3084122 */
				TI.DEPOFISID,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,S.STOKID,S.ADI,GG2.ADI,GG.KDV,GG2.KDV,FBFIYAT,DKURU HAVING SUM(FMIKTAR*(FBFIYAT/100*(100-INDORAN)))>0
			END
		IF (@SATISMODUL='POSSATIS') AND (@MARKA='HUGIN')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID 
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID AND SG.FIRMAID=@FIRMAID 
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE TI.FISCOUNTER=@DEPOFISID AND S.FIRMAID=@FIRMAID   GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
		IF (@SATISMODUL='POSSATIS_PARCALI') AND (@MARKA='HUGIN')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID 
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU 
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU 
				WHERE TI.FISCOUNTER=@DEPOFISID AND S.FIRMAID=@FIRMAID AND SG.FIRMAID=@FIRMAID AND GG.FIRMAID=@FIRMAID AND GG2.FIRMAID=@FIRMAID GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
		IF (@SATISMODUL='POSSATIS') AND (@MARKA='BEKO')
			BEGIN
				SELECT TI.FISCOUNTER AS DEPOFISID,ISNULL(GG.OKCKDVID,GG2.OKCKDVID) AS OKCKDVID, ISNULL(GG.KODU,GG2.KODU) AS GELIRKODU, 
				ISNULL(GG.ADI,GG2.ADI) AS GELIRADI, ISNULL(GG.KDV,GG2.KDV) AS KDVORAN, 1.00 AS MIKTAR, 
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS BFIYAT,  
				SUM(ADET*(BIRIMFIYAT/100*(100-INDORAN))) AS TOPLAM FROM ADSSATIR AS TI WITH (NOLOCK)
				INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID AND S.FIRMAID=@FIRMAID
				LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID  AND SG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG WITH (NOLOCK) ON S.GGRUP=GG.KODU  AND GG.FIRMAID=@FIRMAID
				LEFT JOIN GELIRGRUP AS GG2 WITH (NOLOCK) ON SG.POSGRUBU=GG2.KODU AND GG2.FIRMAID=@FIRMAID
				WHERE TI.FISCOUNTER=@DEPOFISID  GROUP BY
				TI.FISCOUNTER,GG.OKCKDVID,GG2.OKCKDVID,GG.KODU,GG2.KODU,GG.ADI,GG2.ADI,GG.KDV,GG2.KDV
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_OTVTANIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OTVTANIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM KDVMUAFTANIM WITH (NOLOCK) WHERE TIP=3 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_OZELRAPORLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OZELRAPORLAR] @FIRMAID INT
AS
SELECT 10000+DINAMIKRAPORID AS EKRANID,RAPORFIRMAID,99 AS EKRANSIRA,0 AS EKRANMI,'tfstdrapor' AS FORMADI,
RAPORADI AS EKRANADI,36 AS RESIMINDEX,33 AS RESIMINDEX32,33 AS TREERESIMINDEX, 0 AS SECINDEX,0 AS ANAMODULMU,
ANAEKRANID AS BAGLIMODULID,1 AS AKTIF,0 AS YENIISLEM, NULL AS FISTURID,1 AS TABICINDE
FROM DINAMIKRAPOR WHERE ANAEKRANID>0 AND OZELRAPOR=1 AND RAPORFIRMAID=@FIRMAID AND 10000+DINAMIKRAPORID NOT IN(SELECT EKRANID FROM EKRANLAR)
UNION ALL
SELECT 10000+DINAMIKRAPORID AS EKRANID,RAPORFIRMAID,99 AS EKRANSIRA,0 AS EKRANMI,'tfstdrapor' AS FORMADI,
RAPORADI AS EKRANADI,36 AS RESIMINDEX,33 AS RESIMINDEX32,33 AS TREERESIMINDEX, 0 AS SECINDEX,0 AS ANAMODULMU,
ANAEKRANID AS BAGLIMODULID,1 AS AKTIF,0 AS YENIISLEM, NULL AS FISTURID,1 AS TABICINDE
FROM DINAMIKRAPOR WHERE ANAEKRANID>0 AND OZELRAPOR=1 AND ISNULL(RAPORFIRMAID,0)=0 AND 10000+DINAMIKRAPORID NOT IN(SELECT EKRANID FROM EKRANLAR)
GO
/****** Object:  StoredProcedure [dbo].[PRL_OZETSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_OZETSATIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(900)
AS
SET NOCOUNT ON
BEGIN
DECLARE @SQLCUMLE NVARCHAR(1500)
SET @SQLCUMLE='SELECT NOVAUSER.ADSOYAD, SUM(TTUTAR) AS BRUTSATIS, 
SUM(TTUTAR)-SUM(TOPLAM) AS INDTUTAR, 
SUM(TOPLAM) AS NETSATIS, SUM(NAKIT) AS NAKIT, 
SUM(KKARTI) AS KKARTI, SUM(ACIK) AS ACIK, 
SUM(TICKET1) AS TICKET1,
SUM(TICKET2) AS TICKET2,
SUM(TICKET3) AS TICKET3,
SUM(TICKET4) AS TICKET4,
SUM(TICKET5) AS TICKET5,
SUM(TOPLAM)-SUM(NAKIT+KKARTI+ACIK) AS BEKLEME
FROM TUKETIMFIS LEFT JOIN NOVAUSER ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY NOVAUSER.ADSOYAD'
SET @SQLCUMLE=REPLACE(@SQLCUMLE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @SQLCUMLE=REPLACE(@SQLCUMLE,'SUBEID','TUKETIMFIS.SUBEID')
SET @SQLCUMLE=REPLACE(@SQLCUMLE,'(SIL','(TUKETIMFIS.SIL')
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PAKETFIYATSEC]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_PAKETFIYATSEC] @DOVIZ NVARCHAR(5), @TARIH NVARCHAR(10), @GUNSAYI NVARCHAR(5), @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM HSPAKETFIYAT WHERE ISNULL(SIL,0)=0 AND
DOVIZ='''+@DOVIZ+''' AND GUNSAYISI='+@GUNSAYI+' AND '''+@TARIH+'''>=ILKTARIH AND '''+@TARIH+'''<=SONTARIH
 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PAKETIND]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PAKETIND] @PAKETFIYAT FLOAT, @STOKID INT 
AS
SELECT 100-(@PAKETFIYAT/(SELECT SUM(FIYAT) FROM STOKPAKET WHERE STOKID=@STOKID)*100) AS INDYUZDE FROM STOK WHERE STOKID=@STOKID
GO
/****** Object:  StoredProcedure [dbo].[PRL_PAKETSEC]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_PAKETSEC]  @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP 1 HSPAKETID,GUNSAYISI,CSVKODU,QRKOD,SATILDI FROM HSPAKET WITH (NOLOCK) INNER JOIN HSPAKETFIS WITH (NOLOCK) ON 
HSPAKET.HSPAKETFISID=HSPAKETFIS.HSPAKETFISID WHERE ISNULL(HSPAKETFIS.SIL,0)=0 AND ISNULL(SATILDI,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERADAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE PROCEDURE [dbo].[PRL_PERADAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERADAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERADAYDOSYA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_PERADAYDOSYA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERADAYDOSYA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERAKENDE_KASA_DOVIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERAKENDE_KASA_DOVIZ]   @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'SUBEID','TUKETIMFIS.SUBEID')
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @SQLCUMLE='SELECT TARIH, SUBELER.SUBEADI,DEPO.DEPOADI, TUKETIMFIS.SUBEID, CDEPOID, 
SUM(TOPLAM) AS TOPLAMTL, (CASE WHEN SUM(ISNULL(TOPLAM,0)/NULLIF(ISNULL(DKURU,0),0)) 
IS NULL THEN SUM(TOPLAM) 
ELSE SUM(ISNULL(TOPLAM,0)/NULLIF(ISNULL(DKURU,0),0)) END) AS DOVIZTUTAR, 
ISNULL(DKODU,''TL'') AS DKODU FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER 
WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID
WHERE ISLEM=''SATIS'' AND ISNULL(TUKETIMFIS.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,TUKETIMFIS.SUBEID,CDEPOID,DKODU,SUBELER.SUBEADI,DEPO.DEPOADI ORDER BY DKODU,TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERAKENDE_KASIYER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERAKENDE_KASIYER]   @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
SET @PARAMETRE=REPLACE(@PARAMETRE,'SUBEID','TUKETIMFIS.SUBEID')
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @SQLCUMLE='SELECT TARIH, NOVAUSER.ADSOYAD, SUBELER.SUBEADI,DEPO.DEPOADI, TUKETIMFIS.SUBEID, CDEPOID, 
SUM(TOPLAM) AS TOPLAMTL, (CASE WHEN SUM(ISNULL(TOPLAM,0)/NULLIF(ISNULL(DKURU,0),0)) 
IS NULL THEN SUM(TOPLAM) 
ELSE SUM(ISNULL(TOPLAM,0)/NULLIF(ISNULL(DKURU,0),0)) END) AS DOVIZTUTAR, 
ISNULL(DKODU,''TL'') AS DKODU FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN SUBELER 
WITH (NOLOCK) ON TUKETIMFIS.SUBEID=SUBELER.SUBEID
INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID
LEFT JOIN NOVAUSER ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID
WHERE ISLEM=''SATIS'' AND ISNULL(TUKETIMFIS.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,TUKETIMFIS.SUBEID,CDEPOID,DKODU,NOVAUSER.ADSOYAD,SUBELER.SUBEADI,DEPO.DEPOADI ORDER BY NOVAUSER.ADSOYAD,TARIH,DKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERAKENDE_SATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_PERAKENDE_SATIS]  @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'CDEPOID','DEPOID')
SET @SQLCUMLE='SELECT TARIH,GRUPKODU,GRUPADI,STOKKODU,STOKADI,SUM(FADET) AS MIKTAR,FBIRIM, 
SUM(FADET*NFIYAT)/NULLIF(ISNULL(SUM(FADET),0),0) AS BIRIMFIYAT, SUM(FADET*NFIYAT) AS TOPLAM 
FROM [FNCQ_STOKISLEMLER] ('''+@TARIH1+''','''+@TARIH2+''','+@FIRMAID+') WHERE ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,GRUPKODU,GRUPADI,STOKKODU,STOKADI,FBIRIM ORDER BY TARIH,GRUPKODU,STOKADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERAKENDE_SATIS_GRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERAKENDE_SATIS_GRUP]  @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'CDEPOID','DEPOID')
SET @SQLCUMLE='SELECT TARIH,GRUPKODU,GRUPADI,SUM(FADET) AS MIKTAR, 
SUM(FADET*NFIYAT)/NULLIF(ISNULL(SUM(FADET),0),0) AS BIRIMFIYAT, SUM(FADET*NFIYAT) AS TOPLAM 
FROM [FNCQ_STOKISLEMLER] ('''+@TARIH1+''','''+@TARIH2+''','+@FIRMAID+') WHERE ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+'
GROUP BY TARIH,GRUPKODU,GRUPADI ORDER BY TARIH,GRUPKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERBUTCEGIRIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_PERBUTCEGIRIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERBUTCEGIRIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERBUTCEKUR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERBUTCEKUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM PERBUTCEKUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERDEPART]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_PERDEPART]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERDEPART WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERELEKTRADEP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERELEKTRADEP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERELEKTRADEP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERELEKTRASICIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERELEKTRASICIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERELEKTRASICIL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERELEKTRAUNV]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERELEKTRAUNV]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERELEKTRAUNV WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERSAYISI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_PERSAYISI] @SUBEID INT, @DEPARTMANID INT
AS
SELECT COUNT(*) AS SAYI FROM IKPERSONEL WHERE ISTENAYRILIS IS NULL AND SUBEID=@SUBEID AND DEPARTMANID=@DEPARTMANID
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERSEBEP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE PROCEDURE [dbo].[PRL_PERSEBEP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERSEBEP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERSONEL_MESAI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERSONEL_MESAI]  @SICILID INT, @FIRMAID INT
AS
BEGIN
if ABS(@SICILID)>0
	BEGIN
		SELECT IKFAZLAMESAI.FIRMAID,IKFAZLAMESAI.SUBEID, SUBELER.SUBEADI,YEAR(MESAITARIHI) AS MESAIYIL, MONTH(MESAITARIHI) AS AY, MESAITARIHI,FMD.PSICILID, PER.ADSOYAD, 
		PERDEPART.DEPKODU,PERDEPART.DEPADI, MT.MESAIADI,MESAIGEREKCESI,MESAISAATI,IKACIKLAMA,OPRACIKLAMA,ISNULL(KULLANDI,0) AS KULLANDI  
		FROM IKFAZLAMESAI_DETAY FMD INNER JOIN  IKFAZLAMESAI ON FMD.IKFAZLAMESAIID=IKFAZLAMESAI.IKFAZLAMESAIID LEFT JOIN IKFAZLAMESAITANIM AS MT ON FMD.MESAIGEREKCEID=MT.IKFAZLAMESAITANIMID
		INNER JOIN IKPERSONEL AS PER ON  FMD.PSICILID=PER.PSICILID
		LEFT JOIN PERDEPART ON PER.DEPARTMANID=PERDEPART.PERDEPARTMANID
		INNER JOIN SUBELER ON IKFAZLAMESAI.SUBEID=SUBELER.SUBEID
		WHERE ISNULL(IKFAZLAMESAI.SIL,0)=0 AND IKFAZLAMESAI.FIRMAID=@FIRMAID
	END
ELSE
	BEGIN
		SELECT IKFAZLAMESAI.FIRMAID,IKFAZLAMESAI.SUBEID, SUBELER.SUBEADI,YEAR(MESAITARIHI) AS MESAIYIL, MONTH(MESAITARIHI) AS AY, MESAITARIHI,FMD.PSICILID, PER.ADSOYAD, 
		PERDEPART.DEPKODU,PERDEPART.DEPADI, MT.MESAIADI,MESAIGEREKCESI,MESAISAATI,IKACIKLAMA,OPRACIKLAMA,ISNULL(KULLANDI,0) AS KULLANDI  
		FROM IKFAZLAMESAI_DETAY FMD INNER JOIN  IKFAZLAMESAI ON FMD.IKFAZLAMESAIID=IKFAZLAMESAI.IKFAZLAMESAIID LEFT JOIN IKFAZLAMESAITANIM AS MT ON FMD.MESAIGEREKCEID=MT.IKFAZLAMESAITANIMID
		INNER JOIN IKPERSONEL AS PER ON  FMD.PSICILID=PER.PSICILID
		LEFT JOIN PERDEPART ON PER.DEPARTMANID=PERDEPART.PERDEPARTMANID
		INNER JOIN SUBELER ON IKFAZLAMESAI.SUBEID=SUBELER.SUBEID
		WHERE ISNULL(IKFAZLAMESAI.SIL,0)=0 AND FMD.PSICILID=@SICILID and IKFAZLAMESAI.FIRMAID=@FIRMAID

END

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERSSKPARAMETRE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_PERSSKPARAMETRE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERSSKPARAMETRE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PERUNVAN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PERUNVAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PERUNVAN WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PING]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_PING]
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(100)
SET @SQLCUMLE='SELECT TOP 0 * FROM PING WITH (NOLOCK)'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSCARIHESAP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSCARIHESAP]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT                 
MUSTERIID,CARIUNVANI AS UNVANI,                                                            
COUNT(*) AS ADISYON,
SUM(ISNULL(KISI,0)) AS KISI,
SUM(ISNULL(ONAKIT,0)) AS NAKIT,                                        
SUM(ISNULL(OKK,0)) AS KK,                                        
SUM(ISNULL(OTICKET,0)) AS TICKET,                                        
SUM(ISNULL(OTICKET2,0)) AS TICKET2,                                        
SUM(ISNULL(OTICKET3,0)) AS TICKET3,                                        
SUM(ISNULL(OTICKET4,0)) AS TICKET4,                                        
SUM(ISNULL(OACIK,0)) AS ACIK,                                        
SUM(ISNULL(TOPLAM,0)) AS TOPLAM
FROM [FNCQ_ADISYON] ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') AS ADISYON                                                                          
WHERE CARIUNVANI<>'''' AND 1=1 '+@PARAMETRE+'   
GROUP BY MUSTERIID, CARIUNVANI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSCARISATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSCARISATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT KASIYER AS YETKILIKODU, CARIUNVANI AS UNVANI, TUR,GRUPADI AS GRUBU,URUNADI AS URUN,
SUM(ADET) AS ADET, SUM(TOPLAM) AS TUTAR, SUM(MALIYETTOPLAM) AS MALIYET, 
SUM(NETTOPLAM) AS NETSATIS, SUM(INDTUTAR) AS INDIRIM, 
SUM(NETTOPLAM-MALIYETTOPLAM) AS KAR FROM   FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') 
WHERE CARIUNVANI<>'''' AND 1=1 '+@PARAMETRE+' GROUP BY KASIYER,CARIUNVANI,TUR,GRUPADI,URUNADI
ORDER BY UNVANI, SUM(NETTOPLAM)'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSDEPOFISOLUSTUR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_POSDEPOFISOLUSTUR]  
@TARIH SMALLDATETIME,
@CDEPOIDYIYECEK INT,
@CDEPOIDICECEK INT,
@CDEPOIDDIGER INT,
@SUBEID INT,
@FIRMAID INT,
@DEPID INT
AS
BEGIN
DECLARE
@GUID uniqueidentifier = NEWID(),
@DEPOFISID INT
DELETE FROM DEPOFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=CAST(@DEPID AS NVARCHAR(10)) AND ISLEM='SATIS' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH)
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=CAST(@DEPID AS NVARCHAR(10)) AND ISLEM='SATIS' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH
DELETE FROM DEPOFISISL WHERE DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=CAST(@DEPID AS NVARCHAR(10)) AND ISLEM='ODENMEZ' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH)
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND SDEPART=CAST(@DEPID AS NVARCHAR(10)) AND ISLEM='ODENMEZ' AND ACIKLAMA='POS AKTARIM' AND TARIH=@TARIH

if (SELECT ISNULL(COUNT(*),0) FROM ADSSATIR WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH))>0
	BEGIN
		
		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON  AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDYIYECEK>0
					BEGIN
						--YIYECEK SATISLAR

						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,CSUBEID,SDEPART) 
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDYIYECEK, @FIRMAID, @SUBEID, CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT,'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDYIYECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK)  ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID 
						 WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0
						 GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD  WITH (NOLOCK)INNER JOIN ADSSATIR AS ADS ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDICECEK>0
					BEGIN
						SET @GUID=NEWID()
						--ICECEK SATISLARI
				
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDICECEK, @FIRMAID,@SUBEID,CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0
						GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDDIGER>0 
					BEGIN
						SET @GUID=NEWID()
						--DIGER SATISLARI
						
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'SATIS' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDDIGER, @FIRMAID,@SUBEID, CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS BFIYAT,  'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN)  AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR<>'ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0
						GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END
	END

if (SELECT ISNULL(COUNT(*),0) FROM ADSSATIR WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WITH (NOLOCK) WHERE TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH))>0
	BEGIN
		
		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD  WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDYIYECEK>0
					BEGIN
						SET @GUID=NEWID()
						--YIYECEK ODENMEZ
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDYIYECEK, @FIRMAID, @SUBEID, CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDYIYECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND ISNULL(POSTURU,1)=1 and ISNULL(AD.SIL,0)=0
						GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
		
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDICECEK>0
					BEGIN
						SET @GUID=NEWID()
				
						--ICECEK ODENMEZ
						
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDICECEK,@FIRMAID, @SUBEID,CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS  WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE  AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU=2 and ISNULL(AD.SIL,0)=0
						GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END
			END

		IF (SELECT ISNULL(COUNT(*),0) FROM ADISYON AS AD INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0)>0
			BEGIN
				IF @CDEPOIDDIGER>0
					BEGIN
						SET @GUID=NEWID()
						--DIGER ODENMEZ
						INSERT INTO DEPOFIS (DEPOFISUUID,TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,CSUBEID,SDEPART)
						SELECT @GUID, @TARIH, 'SYSTEM' AS YETKILI,'ODENMEZ' AS ISLEM,'POS AKTARIM' AS ACIKLAMA, @CDEPOIDDIGER, @SUBEID, CAST(@DEPID AS NVARCHAR(10))

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,ACIKLAMA,FBFIYAT,RCDEPOID)
						SELECT @DEPOFISID AS DEPOFISID,ADS.STOKID,SUM(ADET) AS MIKTAR, S.BIRIM AS FBIRIM,SUM(ADET) AS FMIKTAR,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS BFIYAT, 'SYSTEM' AS YETKILI,'Pos Aktarım' AS ACIKLAMA,
						BIRIMFIYAT/100*(100-AD.INDORAN) AS FBFIYAT, @CDEPOIDICECEK FROM ADISYON AS AD WITH (NOLOCK) INNER JOIN ADSSATIR AS ADS WITH (NOLOCK) ON AD.FISCOUNTER=ADS.FISCOUNTER
						 INNER JOIN STOK AS S WITH (NOLOCK) ON ADS.STOKID=S.STOKID WHERE  AD.FIRMAID=@FIRMAID AND AD.SUBEID=@SUBEID AND S.FIRMAID=@FIRMAID AND  TUR='ODENMEZ' AND DEPID=@DEPID AND TARIH=@TARIH AND POSTURU>=3 and ISNULL(AD.SIL,0)=0
						GROUP BY ADS.STOKID,S.BIRIM,BIRIMFIYAT,AD.INDORAN
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL  WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID
					END

			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSGARSONANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSGARSONANALIZ]  @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),   @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1900)
SET @SQLCUMLE='SELECT                 
GARSONKODU,GARSONADI AS GADI,                                                              
COUNT(*) AS ADISYON,
SUM(ISNULL(KISI,0)) AS KISI,
SUM(ISNULL(ONAKIT,0)) AS NAKIT,                                        
SUM(ISNULL(OKK,0)) AS KK,                                        
SUM(ISNULL(OTICKET,0)) AS TICKET,                                        
SUM(ISNULL(OTICKET2,0)) AS TICKET2,                                        
SUM(ISNULL(OTICKET3,0)) AS TICKET3,                                        
SUM(ISNULL(OTICKET4,0)) AS TICKET4,                                        
SUM(ISNULL(OACIK,0)) AS ACIK,                                        
SUM(ISNULL(TOPLAM,0)) AS TOPLAM
FROM [FNCQ_ADISYON] ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') AS ADISYON                                                                          
WHERE 1=1 '+@PARAMETRE+'   
GROUP BY GARSONKODU,GARSONADI 
ORDER BY SUM(ISNULL(TOPLAM,0)) DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSGRUPSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSGRUPSATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT TUR, GRUPADI AS GRUBU,SUM(ADET) AS ADET, SUM(TOPLAM) AS TUTAR, SUM(ISNULL(MALIYETTOPLAM,0)) AS MALIYET, 
SUM(NETTOPLAM) AS NETSATIS, SUM(NULLIF(NETTOPLAM,0)/TOPLAM*100) AS YUZDE, AVG(INDORAN) AS INDORAN,SUM(INDTUTAR) AS INDIRIM, 
SUM(NETTOPLAM-ISNULL(MALIYETTOPLAM,0)) AS KAR  FROM FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE+' GROUP BY TUR,GRUPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSINDIRIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSINDIRIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM POSINDIRIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSINDIRIM_CARI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[PRL_POSINDIRIM_CARI] (@FISCOUNTER INT,@INDIRIMID INT, @TARIHSAAT NVARCHAR(30)) 
AS
UPDATE ADSSATIR SET 
INDORAN=ISNULL((SELECT ISNULL(PD.INDORAN,P.INDORAN) FROM POSINDIRIMDETAY AS PD INNER JOIN POSINDIRIM P ON PD.POSINDIRIMID=P.POSINDIRIMID 
WHERE PD.POSINDIRIMID=@INDIRIMID AND PD.STOKID=ADSSATIR.STOKID),0),INDID=@INDIRIMID
FROM ADSSATIR WHERE FISCOUNTER=@FISCOUNTER
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSINDIRIMDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSINDIRIMDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM POSINDIRIMDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSKASIYERANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSKASIYERANALIZ] @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),  @FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1500)
SET @SQLCUMLE='SELECT                 
YETKILIKODU,YETKILIADI AS GADI,                                                            
COUNT(*) AS ADISYON,
SUM(ISNULL(KISI,0)) AS KISI,
SUM(ISNULL(ONAKIT,0)) AS NAKIT,                                        
SUM(ISNULL(OKK,0)) AS KK,                                        
SUM(ISNULL(OTICKET,0)) AS TICKET,                                        
SUM(ISNULL(OTICKET2,0)) AS TICKET2,                                        
SUM(ISNULL(OTICKET3,0)) AS TICKET3,                                        
SUM(ISNULL(OTICKET4,0)) AS TICKET4,                                        
SUM(ISNULL(OACIK,0)) AS ACIK,                                        
SUM(ISNULL(TOPLAM,0)) AS TOPLAM
FROM [FNCQ_ADISYON] ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') AS ADISYON                                                                          
WHERE 1=1 '+@PARAMETRE+'   
GROUP BY YETKILIKODU,YETKILIADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSKONTROL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_POSKONTROL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM POSKONTROL WITH (NOLOCK) WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSKONTROL_INSERT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_POSKONTROL_INSERT] @BILGISAYAR NVARCHAR(50), @FIRMAID INT
AS
BEGIN
	INSERT INTO POSKONTROL (FIRMAID,TERMINAL,POSDURUM) VALUES(@FIRMAID,@BILGISAYAR,0)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSKONTROL_UPDATE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_POSKONTROL_UPDATE] @DURUM SMALLINT, @BILGISAYAR NVARCHAR(50), @FIRMAID INT
AS
BEGIN
if @DURUM=0
	BEGIN
		UPDATE POSKONTROL SET POSDURUM=@DURUM WHERE FIRMAID=@FIRMAID AND  TERMINAL=@BILGISAYAR
	END
ELSE if @DURUM=1
	BEGIN
		UPDATE POSKONTROL SET POSDURUM=@DURUM WHERE FIRMAID=@FIRMAID AND  TERMINAL<>@BILGISAYAR
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSSAATSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSSAATSATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT TARIH,CONVERT(NVARCHAR(2), ASAATI, 108) AS SAAT,ADET,BIRIMFIYAT AS BRUTFIYAT,NETFIYAT AS NFIYAT, INDTUTAR AS INDIRIM,
1 AS MASA FROM  FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSSATISIADE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSSATISIADE]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT   KODU AS DEPKODU, MASANO, TARIH,  
FISNO, SATIRGARSONADI AS GARSONKODU,URUNADI  , ADET, ADET*BIRIMFIYAT AS TUTAR,    
SATIRGARSONADI AS YETKILIKODU, ISLEMTURU AS TUR, MUSTERIADI, ACIKLAMA  
FROM FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''')  
WHERE ADET<0 AND 1=1 '+@PARAMETRE                                                                            
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSSATISINDIRIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSSATISINDIRIM]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='
SELECT URUNADI, SUM(ADET) AS ADET,SUM(INDTUTAR) AS INDIRIMTUTAR,
SUM(TOPLAM) AS TUTAR FROM  FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''')                             
WHERE INDTUTAR>0.00 AND 1=1 '+@PARAMETRE+'                                                                                
GROUP BY URUNADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSTOPSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSTOPSATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),@FIRMAID NVARCHAR(10),  @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT TOP 20 TUR,GRUPADI AS GRUBU,URUNADI AS URUN,
SUM(ADET) AS ADET, SUM(TOPLAM) AS TUTAR, SUM(MALIYETTOPLAM) AS MALIYET, 
SUM(NETTOPLAM) AS NETSATIS, AVG(NULLIF(NETTOPLAM,0)/NULLIF(TOPLAM,0)*100) AS YUZDE, SUM(INDTUTAR) AS INDIRIM, 
SUM(ISNULL(NETTOPLAM,0)-ISNULL(MALIYETTOPLAM,0)) AS KAR FROM   FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''','''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE+' GROUP BY KASIYER,CARIUNVANI,TUR,GRUPADI,URUNADI
ORDER BY SUM(ADET) DESC'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSTURSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSTURSATIS]   @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT                 
TUR,                                                            
COUNT(*) AS ADISYON,
SUM(ISNULL(KISI,0)) AS KISI,
SUM(ISNULL(ONAKIT,0)) AS NAKIT,                                        
SUM(ISNULL(OKK,0)) AS KK,                                        
SUM(ISNULL(OTICKET,0)) AS TICKET,                                        
SUM(ISNULL(OTICKET2,0)) AS TICKET2,                                        
SUM(ISNULL(OTICKET3,0)) AS TICKET3,                                        
SUM(ISNULL(OTICKET4,0)) AS TICKET4,                                        
SUM(ISNULL(OACIK,0)) AS ACIK,                                        
SUM(ISNULL(TOPLAM,0)) AS TOPLAM
FROM [FNCQ_ADISYON] ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') AS ADISYON                                                                          
WHERE 1=1 '+@PARAMETRE+'   
GROUP BY TUR'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSURUNSATIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_POSURUNSATIS]  @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10),   @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(1600)
SET @SQLCUMLE='
SELECT TUR, GRUPADI AS GRUBU,URUNADI AS URUN, SUM(ADET) AS ADET, SUM(TOPLAM) AS TUTAR, SUM(ISNULL(MALIYETTOPLAM,0)) AS MALIYET, 
SUM(NETTOPLAM) AS NETSATIS, SUM(NULLIF(NETTOPLAM,0)/TOPLAM*100) AS YUZDE, AVG(INDORAN) AS INDORAN,SUM(INDTUTAR) AS INDIRIM, 
SUM(NETTOPLAM-ISNULL(MALIYETTOPLAM,0)) AS KAR  FROM FNCQ_ADISYONANALIZ  ('''+@ILKTARIH+''', '''+@SONTARIH+''', '''+@FIRMAID+''') 
WHERE 1=1 '+@PARAMETRE+' GROUP BY TUR,URUNADI,GRUPADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_POSYAZICITIP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_POSYAZICITIP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM POSYAZICITIP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PRCOZELLIGI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PRCOZELLIGI] @PRCNAME NVARCHAR(40)
AS
SELECT ROUTINE_NAME ADI, ROUTINE_TYPE AS TURU,  ROUTINE_DEFINITION AS PARAMETRE
  FROM NOVADB.INFORMATION_SCHEMA.ROUTINES
 WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME=@PRCNAME
GO
/****** Object:  StoredProcedure [dbo].[PRL_PROJE_DAIRE_SEC]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PROJE_DAIRE_SEC] @PARAMETRE NVARCHAR(200)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(900)
SET @SQLCUMLE='SELECT EMLAKSATISID,TARIH,PROJE.GRUPADI+'' ''+ISNULL(DAIRELER,'''')+'' ''+ISNULL(MUH_HESAP_ALTCARI.UNVANI,MUH_HESAP.ACIKLAMA) AS ACIKLAMA,
ALICIHESAPID,MUH_HESAP.KODU AS ALICIHESAPKODU, MUH_HESAP.ACIKLAMA AS ALICIHESAPADI, 
ALICIALTCARIID,ISNULL(MUH_HESAP_ALTCARI.UNVANI,MUH_HESAP.ACIKLAMA) AS ALICI_ALTUNVANI, 
PROJEID,PROJE.GRUPADI AS PROJE, DAIREID, DAIRE.GRUPADI AS DAIRENO, REELFIYAT,EMLAKSATIS.DOVIZ,DAIRELER,TAPUTARIH,TAPUDAKIAD,MUHFISID 
FROM EMLAKSATIS
LEFT JOIN MUH_HESAP ON EMLAKSATIS.ALICIHESAPID=MUH_HESAP.HESAPID
LEFT JOIN MUH_HESAP_ALTCARI ON EMLAKSATIS.ALICIALTCARIID=MUH_HESAP_ALTCARI.ALTCARIID
LEFT JOIN MUH_GRUP AS PROJE ON EMLAKSATIS.PROJEID=PROJE.GRUPID
LEFT JOIN MUH_GRUP AS DAIRE ON EMLAKSATIS.DAIREID=DAIRE.GRUPID
WHERE ISNULL(EMLAKSATIS.SIL,0)=0 AND 1=1 '+@PARAMETRE+' ORDER BY MUH_HESAP.ACIKLAMA,MUH_HESAP_ALTCARI.UNVANI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PROJEBLOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PROJEBLOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PROJEBLOK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PROJEEMLAKTIP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PROJEEMLAKTIP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PROJEEMLAKTIP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_PTARIH]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_PTARIH]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM PTARIH WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RAPORLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_RAPORLAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RAPORLAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RECETE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_RECETE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RECETE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RECETEDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_RECETEDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RECETEDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RENKBEDENGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_RENKBEDENGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RENKBEDENGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RENKLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_RENKLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RENKLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RESMITATIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_RESMITATIL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM RESMITATIL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_RESMITATIL_BUL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_RESMITATIL_BUL]  @YIL NVARCHAR(4), @AY NVARCHAR(2), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT * FROM FNCQ_RESMITATIL ('+@YIL+','+@AY+','+@FIRMAID+')  WHERE 1=1 '+@PARAMETRE+' ORDER BY YIL,AY,GUN'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_REYON]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_REYON]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM REYON WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATILDI_ISARETLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SATILDI_ISARETLER] @DURUM NVARCHAR(10), @GRUPID INT, @FIRMAID INT
AS
UPDATE MUH_GRUP SET DURUM=@DURUM WHERE GRUPID=@GRUPID AND FIRMAID=@FIRMAID 


GO
/****** Object:  StoredProcedure [dbo].[PRL_SATIS_DETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SATIS_DETAY]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(900)
SET @SQLCUMLE='SELECT TI.BARKOD,S.ADI AS STOKADI, FBIRIM, SUM(FMIKTAR) AS MIKTAR, 
NULLIF(SUM(FMIKTAR*FBFIYAT),0)/NULLIF(SUM(FMIKTAR),0) AS BFIYAT, SUM(FMIKTAR*FBFIYAT) AS TOPLAM
FROM TUKETIMFISISL AS TI WITH (NOLOCK) INNER JOIN STOK AS S WITH (NOLOCK) ON TI.STOKID=S.STOKID
INNER JOIN TUKETIMFIS AS T WITH (NOLOCK) ON TI.DEPOFISID=T.DEPOFISID WHERE 1=1 '+@PARAMETRE+'
GROUP BY TI.BARKOD,S.ADI,FBIRIM
ORDER BY S.ADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISFATURA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SATISFATURA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATID,TARIH,FATNO,UNVANI,TOPLAM,KDV,GTOPLAM 
FROM FATURA WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND TUR=-1 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISFIS_GERICEK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SATISFIS_GERICEK]  @FATID INT, @FIRMAID INT
AS
BEGIN
UPDATE MUH_FIS SET SIL=-2, OZELKOD2='FATURAYA AKTARILDI' WHERE FIRMAID=@FIRMAID AND ENTKAYNAKID>0 AND ENTKAYNAKID IN(SELECT DISTINCT SATISTID FROM FATISL WHERE SATISTID>0 AND FATID=@FATID)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISFISDOVIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SATISFISDOVIZ] @FIRMAID INT, @SUBEID INT, @TOPLAM FLOAT
AS
BEGIN
SELECT DI.SUBEID,DI.KODU AS DOVIZ,  CAST(@TOPLAM/ISNULL(DOVIZALIS,1) AS decimal(19,4)) AS DVZTUTAR, 
CAST(DOVIZALIS AS decimal(19,4)) AS KUR
FROM DOVIZISL AS DI INNER JOIN DOVIZ AS D ON DI.KODU=D.KODU WHERE ISNULL(DI.SIL,0)=0 AND DI.FIRMAID=@FIRMAID AND DI.SUBEID=@SUBEID AND 
D.FIRMAID=@FIRMAID AND DI.TARIH=(select MAX(TARIH) FROM DOVIZISL WHERE FIRMAID=@FIRMAID) 
ORDER BY SIRANO
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRL_SATISLAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' TARIH, CDEPOID AS DEPOID, D.KODU AS DEPOKODU,D.DEPOADI, sum(NAKIT) AS NAKIT,
    SUM(KKARTI) AS KK, SUM(ACIK) AS ACIK,  SUM(TOPLAM) AS TOPLAM FROM TUKETIMFIS  WITH (NOLOCK)
    INNER JOIN DEPO AS D   WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=D.DEPOID
    WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+' GROUP BY TARIH,CDEPOID,D.KODU,D.DEPOADI ORDER BY D.KODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISODEME]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SATISODEME]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SATISODEME WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISODEME_SIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SATISODEME_SIL] @DEPOFISID INT
AS
IF @DEPOFISID>0
	BEGIN
		DELETE FROM SATISODEME WHERE DEPOFISID=@DEPOFISID
		UPDATE TUKETIMFISISL SET ZRURUNID=NULL, FBFIYAT=BFIYAT WHERE ZRURUNID=-1 AND DEPOFISID=@DEPOFISID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SATISTEMSILCI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_SATISTEMSILCI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SATISTEMSILCI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMANALIZ] @FIRMAID INT
AS
SELECT CAST(convert(varchar, TARIH, 23) AS DATETIME) as TARIH, TARIH AS SAYIMZAMANI,DEPO.KODU,DEPO.DEPOADI,
SAYIMFIS.BARKOD,SGRUP.GRUPKODU,SGRUP.GRUPADI,SAYIMFIS.STOKID,STOK.ADI AS STOKADI,SAYIMFIS.SAYIMBIRIMI,SAYIM,KALAN,FARK,SAYIM*SAYIMFIS.ORTFIYAT AS SAYIMTUTAR,KALAN*SAYIMFIS.ORTFIYAT AS KALANTUTAR, FARK*SAYIMFIS.ORTFIYAT AS FARKTUTAR, 
FARK AS TUKETIM, FARK*SAYIMFIS.ORTFIYAT AS TUKETIMTUTAR,SAYIMFIS.ORTFIYAT 
FROM SAYIMFIS INNER JOIN STOK ON SAYIMFIS.STOKID=STOK.STOKID
INNER JOIN SGRUP ON STOK.GRUPID=SGRUP.SGRUPID
INNER JOIN DEPO ON SAYIMFIS.DEPOID=DEPO.DEPOID
WHERE SAYIMFIS.FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMFIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SAYIMFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SAYIMFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMFIS_MAHSUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMFIS_MAHSUP] @FIRMAID INT, @SUBEID INT, @DEPOID INT
AS
BEGIN
SELECT ISNULL(MUHALISHESAPID,-999) AS HESAPID, DEPO.DEPOADI+' : '+SGRUP.GRUPADI AS ACIKLAMA, 0.00 AS BORC, SUM(SAYIMFIS.FARKTUTARI*-1) AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
FROM SAYIMFIS WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK)  ON SAYIMFIS.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK) ON STOK.GRUPID=SGRUP.SGRUPID
INNER JOIN DEPO WITH (NOLOCK) ON SAYIMFIS.DEPOID=DEPO.DEPOID
WHERE  SAYIMFIS.FIRMAID=@FIRMAID AND SAYIMFIS.SUBEID=@SUBEID AND SAYIMFIS.DEPOID=@DEPOID
GROUP BY MUHALISHESAPID,DEPO.DEPOADI,SGRUP.GRUPADI
UNION ALL
SELECT ISNULL(MUHSARFHESAPID,-999) AS HESAPID, DEPO.DEPOADI+' : '+SGRUP.GRUPADI AS ACIKLAMA, SUM(SAYIMFIS.FARKTUTARI*-1) AS BORC, 0.00 AS ALACAK, 0.00 AS DBORC, 0.00 AS DALACAK 
FROM SAYIMFIS WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK)  ON SAYIMFIS.STOKID=STOK.STOKID
INNER JOIN SGRUP WITH (NOLOCK) ON STOK.GRUPID=SGRUP.SGRUPID
INNER JOIN DEPO WITH (NOLOCK) ON SAYIMFIS.DEPOID=DEPO.DEPOID
WHERE SAYIMFIS.FIRMAID=@FIRMAID AND SAYIMFIS.SUBEID=@SUBEID AND SAYIMFIS.DEPOID=@DEPOID
GROUP BY MUHSARFHESAPID,DEPO.DEPOADI,SGRUP.GRUPADI
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMFISARSIV]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SAYIMFISARSIV]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SAYIMFISARSIV WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMFISYAZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMFISYAZ]  
@DEPOFISID INT,
@FIRMAID INT,
@SUBEID INT,
@DEPOID INT,
@BARKODAGORE NVARCHAR(5)
AS
BEGIN
IF @BARKODAGORE='HAYIR'
	BEGIN
		INSERT INTO DEPOFISISL (DEPOFISID,BARKOD,STOKID,MIKTAR,FMIKTAR,FBIRIM,BFIYAT,FBFIYAT)
		SELECT @DEPOFISID, S.BARKOD,SF.STOKID,FARK,FARK,SF.SAYIMBIRIMI,
		ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT,ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT
        FROM SAYIMFIS  AS SF LEFT JOIN STOK AS S ON SF.STOKID=S.STOKID
        where SF.FIRMAID=@FIRMAID AND SF.SUBEID=@SUBEID AND SF.DEPOID=@DEPOID
	END
ELSE
	BEGIN
		INSERT INTO DEPOFISISL (DEPOFISID,BARKOD,STOKID,RENKID,BEDENID,MIKTAR,FMIKTAR,FBIRIM,BFIYAT,FBFIYAT)
		SELECT @DEPOFISID, SF.BARKOD,SF.STOKID,SF.RENKID,SF.BEDENID,FARK,FARK,SF.SAYIMBIRIMI,
		ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT,ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT
        FROM SAYIMFIS  AS SF LEFT JOIN STOK AS S ON SF.StokID=S.STOKID
        where SF.FIRMAID=@FIRMAID AND SF.SUBEID=@SUBEID AND SF.DEPOID=@DEPOID
	END
UPDATE SAYIMFIS SET DEPOFISID=@DEPOFISID WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID

INSERT INTO SAYIMFISARSIV (TARIH,MOBILSAYIMDONEMID,DEPOFISID,USERID,BARKOD,GRUPID,STOKID,RENKID,BEDENID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,FSAYIM,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI)
SELECT TARIH,MOBILSAYIMDONEMID,DEPOFISID,USERID,BARKOD,GRUPID,STOKID,RENKID,BEDENID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,FSAYIM,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI 
FROM SAYIMFIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID

DELETE FROM SAYIMFIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMGERIAL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMGERIAL]  
@DEPOFISID INT,
@FIRMAID INT,
@SUBEID INT,
@DEPOID INT
AS
BEGIN
INSERT INTO SAYIMFIS (TARIH,MOBILSAYIMDONEMID,DEPOFISID,USERID,BARKOD,GRUPID,STOKID,RENKID,BEDENID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,FSAYIM,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI)
SELECT TARIH,MOBILSAYIMDONEMID,DEPOFISID,USERID,BARKOD,GRUPID,STOKID,RENKID,BEDENID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,FSAYIM,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI 
FROM SAYIMFISARSIV WHERE DEPOFISID=@DEPOFISID AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID

DELETE FROM SAYIMFISARSIV WHERE DEPOFISID=@DEPOFISID AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMOLUSTUR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMOLUSTUR]  @SAYIMTARIH NVARCHAR(10), @KULLANICI NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='INSERT INTO SAYIMFIS (TARIH,USERID,BARKOD,GRUPID,STOKID,FIRMAID,SUBEID,DEPOID,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI) 
SELECT '''+@SAYIMTARIH+''','+@KULLANICI+',STOKKODU, GRUPID,STOKID,'+@FIRMAID+',SUBEID, DEPOID,0,SUM(GCADET) AS KALANMIKTAR,0,0,BIRIM,NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT,0 
FROM FNCQ_STOKBAKIYE  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' AND STOKID NOT IN(SELECT STOKID FROM SAYIMFIS WHERE 1=1 '+@PARAMETRE+')  
 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU'
EXEC (@SQLCUMLE)
SET @SQLCUMLE='SELECT * INTO ##SAYIM'+@FIRMAID+' FROM (
SELECT '''+@SAYIMTARIH+''' AS TARIH,'+@KULLANICI+' AS KULLANICI,STOKKODU, GRUPID,STOKID,'+@FIRMAID+' AS FIRMAID,SUBEID, DEPOID,0 AS SAYIM,SUM(GCADET) AS KALANMIKTAR,0 AS FARK,0 AS SAYIMTUTAR,BIRIM,NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT,0  AS FARKTUTARI
FROM FNCQ_STOKBAKIYE  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU) AS TBL'
EXEC (@SQLCUMLE)
SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*##SAYIM'+@FIRMAID+'.ORTFIYAT, SAYIMFIS.ORTFIYAT=##SAYIM'+@FIRMAID+'.ORTFIYAT, SAYIMFIS.KALAN=##SAYIM'+@FIRMAID+'.KALANMIKTAR FROM SAYIMFIS INNER JOIN ##SAYIM'+@FIRMAID+' ON SAYIMFIS.STOKID=##SAYIM'+@FIRMAID+'.STOKID AND SAYIMFIS.DEPOID=##SAYIM'+@FIRMAID+'.DEPOID'
EXEC (@SQLCUMLE)
SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*Q.ORTFIYAT, SAYIMFIS.ORTFIYAT=Q.ORTFIYAT 
FROM SAYIMFIS INNER JOIN [FNCQ_STOKORTFIYAT]  (ISNULL(convert(varchar,(SELECT TARIH FROM [FNCQ_SONSAYIMTARIH] ('''+@FIRMAID+''')), 23),''2000-01-01''),'''+@TARIH2+''','''+@FIRMAID+''') AS Q 
ON SAYIMFIS.STOKID=Q.STOKID AND SAYIMFIS.DEPOID=Q.DEPOID WHERE FIRMAID='+@FIRMAID
EXEC (@SQLCUMLE)
SET @SQLCUMLE='DROP TABLE ##SAYIM'+@FIRMAID
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMOLUSTUR_YENI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMOLUSTUR_YENI]  @SAYIMTARIH NVARCHAR(10), @KULLANICI NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200), 
@DEVIRAL NVARCHAR(5)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='UPDATE FATURA SET FATURA.SUBEID=DEPO.SUBEID FROM FATURA INNER JOIN DEPO ON FATURA.DEPOID=DEPO.DEPOID WHERE ISNULL(DEPO.SIL,0)=0 AND  FATURA.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+'
UPDATE FATURA SET FATURA.DEPOID=DEPO.DEPOID FROM FATURA INNER JOIN DEPO ON FATURA.SUBEID=DEPO.SUBEID WHERE ISNULL(DEPO.SIL,0)=0 AND  FATURA.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+' AND FATURA.DEPOID IS NULL AND ANADEPO=1
UPDATE DEPOFIS SET DEPOFIS.SUBEID=DEPO.SUBEID FROM DEPOFIS INNER JOIN DEPO ON DEPOFIS.GDEPOID=DEPO.DEPOID WHERE ISNULL(DEPO.SIL,0)=0 AND  DEPOFIS.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+'
UPDATE DEPOFIS SET DEPOFIS.GSUBEID=DEPO.SUBEID FROM DEPOFIS INNER JOIN DEPO ON DEPOFIS.GDEPOID=DEPO.DEPOID WHERE ISNULL(DEPO.SIL,0)=0 AND  DEPOFIS.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+'
UPDATE DEPOFIS SET DEPOFIS.CSUBEID=DEPO.SUBEID FROM DEPOFIS INNER JOIN DEPO ON DEPOFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(DEPO.SIL,0)=0 AND  DEPOFIS.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+'
UPDATE SAYIMFISARSIV SET SAYIMFISARSIV.SUBEID=DEPO.SUBEID FROM SAYIMFISARSIV INNER JOIN DEPO ON SAYIMFISARSIV.DEPOID=DEPO.DEPOID WHERE ISNULL(DEPO.SIL,0)=0 AND  SAYIMFISARSIV.FIRMAID='+@FIRMAID+' AND DEPO.FIRMAID='+@FIRMAID+''
EXEC (@SQLCUMLE)
IF @DEVIRAL='EVET'
	BEGIN
		SET @SQLCUMLE='INSERT INTO SAYIMFIS (TARIH,USERID,BARKOD,GRUPID,STOKID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI) 
		SELECT '''+@SAYIMTARIH+''','+@KULLANICI+',STOKKODU, GRUPID,STOKID,'+@FIRMAID+',SUBEID, DEPOID,SUM(DEVIR),SUM(DEVIRTUTAR),SUM(ALIM),SUM(ALIMTUTAR), 0,SUM(KALANMIKTAR) AS KALANMIKTAR,0,0,BIRIM,NULLIF(SUM(KALANMIKTAR*ORTFIYAT),0)/NULLIF(SUM(KALANMIKTAR),0) AS ORTFIYAT,0 
		FROM [FNCQ_STOKBAKIYE_SAYIM]  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' AND STOKID NOT IN(SELECT STOKID FROM SAYIMFIS WHERE 1=1 '+@PARAMETRE+')  
		 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU'
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='SELECT * INTO ##SAYIM'+@FIRMAID+' FROM (
		SELECT '''+@SAYIMTARIH+''' AS TARIH,'+@KULLANICI+' AS KULLANICI,STOKKODU, GRUPID,STOKID,'+@FIRMAID+' AS FIRMAID,SUBEID, DEPOID,SUM(DEVIR) AS DEVIR,
		SUM(DEVIRTUTAR) AS DEVIRTUTAR, SUM(ALIM) AS ALIM,SUM(ALIMTUTAR) AS ALIMTUTAR, 0 AS SAYIM,SUM(KALANMIKTAR) AS KALANMIKTAR,0 AS FARK,0 AS SAYIMTUTAR,BIRIM,NULLIF(SUM(KALANMIKTAR*ORTFIYAT),0)/NULLIF(SUM(KALANMIKTAR),0) AS ORTFIYAT,0  AS FARKTUTARI
		FROM FNCQ_STOKBAKIYE_SAYIM  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
		 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU) AS TBL'
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*##SAYIM'+@FIRMAID+'.ORTFIYAT, SAYIMFIS.ORTFIYAT=##SAYIM'+@FIRMAID+'.ORTFIYAT, 
		SAYIMFIS.KALAN=##SAYIM'+@FIRMAID+'.KALANMIKTAR, SAYIMFIS.DEVIR=##SAYIM'+@FIRMAID+'.DEVIR, SAYIMFIS.DEVIRTUTAR=##SAYIM'+@FIRMAID+'.DEVIRTUTAR,
		SAYIMFIS.ALIM=##SAYIM'+@FIRMAID+'.ALIM, SAYIMFIS.ALIMTUTAR=##SAYIM'+@FIRMAID+'.ALIMTUTAR FROM SAYIMFIS INNER JOIN ##SAYIM'+@FIRMAID+' ON SAYIMFIS.STOKID=##SAYIM'+@FIRMAID+'.STOKID AND SAYIMFIS.DEPOID=##SAYIM'+@FIRMAID+'.DEPOID'
		EXEC (@SQLCUMLE)


		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*ORTFIYAT WHERE FIRMAID='+@FIRMAID+@PARAMETRE
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.ORTFIYAT=SAYIMFIS.SAYIMTUTAR/SAYIMFIS.SAYIM WHERE SAYIMTUTAR>0 AND SAYIM>0 AND ISNULL(ORTFIYAT,0)=0 AND FIRMAID='+@FIRMAID+@PARAMETRE
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='DROP TABLE ##SAYIM'+@FIRMAID
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE='INSERT INTO SAYIMFIS (TARIH,USERID,BARKOD,GRUPID,STOKID,FIRMAID,SUBEID,DEPOID,DEVIR,DEVIRTUTAR,ALIM,ALIMTUTAR,SAYIM,KALAN,FARK,SAYIMTUTAR,SAYIMBIRIMI,ORTFIYAT,FARKTUTARI) 
		SELECT '''+@SAYIMTARIH+''','+@KULLANICI+',STOKKODU, GRUPID,STOKID,'+@FIRMAID+',SUBEID, DEPOID,0,0,0,0,0,SUM(GCADET) AS KALANMIKTAR,0,0,BIRIM,NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT,0 
		FROM FNCQ_STOKBAKIYE  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' AND STOKID NOT IN(SELECT STOKID FROM SAYIMFIS WHERE 1=1 '+@PARAMETRE+')  
		 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU'
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='SELECT * INTO ##SAYIM'+@FIRMAID+' FROM (
		SELECT '''+@SAYIMTARIH+''' AS TARIH,'+@KULLANICI+' AS KULLANICI,STOKKODU, GRUPID,STOKID,'+@FIRMAID+' AS FIRMAID,SUBEID, DEPOID,0 AS SAYIM,SUM(GCADET) AS KALANMIKTAR,0 AS FARK,0 AS SAYIMTUTAR,BIRIM,NULLIF(SUM(GCADET*NFIYAT),0)/NULLIF(SUM(GCADET),0) AS ORTFIYAT,0  AS FARKTUTARI
		FROM FNCQ_STOKBAKIYE  ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
		 GROUP BY GRUPID,STOKID, DEPOID, BIRIM,SUBEID,STOKKODU) AS TBL'
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*##SAYIM'+@FIRMAID+'.ORTFIYAT, SAYIMFIS.ORTFIYAT=##SAYIM'+@FIRMAID+'.ORTFIYAT, SAYIMFIS.KALAN=##SAYIM'+@FIRMAID+'.KALANMIKTAR FROM SAYIMFIS INNER JOIN ##SAYIM'+@FIRMAID+' ON SAYIMFIS.STOKID=##SAYIM'+@FIRMAID+'.STOKID AND SAYIMFIS.DEPOID=##SAYIM'+@FIRMAID+'.DEPOID'
		EXEC (@SQLCUMLE)
		
		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.ORTFIYAT=SAYIMFIS.SAYIMTUTAR/SAYIMFIS.SAYIM WHERE SAYIMTUTAR>0 AND SAYIM>0 AND ISNULL(ORTFIYAT,0)=0 AND FIRMAID='+@FIRMAID
		EXEC (@SQLCUMLE)

		SET @SQLCUMLE='UPDATE SAYIMFIS SET SAYIMFIS.FARK=SAYIMFIS.SAYIM-SAYIMFIS.KALAN, SAYIMFIS.FARKTUTARI=(SAYIMFIS.SAYIM-SAYIMFIS.KALAN)*Q.ORTFIYAT, SAYIMFIS.ORTFIYAT=Q.ORTFIYAT 
		FROM SAYIMFIS INNER JOIN [FNCQ_STOKORTFIYAT]  (ISNULL(convert(varchar,(SELECT TARIH FROM [FNCQ_SONSAYIMTARIH] ('''+@FIRMAID+''')), 23),''2000-01-01''),'''+@TARIH2+''','''+@FIRMAID+''') AS Q 
		ON SAYIMFIS.STOKID=Q.STOKID AND SAYIMFIS.DEPOID=Q.DEPOID WHERE FIRMAID='+@FIRMAID
		EXEC (@SQLCUMLE)
		SET @SQLCUMLE='DROP TABLE ##SAYIM'+@FIRMAID
		EXEC (@SQLCUMLE)
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMSIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMSIL] @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DEPOID NVARCHAR(10)
AS
DELETE FROM SAYIMFIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND DEPOID=@DEPOID
GO
/****** Object:  StoredProcedure [dbo].[PRL_SAYIMTODEPOFIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SAYIMTODEPOFIS]  
@FIRMAID INT,
@ILKTARIH NVARCHAR(10),
@SONTARIH NVARCHAR(10)
AS
BEGIN
DECLARE
@TARIH NVARCHAR(10),
@SUBEID INT,
@DEPOID INT,
@SONFISID INT

DECLARE DEPOFISLER CURSOR FOR

SELECT convert(varchar, TARIH, 23) AS TARIH,FIRMAID,SUBEID,DEPOID FROM SAYIMFISARSIV WHERE  FIRMAID=@FIRMAID
AND TARIH BETWEEN  @ILKTARIH AND @SONTARIH GROUP BY convert(varchar, TARIH, 23),FIRMAID,SUBEID,DEPOID 

OPEN DEPOFISLER

FETCH NEXT FROM DEPOFISLER INTO @TARIH, @FIRMAID, @SUBEID, @DEPOID 
WHILE @@FETCH_STATUS=0
	BEGIN
		INSERT INTO DEPOFIS (TARIH,ISLEM,FIRMAID,SUBEID,GDEPOID,ACIKLAMA,ADD_DATE)
		VALUES(@TARIH,'SAYIM',@FIRMAID,@SUBEID,@DEPOID,'SAYIM',GETDATE())

		SELECT @SONFISID=MAX(DEPOFISID) FROM DEPOFIS WHERE FIRMAID=@FIRMAID

		INSERT INTO DEPOFISISL (DEPOFISID,BARKOD,STOKID,MIKTAR,FMIKTAR,FBIRIM,BFIYAT,FBFIYAT,ACIKLAMA)
		SELECT @SONFISID, S.BARKOD,SF.STOKID,SAYIM,SAYIM,SF.SAYIMBIRIMI,
		ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT,ISNULL(SF.ORTFIYAT,S.SALISFIYAT) AS ORTFIYAT,'Sayım'
        FROM SAYIMFISARSIV  AS SF LEFT JOIN STOK AS S ON SF.STOKID=S.STOKID
        where convert(varchar, TARIH, 23)=@TARIH AND SF.FIRMAID=@FIRMAID AND SF.SUBEID=@SUBEID AND SF.DEPOID=@DEPOID
								
		FETCH NEXT FROM DEPOFISLER INTO @TARIH, @FIRMAID, @SUBEID, @DEPOID								
	END
CLOSE DEPOFISLER
DEALLOCATE DEPOFISLER

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SBIRIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SBIRIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SBIRIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SECILIHESAPBAKIYE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SECILIHESAPBAKIYE] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @KODU NVARCHAR(20)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SUM(BORC) AS BORC, SUM(ALACAK) AS ALACAK, SUM(BORC)-SUM(ALACAK) AS BAKIYE, (CASE WHEN SUM(BORC)-SUM(ALACAK)>0 THEN 
''BORCLU'' WHEN SUM(BORC)-SUM(ALACAK)<0 THEN ''ALACAKLI'' ELSE '''' END) AS DURUM FROM FNCQ_HESAPDETAY_FATURA_HESAPID ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@KODU+''')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SERVISDURUM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SERVISDURUM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SERVISDURUM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SERVISDURUM_EKLE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SERVISDURUM_EKLE] @FIRMAID INT, @SUBEID INT
AS
BEGIN
INSERT INTO SERVISDURUM (FIRMAID,SUBEID,SERVISDURUMU,RENKKODU) 
SELECT @FIRMAID,@SUBEID,SERVISDURUMU,RENKKODU FROM SERVISDURUM WHERE FIRMAID=-1
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SERVISFATID_KALDIR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SERVISFATID_KALDIR] @FIRMAID INT, @FATID INT
AS
IF @FATID>0
	BEGIN
		UPDATE SERVISFORM SET FATID=NULL WHERE FIRMAID=@FIRMAID AND FATID=@FATID
		UPDATE TUKETIMFIS SET MUHFC=NULL WHERE FIRMAID=@FIRMAID AND MUHFC=@FATID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SERVISFORM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





CREATE PROCEDURE [dbo].[PRL_SERVISFORM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SERVISFORM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SERVISPARCA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SERVISPARCA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SERVISPARCA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_SGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SGRUP WITH (NOLOCK) WHERE GRUPTURU=''STOK'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SIFREDEGISTIR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SIFREDEGISTIR]  @FIRMAID INT, @USERID INT, @ESKISIFRE NVARCHAR(20), @YENISIFRE NVARCHAR(20)
AS
BEGIN
	UPDATE NOVAUSER SET SIFRESI=@YENISIFRE WHERE FIRMAID=@FIRMAID AND NOVAUSERID=@USERID AND SIFRESI=@ESKISIFRE
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SILINEN_SATISLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_SILINEN_SATISLAR] @FIRMAID INT, @TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
BEGIN
	SELECT '01-Satır Silindi' AS DRM, TARIH,ISNULL(SATISZAMANI,GERCEKTARIH) AS ZAMAN,DEPO.DEPOADI,NOVAUSER.ADSOYAD,TI.BARKOD,STOK.ADI AS STOKADI, FMIKTAR,FBFIYAT,FMIKTAR*FBFIYAT AS TOPLAM 
	FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL AS TI WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TI.DEPOFISID INNER JOIN STOK WITH (NOLOCK) ON TI.STOKID=STOK.STOKID
	INNER JOIN DEPO WITH (NOLOCK)  ON TUKETIMFIS.CDEPOID=DEPO.DEPOID LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID
	WHERE ISNULL(TUKETIMFIS.SIL,0)=0 AND TI.SILINDI=-2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND STOK.FIRMAID=@FIRMAID AND TUKETIMFIS.TARIH BETWEEN @TARIH1 AND @TARIH2 
	UNION ALL
	SELECT '02-Fiş Silindi' AS DRM, TARIH,ISNULL(SATISZAMANI,GERCEKTARIH) AS ZAMAN,DEPO.DEPOADI,NOVAUSER.ADSOYAD,TI.BARKOD,STOK.ADI AS STOKADI, FMIKTAR,FBFIYAT,FMIKTAR*FBFIYAT AS TOPLAM 
	FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN TUKETIMFISISL AS TI WITH (NOLOCK)  ON TUKETIMFIS.DEPOFISID=TI.DEPOFISID INNER JOIN STOK WITH (NOLOCK) ON TI.STOKID=STOK.STOKID
	INNER JOIN DEPO WITH (NOLOCK)  ON TUKETIMFIS.CDEPOID=DEPO.DEPOID LEFT JOIN NOVAUSER WITH (NOLOCK) ON TUKETIMFIS.USERID=NOVAUSER.NOVAUSERID
	WHERE TUKETIMFIS.SIL=-2 AND TUKETIMFIS.FIRMAID=@FIRMAID AND STOK.FIRMAID=@FIRMAID AND TUKETIMFIS.TARIH BETWEEN @TARIH1 AND @TARIH2 ORDER BY DRM,TARIH,ZAMAN
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SIPARIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_SIPARIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SIPARIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SIPARISANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SIPARISANALIZ] @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
DECLARE @SQL NVARCHAR(1250)
SET @SQL='SELECT SIPARIS.SIPARISID,SIPARIS.FIRMAID,SIPARIS.SUBEID,SIPARIS.DEPOID,DEPO.DEPOADI,YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, TARIH,SAAT,SIPARIS.YETKILI,SIPARIS.HESAPID,
MUH_HESAP.ACIKLAMA AS HESAPADI,MUH_HESAP.ADRES1,MUH_HESAP.ADRES2,MUH_HESAP.ILCE,MUH_HESAP.SEHIR,MUH_HESAP.TEL1,MUH_HESAP.GSM,MUH_HESAP.VD,MUH_HESAP.VDNO,
ENO,SIPARIS.ACIKLAMA,SIPARISDETAY.BARKOD,SIPARISDETAY.STOKID,STOK.ADI AS STOKADI, SIPARISDETAY.FMIKTAR,
SIPARISDETAY.FBIRIM,SIPARISDETAY.FBFIYAT,SIPARISDETAY.BFIYAT, SIPARISDETAY.FMIKTAR*SIPARISDETAY.FBFIYAT AS ARATOPLAM, 
TMIKTAR,TTUTAR,SIPARISTURU,SIPARIS.FTKESILDI,SIPARIS.FATID 
FROM SIPARIS INNER JOIN SIPARISDETAY ON SIPARIS.SIPARISID=SIPARISDETAY.SIPARISID
INNER JOIN DEPO ON SIPARIS.DEPOID=DEPO.DEPOID
INNER JOIN STOK ON SIPARISDETAY.STOKID=STOK.STOKID
LEFT JOIN MUH_HESAP ON SIPARIS.HESAPID=MUH_HESAP.HESAPID
WHERE ISNULL(SIPARIS.SIL,0)=0 AND  SIPARIS.FIRMAID='+@FIRMAID+' AND STOK.FIRMAID='+@FIRMAID+'  AND MUH_HESAP.FIRMAID='+@FIRMAID+' AND 1=1 '+@PARAMETRE
EXEC(@SQL)
GO
/****** Object:  StoredProcedure [dbo].[PRL_SIPARISDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SIPARISDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SIPARISDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SITEDUYURULAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SITEDUYURULAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SITEDUYURULAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SITEGENELKURUL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SITEGENELKURUL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SITEGENELKURUL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SITEKONUTUR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SITEKONUTUR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SITEKONUTUR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SMM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SMM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FATURA.*,EFATNO,EFATTURU,EDEVLETDURUM,EFATURADURUM 
FROM FATURA WITH (NOLOCK) LEFT OUTER JOIN FATURADETAY WITH (NOLOCK) ON FATURA.FATID=FATURADETAY.FATID 
WHERE FISDURUMID=4 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SONSAYIMTARIH]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SONSAYIMTARIH] @FIRMAID NVARCHAR(10), @DEPOID NVARCHAR(10)
AS
SELECT TARIH AS SONSAYIMTARIH,TARIH+1 SONRAKIDONEMBASI, FIRMAID,DEPOID FROM SAYIMFISARSIV 
WHERE DEPOID=@DEPOID AND FIRMAID=@FIRMAID AND TARIH=(SELECT MAX(TARIH) FROM SAYIMFISARSIV WHERE FIRMAID=@FIRMAID AND DEPOID=@DEPOID)
GROUP BY TARIH,FIRMAID,DEPOID
GO
/****** Object:  StoredProcedure [dbo].[PRL_SOZLESME]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[PRL_SOZLESME]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SOZLESME WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SOZLESMEDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[PRL_SOZLESMEDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SOZLESMEDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SOZLESMEDETAY_FATURA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SOZLESMEDETAY_FATURA] @FIRMAID INT,  @YIL INT, @AY INT
AS
SELECT SOZLESMEDETAYID, FTARIH,FISTURID,S.HESAPID,MUH_HESAP.ACIKLAMA,MUH_HESAP.VD,MUH_HESAP.EMAIL, REPLACE(MUH_HESAP.VDNO,' ','') AS VDNO,MUH_HESAP.ADRES1,MUH_HESAP.ADRES2, MUH_HESAP.SEHIR, ALTCARIID,YAZILIMHESAPID,DONANIMHESAPID,DIGERHESAPID, YAZILIMSTOKID,DONANIMSTOKID,DIGERSTOKID,
YEAR(FTARIH) AS YIL, MONTH(FTARIH) AS AY, SD.YAZILIMBEDELI,SD.DONANIMBEDELI,DIGERBEDELI,
ISNULL(SD.YAZILIMBEDELI,0)+ISNULL(SD.DONANIMBEDELI,0)+ISNULL(SD.DIGERBEDELI,0) as TOPLAM,FTKESILDI,FATID,FTACIKLAMA,KDVDAHILMI 
FROM SOZLESMEDETAY AS SD LEFT JOIN SOZLESME AS S ON SD.SOZLESMEID=S.SOZLESMEID 
LEFT JOIN MUH_HESAP ON S.HESAPID=MUH_HESAP.HESAPID

WHERE ISNULL(S.SIL,0)=0 AND S.FIRMAID=@FIRMAID AND YEAR(FTARIH)=@YIL AND MONTH(FTARIH)=@AY
GO
/****** Object:  StoredProcedure [dbo].[PRL_SOZLESMEDETAY_FATURA_IPTAL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SOZLESMEDETAY_FATURA_IPTAL] @FIRMAID INT,  @YIL INT, @AY INT
AS
DECLARE @SAY INT
SELECT @SAY=COUNT(*) FROM FATURA INNER JOIN FATURADETAY ON FATURA.FATID=FATURADETAY.FATID 
WHERE FIRMAID=@FIRMAID AND YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND FATURA.FATCOUNTER>0 AND EFATNO<>''

IF @SAY<=0
	BEGIN
		UPDATE FATURA SET FISDURUMID=-2, SIL=-2 WHERE FIRMAID=@FIRMAID AND YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND FATURA.FATCOUNTER>0
		UPDATE SOZLESMEDETAY SET FTKESILDI=0, FATID=NULL WHERE SOZLESMEDETAYID IN(SELECT FATCOUNTER FROM FATURA 
		WHERE FIRMAID=@FIRMAID AND YEAR(TARIH)=@YIL AND MONTH(TARIH)=@AY AND FATURA.FATCOUNTER>0) 
	END

GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_HIZMETRAPORU]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPA_HIZMETRAPORU]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT ''01-SATISCI'' AS DURUM, SATISCIADI AS GOREVLIADI, HIZMETADI, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SUM(NETTUTAR) AS TUTAR,DOVIZ,
SUM(NETTUTAR_TL) AS TUTAR_TL, SUM(GOREVLI_TOPLAMPRIM) AS PRIM, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRM_TL,SATISCI_DOVIZ AS PRIMDOVIZ    FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY SATISCIADI,HIZMETADI,DOVIZ,SATISCI_DOVIZ
UNION ALL
SELECT ''01-GOREVLI'' AS DURUM, GOREVLIADI, HIZMETADI, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SUM(NETTUTAR) AS TUTAR,DOVIZ,
SUM(NETTUTAR_TL) AS TUTAR_TL, SUM(GOREVLI_TOPLAMPRIM) AS PRIM, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRM_TL,GOREVLI_DOVIZ AS PRIMDOVIZ FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY GOREVLIADI,HIZMETADI,DOVIZ,GOREVLI_DOVIZ
ORDER BY DURUM,GOREVLIADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_HIZMETRAPORU_KAPANDI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SPA_HIZMETRAPORU_KAPANDI]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT ''01-SATISCI'' AS DURUM, SATISCIADI AS GOREVLIADI, HIZMETADI, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SUM(NETTUTAR) AS TUTAR,DOVIZ,
SUM(NETTUTAR_TL) AS TUTAR_TL, SUM(GOREVLI_TOPLAMPRIM) AS PRIM, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRM_TL  FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE KAPANDI=1 AND 1=1 '+@PARAMETRE+'
GROUP BY SATISCIADI,HIZMETADI,DOVIZ
UNION ALL
SELECT ''01-GOREVLI'' AS DURUM, GOREVLIADI, HIZMETADI, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SUM(NETTUTAR) AS TUTAR,DOVIZ,
SUM(NETTUTAR_TL) AS TUTAR_TL, SUM(GOREVLI_TOPLAMPRIM) AS PRIM, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRM_TL  FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE KAPANDI=1 AND 1=1 '+@PARAMETRE+'
GROUP BY GOREVLIADI,HIZMETADI,DOVIZ
ORDER BY DURUM,GOREVLIADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_KASARAPORU]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPA_KASARAPORU] @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT SPAFIS.FIRMAID, ODEMETURU, SUM(SPAODEME.TUTAR) AS TUTAR, AVG(SPAODEME.KUR) AS KUR, SPAODEME.DOVIZ   
FROM SPAODEME WITH (NOLOCK) INNER JOIN SPAFIS WITH (NOLOCK) ON SPAODEME.SPAFISID=SPAFIS.SPAFISID
WHERE ISNULL(SPAFIS.SIL,0)=0 AND 1=1 '+@PARAMETRE+'
GROUP BY FIRMAID,ODEMETURU,SPAODEME.DOVIZ
ORDER BY SPAODEME.DOVIZ,ODEMETURU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_KASARAPORU_SATISCI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPA_KASARAPORU_SATISCI] @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @SQLCUMLE='
SELECT SPAFIS.FIRMAID, ODEMETURU, SPAGOREVLI.GOREVLIADI, SUM(SPAODEME.TUTAR) AS TUTAR, AVG(SPAODEME.KUR) AS KUR, SPAODEME.DOVIZ,  
SUM(SPAODEME.TUTAR)/100*ISNULL(SPAGOREVLI.PRIMORAN,0) AS PRIMTUTAR,SUM(SPAODEME.TUTAR)/100*ISNULL(SPAGOREVLI.PRIMORAN,0)*AVG(SPAODEME.KUR) AS PRIMTUTARTL, SPAGOREVLI.PRIMORAN
FROM SPAODEME WITH (NOLOCK) INNER JOIN SPAFIS WITH (NOLOCK) ON SPAODEME.SPAFISID=SPAFIS.SPAFISID
LEFT JOIN SPAGOREVLI ON SPAFIS.SPAGOREVLIID=SPAGOREVLI.SPAGOREVLIID
WHERE ISNULL(SPAFIS.SIL,0)=0  AND 1=1 '+@PARAMETRE+'
GROUP BY SPAFIS.FIRMAID,ODEMETURU,SPAODEME.DOVIZ,SPAGOREVLI.GOREVLIADI,SPAGOREVLI.PRIMORAN
ORDER BY SPAGOREVLI.GOREVLIADI,SPAODEME.DOVIZ,ODEMETURU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_PRIMRAPORU]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPA_PRIMRAPORU]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT ''01-SATISCI'' AS DURUM, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SATISCIADI AS GOREVLI, SUM(BIRIMFIYAT) AS TOPLAM, SUM(INDTUTAR) AS INDIRIM, SUM(NETTUTAR) AS SATISTOPLAM, CAST(''XX'' AS nvarchar(10)) as DOVIZ, 
AVG(KUR) AS KUR,SUM(BIRIMFIYAT_TL) AS TOPLAM_TL, SUM(INDTUTAR_TL) AS INDIRIM_TL, SUM(NETTUTAR_TL) AS SATISTOPLAM_TL,
SUM(SATISCI_TOPLAMPRIM) AS PRIMTUTAR, SUM(SATISCI_TOPLAMPRIM_TL) AS PRIMTUTAR_TL,SATISCI_DOVIZ AS PRIMDOVIZ   FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY SATISCIADI,SATISCI_DOVIZ
UNION ALL
SELECT ''01-GOREVLI'' AS DURUM, COUNT(*) AS ISLEM, SUM(SURE) AS SURE,GOREVLIADI AS GOREVLI, SUM(BIRIMFIYAT) AS TOPLAM, SUM(INDTUTAR) AS INDIRIM, SUM(NETTUTAR) AS SATISTOPLAM, CAST(''XX'' AS nvarchar(10)) as DOVIZ, 
AVG(KUR) AS KUR,SUM(BIRIMFIYAT_TL) AS TOPLAM_TL, SUM(INDTUTAR_TL) AS INDIRIM_TL, SUM(NETTUTAR_TL) AS SATISTOPLAM_TL,
SUM(GOREVLI_TOPLAMPRIM) AS PRIMTUTAR, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRIMTUTAR_TL,GOREVLI_DOVIZ AS PRIMDOVIZ FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' 
GROUP BY GOREVLIADI,GOREVLI_DOVIZ'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_PRIMRAPORU_GOREVLI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPA_PRIMRAPORU_GOREVLI]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2200)
SET @SQLCUMLE='SELECT ''01-GOREVLI'' AS DURUM, COUNT(*) AS ISLEM, SUM(SURE) AS SURE,GOREVLIADI AS GOREVLI, SUM(BIRIMFIYAT) AS TOPLAM, 
SUM(INDTUTAR) AS INDIRIM, SUM(NETTUTAR) AS SATISTOPLAM, cast(''x'' as nvarchar(5)) as DOVIZ, 
AVG(KUR) AS KUR,SUM(BIRIMFIYAT_TL) AS TOPLAM_TL, SUM(INDTUTAR_TL) AS INDIRIM_TL, SUM(NETTUTAR_TL) AS SATISTOPLAM_TL,
SUM(GOREVLI_TOPLAMPRIM) AS PRIMTUTAR, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRIMTUTAR_TL,GOREVLI_DOVIZ AS PRIMDOVIZ FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' 
GROUP BY GOREVLIADI,GOREVLI_DOVIZ'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPA_PRIMRAPORU_KAPANDI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SPA_PRIMRAPORU_KAPANDI]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1800)
SET @SQLCUMLE='SELECT ''01-SATISCI'' AS DURUM, COUNT(*) AS ISLEM, SUM(SURE) AS SURE, SATISCIADI AS GOREVLI, SUM(BIRIMFIYAT) AS TOPLAM, SUM(INDTUTAR) AS INDIRIM, SUM(NETTUTAR) AS SATISTOPLAM, DOVIZ, 
AVG(KUR) AS KUR,SUM(BIRIMFIYAT_TL) AS TOPLAM_TL, SUM(INDTUTAR_TL) AS INDIRIM_TL, SUM(NETTUTAR_TL) AS SATISTOPLAM_TL,
SUM(SATISCI_TOPLAMPRIM) AS PRIMTUTAR, SUM(SATISCI_TOPLAMPRIM_TL) AS PRIMTUTAR_TL FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE KAPANDI=1 AND 1=1 '+@PARAMETRE+'
GROUP BY DOVIZ,SATISCIADI
UNION ALL
SELECT ''01-GOREVLI'' AS DURUM, COUNT(*) AS ISLEM, SUM(SURE) AS SURE,GOREVLIADI AS GOREVLI, SUM(BIRIMFIYAT) AS TOPLAM, SUM(INDTUTAR) AS INDIRIM, SUM(NETTUTAR) AS SATISTOPLAM, DOVIZ, 
AVG(KUR) AS KUR,SUM(BIRIMFIYAT_TL) AS TOPLAM_TL, SUM(INDTUTAR_TL) AS INDIRIM_TL, SUM(NETTUTAR_TL) AS SATISTOPLAM_TL,
SUM(GOREVLI_TOPLAMPRIM) AS PRIMTUTAR, SUM(GOREVLI_TOPLAMPRIM_TL) AS PRIMTUTAR_TL FROM FNCQ_SPAANALIZ ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE KAPANDI=1 AND 1=1 '+@PARAMETRE+' 
GROUP BY DOVIZ,GOREVLIADI'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPAANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPAANALIZ]  @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10),@PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT  * FROM FNCQ_SPAANALIZ ('''+@FIRMAID+''','''+@TARIH+''','''+@TARIH2+''')  WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPAFIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SPAFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SPAFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPAGOREVLI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SPAGOREVLI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SPAGOREVLI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPAMEKAN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_SPAMEKAN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SPAMEKAN WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPAODEME]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SPAODEME]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SPAODEME WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPASATISKAPAT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SPASATISKAPAT] @SPAFISID INT, @DURUM SMALLINT
AS
IF @DURUM=1 
	BEGIN
		UPDATE AJANDA SET LABELCOLOR=1510596 WHERE SPAFISID=@SPAFISID
	END
IF @DURUM=2 
	BEGIN
		UPDATE AJANDA SET LABELCOLOR=536870912 WHERE SPAFISID=@SPAFISID
	END

/*8689404	PEMBE */
/*6610596	YEŞİL */
/*16051844	DENİZ MAVİSİ */
/*12897956	AÇIK MAVİ */
/*7649020	AÇIK PEMBE GİBİ */
/*16033476 MAVİ GİBİ */
/*7661308  */
/*1510596 KIRMIZI */
/*9910596 KOYU MAVİ */
/*536870912 boşş */
GO
/****** Object:  StoredProcedure [dbo].[PRL_SPASTOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_SPASTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,KATSAYI2,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,
SDOVIZ1,SDOVIZ2,SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,TURU,SATISIND,INDVERILIR,SURE,SKOMORAN AS KOMORANI, BKOMORAN AS KOMTUTARI,SDOVIZ AS KOMDOVIZ,PSTOK
FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SQLCONNECTION]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_SQLCONNECTION] 
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM    sys.sysprocesses ORDER BY login_time desc'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SQLSESSION]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SQLSESSION] 
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT conn.session_id, host_name, program_name,
    nt_domain, login_name, connect_time, last_request_end_time 
FROM sys.dm_exec_sessions AS sess
JOIN sys.dm_exec_connections AS conn
   ON sess.session_id = conn.session_id;'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STDRAPOR]  @SORGU NVARCHAR(MAX)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR 
(CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0) OR (CHARINDEX('DROP',@SORGU)>0) OR (CHARINDEX('NOVAUSER',@SORGU)>0) OR (CHARINDEX('NOVAUSERD',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE INSERT CREATE .. SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR_P1]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STDRAPOR_P1]  @SORGU NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR (CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR_P2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STDRAPOR_P2]  @SORGU NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR (CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR_P3]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STDRAPOR_P3]  @SORGU NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR (CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR_P4]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STDRAPOR_P4]  @SORGU NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR (CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STDRAPOR_P5]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STDRAPOR_P5]  @SORGU NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
IF (CHARINDEX('DELETE',@SORGU)>0) OR (CHARINDEX('UPDATE',@SORGU)>0) OR (CHARINDEX('INSERT',@SORGU)>0) OR (CHARINDEX('TRUNCATE',@SORGU)>0) OR (CHARINDEX('ALTER',@SORGU)>0)
	BEGIN
		SET @SQLCUMLE='SELECT ''DELETE UPDATE SQL CALISTIRILAMAZ'' AS ACIKLAMA'
		EXEC (@SQLCUMLE)
	END
ELSE
	BEGIN
		SET @SQLCUMLE=@SORGU
		IF CHARINDEX('FIRMAID=',@SQLCUMLE)>0
			BEGIN
				EXEC (@SQLCUMLE)
			END
		ELSE
			BEGIN
				SET @SQLCUMLE='SELECT ''FIRMAID PARAMETRESI OLMADAN CALISMAZ'' AS ACIKLAMA'
				EXEC (@SQLCUMLE)
			END
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK WITH (NOLOCK) WHERE TURU=''Hammadde'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOK_ANLASMA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOK_ANLASMA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK_ANLASMA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOK_ANLASMA_DETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOK_ANLASMA_DETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK_ANLASMA_DETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOK_FIYAT_ISLEM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOK_FIYAT_ISLEM] @FIRMAID INT, @GRUPID INT, @STOKID INT, @KGFIYATI FLOAT, 
@SALISFIYAT FLOAT, @KARORANI FLOAT,@ISLEMTURU NVARCHAR(20),
@ASGARI FLOAT, @OPTIMAL FLOAT, @FIYAT FLOAT, @KDVORAN INT, @BIRIM NVARCHAR(15), @GGRUP NVARCHAR(10)
AS
BEGIN
DECLARE @SAY INT
DECLARE @KDVDAHIL BIT
BEGIN TRANSACTION
BEGIN TRY
IF @ISLEMTURU='GRUPUPDATE'
BEGIN
	UPDATE STOK SET GRUPID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='ANAGRUPUPDATE'
BEGIN
	UPDATE STOK SET STOKGRUPID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='GRUPSIL'
BEGIN
	UPDATE STOK SET GRUPID=NULL, STOKGRUPID=NULL WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='MARKAUPDATE'
BEGIN
	UPDATE STOK SET MARKAID=@GRUPID WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
ELSE IF @ISLEMTURU='KGALISFIYAT'
	BEGIN
		UPDATE STOK SET KGFIYATI=@KGFIYATI, SALISFIYAT=(@KGFIYATI)*AGIRLIK, 
		SALISBFIYAT=(@KGFIYATI)*AGIRLIK, MALIYET=(@KGFIYATI)*AGIRLIK
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KGALISSATISFIYAT'
	BEGIN
		UPDATE STOK SET KGFIYATI=@KGFIYATI, SALISFIYAT=(@KGFIYATI)*AGIRLIK, 
		SALISBFIYAT=(@KGFIYATI)*AGIRLIK, MALIYET=@KGFIYATI*AGIRLIK,
		SFIYAT1=((@KGFIYATI*AGIRLIK)/100)*(100+@KARORANI)
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KGSATIS'
	BEGIN
		UPDATE STOK SET SFIYAT1=((KGFIYATI*AGIRLIK)/100)*(100+@KARORANI)
		WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND KGFIYATI>0 AND AGIRLIK>0
	END
ELSE IF @ISLEMTURU='ASGARI'
	BEGIN
		UPDATE STOK SET ASGARI=@ASGARI WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='OPTIMAL'
	BEGIN
		UPDATE STOK SET OPTIMAL=@OPTIMAL WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT1'
	BEGIN
		UPDATE STOK SET SFIYAT1=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID	
	END
ELSE IF @ISLEMTURU='SFIYAT2'
	BEGIN
		UPDATE STOK SET SFIYAT2=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT3'
	BEGIN
		UPDATE STOK SET SFIYAT3=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT4'
	BEGIN
		UPDATE STOK SET SFIYAT4=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='SFIYAT5'
	BEGIN
		UPDATE STOK SET SFIYAT5=@FIYAT WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END

ELSE IF @ISLEMTURU='SFIYAT1Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT2Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT2=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT2=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT3Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT3=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT3=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT4Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT4=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT4=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END
ELSE IF @ISLEMTURU='SFIYAT5Y'
	BEGIN
		SELECT @KDVDAHIL=SFIYAT1KDV FROM STOK WHERE STOKID=@STOKID
		IF @KDVDAHIL=1 
			BEGIN
				UPDATE STOK SET SFIYAT5=ROUND(((SALISFIYAT/100)*(100+@KARORANI))/100*(100+SATISKDV),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT5=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SALISFIYAT>0
			END
	END



ELSE IF @ISLEMTURU='SFIYAT1YS'
	BEGIN
		UPDATE STOK SET SFIYAT1=ROUND(((SFIYAT1/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT1>0
	END
ELSE IF @ISLEMTURU='SFIYAT2YS'
	BEGIN
		UPDATE STOK SET SFIYAT2=ROUND(((SFIYAT2/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT2>0
	END
ELSE IF @ISLEMTURU='SFIYAT3YS'
	BEGIN
		UPDATE STOK SET SFIYAT3=ROUND(((SFIYAT3/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT3>0
	END
ELSE IF @ISLEMTURU='SFIYAT4YS'
	BEGIN
		UPDATE STOK SET SFIYAT4=ROUND(((SFIYAT4/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT4>0
	END
ELSE IF @ISLEMTURU='SFIYAT5YS'
	BEGIN
		UPDATE STOK SET SFIYAT5=ROUND(((SFIYAT5/100)*(100+@KARORANI)),2) WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID AND SFIYAT5>0
	END
ELSE IF @ISLEMTURU='SIL'
	BEGIN
		UPDATE STOK SET SIL=-2,DEL_USERID=-2 WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='KDV'
	BEGIN
		UPDATE STOK SET ALISKDV=@KDVORAN, SATISKDV=@KDVORAN WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='BIRIM'
	BEGIN
		UPDATE STOK SET BIRIM=@BIRIM WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='GGRUP'
	BEGIN
		UPDATE STOK SET GGRUP=@GGRUP WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
	END
ELSE IF @ISLEMTURU='ANLASMAYAGORE'
	BEGIN
		SELECT @SAY=COUNT(*) FROM FNCQ_ANLASMAOZET(@FIRMAID) WHERE STOKID=@STOKID AND NETFIYAT>0
		IF @SAY>0
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((NETFIYAT/100)*(100+@KARORANI),2) FROM STOK INNER JOIN  FNCQ_ANLASMAOZET(@FIRMAID) AS ANLASMA ON STOK.STOKID=ANLASMA.STOKID
				WHERE STOK.FIRMAID=@FIRMAID AND  STOK.STOKID=@STOKID AND ANLASMA.STOKID=@STOKID
			END
		ELSE
			BEGIN
				UPDATE STOK SET SFIYAT1=ROUND((SALISFIYAT/100)*(100+@KARORANI),2) WHERE FIRMAID=@FIRMAID AND  STOKID=@STOKID
			END
	END	
COMMIT TRANSACTION
END TRY
BEGIN CATCH
RAISERROR('HATA OLUSTUR',16,1)
ROLLBACK TRANSACTION
END CATCH
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKANALIZ] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
DECLARE
@SQLCUMLE NVARCHAR(900),
@FONKSIYONADI NVARCHAR(30)
SET @FONKSIYONADI='FNCQ_STOKISLEMLER'
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @FONKSIYONADI='FNCQ_STOKISLEMLER_OKCRESMI' 
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @PARAMETRE=REPLACE(@PARAMETRE,'AND OKCFISNO<>''''','')
SET @SQLCUMLE='
SELECT YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, TARIH,SUBEID,SUBEADI,FISTIPI,DEPOID,DEPOKODU,DEPOADI,ISLEM,GRUPKODU,GRUPADI,STOKKODU, STOKADI, FBIRIM, 
SUM(ABS(GCADET)) AS MIKTAR, NULLIF(SUM((GCADET*-1)*NFIYAT),0) / NULLIF(SUM((GCADET*-1)),0) AS ORTFIYAT, 
CARIKODU,CARIUNVANI, NULLIF(SUM((GCADET*-1)*NFIYAT),0) AS TOPLAM, NULLIF(SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)),0)/ NULLIF(SUM((GCADET*-1)),0) AS ORTMALIYET,
SUM((GCADET*-1)*ISNULL(BMALIYET,ISNULL(BIRIMMALIYET,0))) AS TOPLAMMALIYET,  NULLIF(SUM((GCADET*-1)*NFIYAT),0)-SUM((GCADET*-1)*ISNULL(BMALIYET,ISNULL(BIRIMMALIYET,0))) as FARK
FROM '+@FONKSIYONADI+'  ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY TARIH,SUBEID,SUBEADI,FISTIPI,DEPOID,DEPOKODU,DEPOADI,ISLEM,GRUPKODU,GRUPADI,CARIKODU,STOKADI,STOKKODU,CARIUNVANI,FBIRIM'
EXEC (@SQLCUMLE)
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKANALIZ_AYLIK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKANALIZ_AYLIK] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
DECLARE
@SQLCUMLE NVARCHAR(800),
@FONKSIYONADI NVARCHAR(30)
SET @FONKSIYONADI='FNCQ_STOKISLEMLER'
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @FONKSIYONADI='FNCQ_STOKISLEMLER_OKCRESMI' 
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @PARAMETRE=REPLACE(@PARAMETRE,'AND OKCFISNO<>''''','')
SET @SQLCUMLE='
SELECT YEAR(TARIH) AS YIL, MONTH(TARIH) AS AY, SUM(ABS(GCADET)) AS MIKTAR, NULLIF(SUM((GCADET*-1)*NFIYAT),0) / NULLIF(SUM((GCADET*-1)),0) AS ORTFIYAT, 
 NULLIF(SUM((GCADET*-1)*NFIYAT),0) AS TOPLAM, NULLIF(SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)),0)/ NULLIF(SUM((GCADET*-1)),0) AS ORTMALIYET,
SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) AS TOPLAMMALIYET,  NULLIF(SUM((GCADET*-1)*NFIYAT),0)-SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) as FARK
FROM '+@FONKSIYONADI+' ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY  YEAR(TARIH), MONTH(TARIH) ORDER BY YEAR(TARIH), MONTH(TARIH)'
EXEC (@SQLCUMLE)
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKANALIZ_BAKIYE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKANALIZ_BAKIYE] @TARIH NVARCHAR(10),@TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SUBEKODU,SUBEADI,DEPOKODU,DEPOADI,GRUPKODU,GRUPADI,STOKADI,BARKOD, AVG(SALISBFIYAT) AS ALISFIYATI, BIRIM,AVG(NFIYAT) AS NFIYAT,AVG(SFIYAT1) AS SFIYAT1,SUM(GCADET) AS KALAN, SUM(GCADET)*AVG(SALISBFIYAT) AS KALANMALIYET, 
SUM(GCADET)*AVG(SFIYAT1) AS SATISBEDELI FROM [FNCQ_STOKBAKIYE2] ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+'
GROUP BY SUBEKODU,SUBEADI,DEPOKODU,DEPOADI,GRUPKODU,GRUPADI,STOKADI,BIRIM,BARKOD'
EXEC (@SQLCUMLE)
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKANLASMA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_STOKANLASMA] @LIMIT NVARCHAR(5), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(500)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM FNCQ_STOKANLASMA('+@FIRMAID+') WHERE 1=1 '+@PARAMETRE
EXEC(@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STOKBAKIYE]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)

SET @SQLCUMLE='SELECT STOKID,SUM(KALAN) AS KALAN FROM (SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE_DEVRI ('''+@TARIH+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID
UNION ALL
SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID) AS TBL GROUP BY STOKID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYE_DEVRI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STOKBAKIYE_DEVRI]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@TARIHX SMALLDATETIME,
@TARIHD NVARCHAR(10),
@SQLCUMLE NVARCHAR(500)

SET @TARIHX=CAST(@TARIH AS DATETIME)
SET @TARIHX=@TARIHX-1
SET @TARIHD=convert(varchar, @TARIHX, 23)

SET @SQLCUMLE='SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYE_MOBIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBAKIYE_MOBIL]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT STOKADI,BIRIM,RENKADI,BEDEN,SUM(GCADET) AS KALAN  
FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') AS Q 
LEFT JOIN RENKLER ON Q.RENKID=RENKLER.RENKLERID AND RENKLER.FIRMAID='+@FIRMAID+' LEFT JOIN BEDENLER ON Q.BEDENID=BEDENLER.BEDENLERID 
AND BEDENLER.FIRMAID='+@FIRMAID+' WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKADI,BIRIM,RENKADI,BEDEN'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYE2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBAKIYE2]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200), @DEVIRLI  NVARCHAR(10)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
IF @DEVIRLI='EVET'
	BEGIN
		SET @SQLCUMLE='SELECT STOKID,SUM(KALAN) AS KALAN FROM (SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE_DEVRI ('''+@TARIH+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID
		UNION ALL
		SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID) AS TBL GROUP BY STOKID'
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT STOKID,SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYE ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID'
	END
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYEOZET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBAKIYEOZET]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT (SELECT SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE GCADET>0 AND 1=1 '+@PARAMETRE+') AS GIREN,
(SELECT SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE GCADET<0 AND 1=1 '+@PARAMETRE+') AS CIKAN,
(SELECT SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE+') AS KALAN'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYEOZET_KALAN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBAKIYEOZET_KALAN]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT STOKID, SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE+' 
GROUP BY STOKID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBAKIYESAYIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_STOKBAKIYESAYIM]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT STOKID, SUM(GCADET) AS KALANMIKTAR FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE+' GROUP BY STOKID'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBARKOD]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBARKOD]  
@FIRMAID INT,
@BARKOD NVARCHAR(30)
AS
BEGIN
	SELECT ISNULL(B.BARKOD,S.BARKOD) AS BARKOD, PLUNO, S.STOKID AS STOKID, S.GRUPID, S.GRUP AS GRUP, SG.GRUPADI, ISNULL(S.ETERAZI,0) AS ETERAZI, S.KODU AS SKODU, S.ADI AS STOKADI, 
	R.RENKLERID,BD.BEDENLERID, R.RENKADI AS RENK, BD.BEDEN AS BEDEN, S.ALISKDV, S.SATISKDV, S.SERILOTVAR,S.MALIYET, 
	ISNULL(B.BIRIM,S.BIRIM) AS BIRIM, ISNULL(S.FATURABIRIMI,S.BIRIM) AS FATURABIRIMI, 
	S.BIRIM AS ANABIRIM,S.BIRIM2 AS BIRIM2, ISNULL(S.KATSAYI2,1) AS KATSAYI2, S.BIRIM3 AS BIRIM3, S.BIRIM4,S.BIRIM5, ISNULL(S.KATSAYI3,1) AS KATSAYI3, ISNULL(S.KATSAYI4,1) AS KATSAYI4,
	ISNULL(S.KATSAYI5,1) AS KATSAYI5,
	(case WHEN  B.DMIKTAR=NULL OR B.DMIKTAR=0 THEN 1 ELSE ISNULL(B.DMIKTAR,1) END) AS KATSAYI, S.SFIYAT1 AS ANABIRIMFIYAT,   
	CAST((CASE WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM THEN S.SFIYAT1 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM2 THEN S.SFIYAT2 
	WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM3 THEN S.SFIYAT3 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM4 THEN S.SFIYAT4 ELSE ISNULL(B.FIYATI,S.SFIYAT1) END) AS FLOAT) AS FIYAT, 
	S.SFIYAT1, S.SFIYAT2, S.SFIYAT3, S.SFIYAT4,S.SFIYAT5,
	ISNULL(S.SDOVIZ1,'TL') AS SDOVIZ1, ISNULL(S.SDOVIZ2,'TL') AS SDOVIZ2, ISNULL(S.SDOVIZ3,'TL') AS SDOVIZ3, ISNULL(S.SDOVIZ4,'TL') AS SDOVIZ4, ISNULL(S.SDOVIZ5,'TL') AS SDOVIZ5,S.SALISFIYAT AS SALISFBFIYAT,SFIYAT1KDV 
	FROM STOK AS S WITH (NOLOCK) LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON S.STOKID=B.STOKID AND  B.FIRMAID=@FIRMAID   LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID 
	AND SG.FIRMAID=@FIRMAID  
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID 
	WHERE  S.FIRMAID=@FIRMAID AND ISNULL(KKALDIR,0)=0 AND ISNULL(S.SIL,0)=0 AND ISNULL(B.BARKOD,S.BARKOD)=@BARKOD
	/*AND ISNULL(S.DSATIS,0)=1 */
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBARKOD_15112021]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBARKOD_15112021]  
@FIRMAID INT,
@BARKOD NVARCHAR(30)
AS
BEGIN
	SELECT ISNULL(B.BARKOD,S.BARKOD) AS BARKOD, PLUNO, S.STOKID AS STOKID, S.GRUPID, S.GRUP AS GRUP, SG.GRUPADI, ISNULL(S.ETERAZI,0) AS ETERAZI, S.KODU AS SKODU, S.ADI AS STOKADI, 
	R.RENKLERID,BD.BEDENLERID, R.RENKADI AS RENK, BD.BEDEN AS BEDEN, S.ALISKDV, S.SATISKDV, S.SERILOTVAR, 
	ISNULL(B.BIRIM,S.BIRIM) AS BIRIM, ISNULL(S.FATURABIRIMI,S.BIRIM) AS FATURABIRIMI, 
	S.BIRIM AS ANABIRIM,S.BIRIM2 AS BIRIM2, ISNULL(S.KATSAYI2,1) AS KATSAYI2, S.BIRIM3 AS BIRIM3, ISNULL(S.KATSAYI3,1) AS KATSAYI3,
	(case WHEN  B.DMIKTAR=NULL OR B.DMIKTAR=0 THEN 1 ELSE ISNULL(B.DMIKTAR,1) END) AS KATSAYI, S.SFIYAT1 AS ANABIRIMFIYAT,   
	CAST((CASE WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM THEN S.SFIYAT1 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM2 THEN S.SFIYAT2 
	WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM3 THEN S.SFIYAT3 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=S.BIRIM4 THEN S.SFIYAT4 ELSE ISNULL(B.FIYATI,S.SFIYAT1) END) AS FLOAT) AS FIYAT, 
	S.SFIYAT1, S.SFIYAT2, S.SFIYAT3, S.SFIYAT4,S.SFIYAT5,
	ISNULL(S.SDOVIZ1,'TL') AS SDOVIZ1, ISNULL(S.SDOVIZ2,'TL') AS SDOVIZ2, ISNULL(S.SDOVIZ3,'TL') AS SDOVIZ3, ISNULL(S.SDOVIZ4,'TL') AS SDOVIZ4, ISNULL(S.SDOVIZ5,'TL') AS SDOVIZ5,S.SALISFIYAT AS SALISFBFIYAT,SFIYAT1KDV 
	FROM STOK AS S WITH (NOLOCK) LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON S.STOKID=B.STOKID AND  B.FIRMAID=@FIRMAID   LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON S.GRUPID=SG.SGRUPID 
	AND SG.FIRMAID=@FIRMAID  
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID 
	WHERE  S.FIRMAID=@FIRMAID AND ISNULL(KKALDIR,0)=0 AND ISNULL(S.SIL,0)=0 AND ISNULL(B.BARKOD,S.BARKOD)=@BARKOD
	--AND ISNULL(S.DSATIS,0)=1
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKBARKOD_DEPO]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKBARKOD_DEPO]  
@FIRMAID INT,
@DEPOID INT,
@BARKOD NVARCHAR(30)
AS
BEGIN
	SELECT ISNULL(B.BARKOD,STOK.BARKOD) AS BARKOD, PLUNO, STOK.STOKID AS STOKID, STOK.GRUP AS GRUP, SG.GRUPADI, ISNULL(STOK.ETERAZI,0) AS ETERAZI, STOK.KODU AS SKODU, STOK.ADI AS STOKADI, 
	R.RENKLERID,BD.BEDENLERID, R.RENKADI AS RENK, BD.BEDEN AS BEDEN, STOK.ALISKDV, STOK.SATISKDV, STOK.SERILOTVAR, STOK.MALIYET, 
	ISNULL(B.BIRIM,STOK.BIRIM) AS BIRIM, ISNULL(STOK.FATURABIRIMI,STOK.BIRIM) AS FATURABIRIMI, 
	STOK.BIRIM AS ANABIRIM,STOK.BIRIM2 AS BIRIM2, ISNULL(STOK.KATSAYI2,1) AS KATSAYI2, STOK.BIRIM3 AS BIRIM3, ISNULL(STOK.KATSAYI3,1) AS KATSAYI3,
	(case WHEN  B.DMIKTAR=NULL OR B.DMIKTAR=0 THEN 1 ELSE ISNULL(B.DMIKTAR,1) END) AS KATSAYI, SUBEFIYAT.SFIYAT1 AS ANABIRIMFIYAT,   
	CAST((CASE WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM THEN SUBEFIYAT.SFIYAT1 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM2 THEN STOK.SFIYAT2 
	WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM3 THEN SUBEFIYAT.SFIYAT3 WHEN ISNULL(B.FIYATI,0)=0 AND B.BIRIM=STOK.BIRIM4 THEN SUBEFIYAT.SFIYAT4 ELSE ISNULL(B.FIYATI,SUBEFIYAT.SFIYAT1) END) AS FLOAT) AS FIYAT, 
	SUBEFIYAT.SFIYAT1, SUBEFIYAT.SFIYAT2, SUBEFIYAT.SFIYAT3, SUBEFIYAT.SFIYAT4,SUBEFIYAT.SFIYAT5,
	ISNULL(SUBEFIYAT.DOVIZ1,'TL') AS SDOVIZ1, ISNULL(SUBEFIYAT.DOVIZ2,'TL') AS SDOVIZ2, ISNULL(SUBEFIYAT.DOVIZ3,'TL') AS SDOVIZ3, ISNULL(SUBEFIYAT.DOVIZ4,'TL') AS SDOVIZ4, ISNULL(SUBEFIYAT.DOVIZ5,'TL') AS SDOVIZ5,STOK.SALISFBFIYAT,SFIYAT1KDV 
	FROM SUBEFIYAT WITH (NOLOCK) 
	INNER JOIN STOK WITH (NOLOCK) ON SUBEFIYAT.STOKID=STOK.STOKID AND STOK.FIRMAID=@FIRMAID
	LEFT JOIN  BARKOD AS B WITH (NOLOCK) ON STOK.STOKID=B.STOKID  AND B.FIRMAID=@FIRMAID
	LEFT JOIN SGRUP AS SG WITH (NOLOCK) ON STOK.GRUPID=SG.SGRUPID  AND SG.FIRMAID=@FIRMAID 
	LEFT JOIN RENKLER AS R WITH (NOLOCK) ON B.RENKID=R.RENKLERID  AND R.FIRMAID=@FIRMAID
	LEFT JOIN BEDENLER AS BD WITH (NOLOCK) ON B.BEDENID=BD.BEDENLERID AND BD.FIRMAID=@FIRMAID
	WHERE SUBEFIYAT.FIRMAID=@FIRMAID and SUBEFIYAT.DEPOID=@DEPOID AND  ISNULL(B.BARKOD,STOK.BARKOD)=@BARKOD 
	/*AND ISNULL(S.DSATIS,0)=1 */
	/*ISNULL(KKALDIR,0)=0 AND ISNULL(STOK.SIL,0)=0 AND */
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKGIRISYAP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKGIRISYAP] @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DEPOID INT, @TARIH NVARCHAR(10),
@STOKID INT, @BARKOD NVARCHAR(30), @MIKTAR FLOAT,@BIRIM NVARCHAR(10), @BFIYAT FLOAT 
AS
DECLARE 
@DEPOFISID INT,
@DEPOFISUUID uniqueidentifier

IF (SELECT COUNT(*) FROM DEPOFIS WHERE GDEPOID=@DEPOID AND TARIH=@TARIH AND EK2='STOKISLEM' AND ISNULL(SIL,0)=0)>0
	BEGIN
		set @DEPOFISUUID=(SELECT top 1 DEPOFISUUID FROM DEPOFIS WHERE GDEPOID=@DEPOID AND TARIH=@TARIH AND EK2='STOKISLEM' AND ISNULL(SIL,0)=0)

		SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WHERE DEPOFISUUID=@DEPOFISUUID

		INSERT INTO DEPOFISISL (DEPOFISID,BARKOD,STOKID,FMIKTAR,FBFIYAT,MIKTAR,BFIYAT,FBMALIYET,ACIKLAMA,YETKILI)
		VALUES(@DEPOFISID,@BARKOD,@STOKID,@MIKTAR,@BFIYAT,@MIKTAR,@BFIYAT,@BFIYAT,'Hızlı Stok Giriş','SYSTEM')
	END
ELSE
	BEGIN
		set @DEPOFISUUID=NEWID()
		INSERT INTO DEPOFIS (DEPOFISUUID,FIRMAID,SUBEID,TARIH,ISLEM,ENO,ACIKLAMA,EK2,GDEPOID,GSUBEID)
		VALUES(@DEPOFISUUID,@FIRMAID,@SUBEID,@TARIH,'SAYIM',SUBSTRING(CAST(@DEPOFISUUID AS nvarchar(100)),1,8),'Stok Giriş İşlemi','STOKISLEM',@DEPOID, @SUBEID)
		
		SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WHERE DEPOFISUUID=@DEPOFISUUID

		INSERT INTO DEPOFISISL (DEPOFISID,BARKOD,STOKID,FMIKTAR,FBFIYAT,MIKTAR,BFIYAT,FBMALIYET,ACIKLAMA,YETKILI)
		VALUES(@DEPOFISID,@BARKOD,@STOKID,@MIKTAR,@BFIYAT,@MIKTAR,@BFIYAT,@BFIYAT,'Hızlı Stok Giriş','SYSTEM')
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKGRAFIK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKGRAFIK]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700),
@FONKSIYONADI NVARCHAR(30)
SET @FONKSIYONADI='FNCQ_STOKISLEMLER'
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @FONKSIYONADI='FNCQ_STOKISLEMLER_OKCRESMI' 
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @PARAMETRE=REPLACE(@PARAMETRE,'AND OKCFISNO<>''''','')
SET @SQLCUMLE='SELECT  TARIH, DAY(TARIH) AS GUN, MONTH(TARIH) AS AY, SUM((GCADET*-1)) AS TOPLAMMIKTAR, SUM((GCADET*-1)*NFIYAT) AS TOPLAMSTUTAR,
    SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) AS TOPLAMMALIYET, SUM((GCADET*-1)*NFIYAT)-SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) AS SATISKAR 
	FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE+' GROUP BY TARIH ORDER BY TARIH '
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKGRAFIKOZET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKGRAFIKOZET]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700),
@FONKSIYONADI NVARCHAR(30)
SET @FONKSIYONADI='FNCQ_STOKISLEMLER'
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @FONKSIYONADI='FNCQ_STOKISLEMLER_OKCRESMI' 
IF CHARINDEX('OKCFISNO',@PARAMETRE)>0 SET @PARAMETRE=REPLACE(@PARAMETRE,'AND OKCFISNO<>''''','')
SET @SQLCUMLE='SELECT SUM((GCADET*-1)*NFIYAT) AS TOPLAMSTUTAR,SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) AS TOPLAMMALIYET,SUM((GCADET*-1)*NFIYAT)-SUM((GCADET*-1)*ISNULL(BMALIYET,BIRIMMALIYET)) AS SATISKAR
	FROM '+@FONKSIYONADI+' ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE ISLEM=''SATIS'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKHAREKET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKHAREKET]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_STOKDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE+' ORDER BY TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKHAREKET2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_STOKHAREKET2]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_STOKDETAY ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKINDIRIM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STOKINDIRIM]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOKINDIRIM WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKINDIRIMDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_STOKINDIRIMDETAY]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOKINDIRIMDETAY WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKKALAN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_STOKKALAN]   @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10),@STOKID NVARCHAR(10),@PARAMETRE NVARCHAR(200)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT (SELECT SUM(GCADET) AS KALAN FROM FNCQ_STOKBAKIYEOZET ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''','''+@STOKID+''') WHERE 1=1 '+@PARAMETRE+') AS KALAN'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKMARKA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKMARKA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOKMARKA WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKPAKET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKPAKET]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOKPAKET WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKTERAZI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKTERAZI]  @PARAMETRE NVARCHAR(250)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT PLUNO AS PLUNo, PLUNO AS ItemCode, SUBSTRING(ADI,1,20) AS Name1, SUBSTRING(ISNULL(EK2,ADI),1,20) AS Name2, 
SFIYAT1*100 AS UPrice, null as ValiDate, 0 as Tare,0 as GCode, 0 as MessageNo
FROM STOK WHERE ISNULL(SIL,0)=0 AND LEN(PLUNO)=4 AND BARKOD LIKE''270%''
AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKTERAZICL3000]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_STOKTERAZICL3000]  @PARAMETRE NVARCHAR(250)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ''1'' AS [1.Department No], PLUNO AS [2.PLU No], ''1'' AS [4.PLU Type], 
PLUNO AS [11.ItemCode], SUBSTRING(ADI,1,20) AS [10.Name], 
SFIYAT1*100 AS [6.Price] FROM STOK WHERE ISNULL(SIL,0)=0 AND LEN(PLUNO)=4 AND BARKOD LIKE''270%''
AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKUPDATE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKUPDATE]  @FIRMAID INT, @STOKID INT, @STOKADI NVARCHAR(50), @SFIYAT1 FLOAT, @SFIYAT2 FLOAT, @SFIYAT3 FLOAT
AS
BEGIN
UPDATE STOK SET ADI=@STOKADI, SFIYAT1=@SFIYAT1, SFIYAT2=@SFIYAT2, SFIYAT3=@SFIYAT3 WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_STOKUPDATE2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_STOKUPDATE2]  @FIRMAID INT, @STOKID INT, @STOKADI NVARCHAR(50), @SFIYAT1 FLOAT, @SFIYAT2 FLOAT, @SFIYAT3 FLOAT, @MALIYET FLOAT
AS
BEGIN
UPDATE STOK SET ADI=@STOKADI, SFIYAT1=@SFIYAT1, SFIYAT2=@SFIYAT2, SFIYAT3=@SFIYAT3, MALIYET=@MALIYET, SALISFIYAT=@MALIYET WHERE FIRMAID=@FIRMAID AND STOKID=@STOKID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SUBEBANKA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SUBEBANKA]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SUBEBANKA WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SUBEFIYAT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_SUBEFIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(100)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SUBEFIYAT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SUBELER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_SUBELER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SUBELER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_SUBESABLON]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_SUBESABLON]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SUBESABLON WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_ACENTAFIYAT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_ACENTAFIYAT]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_ACENTAFIYAT WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_ACENTALAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_ACENTALAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_ACENTALAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_BELDE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_BELDE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_BELDE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_BOLGE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_BOLGE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_BOLGE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_OTELLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_OTELLER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_OTELLER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_PROGRAMLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_PROGRAMLAR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_PROGRAMLAR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_PROGRAMOTEL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_PROGRAMOTEL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_PROGRAMOTEL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_REHBER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_REHBER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_REHBER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_SOFOR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_SOFOR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_SOFOR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_T_TURREZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_T_TURREZ]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(750)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1200)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM T_TURREZ WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TABLOLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE PROCEDURE [dbo].[PRL_TABLOLAR]
AS
SET NOCOUNT ON
BEGIN
DECLARE @SQL NVARCHAR(600)
SET @SQL='SELECT ROUTINE_NAME ADI, ROUTINE_TYPE AS TURU,  ROUTINE_DEFINITION AS PARAMETRE
  FROM NOVADB.INFORMATION_SCHEMA.ROUTINES
 WHERE ROUTINE_TYPE = ''PROCEDURE''
 UNION ALL
 SELECT ROUTINE_NAME ADI, ROUTINE_TYPE AS TURU,  ROUTINE_DEFINITION AS PARAMETRE
  FROM NOVADB.INFORMATION_SCHEMA.ROUTINES
 WHERE ROUTINE_TYPE = ''FUNCTION''
 UNION ALL
 SELECT TABLE_NAME AS ADI,TABLE_TYPE AS TURU, '''' AS PARAMETRE FROM INFORMATION_SCHEMA.TABLES 
 WHERE TABLE_TYPE=''BASE TABLE'' ORDER BY TURU,ADI'
EXEC (@SQL)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TAKVIM_EKLE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TAKVIM_EKLE]
AS
DECLARE @GUN INT
SET @GUN=0

WHILE (@GUN<=5000)
	BEGIN
		DECLARE @TARIH SMALLDATETIME
		SELECT @TARIH=MAX(TARIH)+1 FROM TAKVIM
		IF @TARIH<='2000-01-01'
			BEGIN
				INSERT INTO TAKVIM  (TARIH) VALUES('2018-01-01')
				SELECT @TARIH=MAX(TARIH) FROM TAKVIM
			END
		INSERT INTO TAKVIM (TARIH) VALUES(@TARIH)
		SET @GUN=@GUN+1
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_THESAPKOD]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_THESAPKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID,HESAPID,KODU,ACIKLAMA,DOVIZ,UCHESAP,HESAPTIPID FROM MUH_HESAP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TOPLU_GUNCELLEME]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TOPLU_GUNCELLEME] @ISLEMID NVARCHAR(10), @PROJEID NVARCHAR(10), @MASMERID NVARCHAR(10), 
@DAIREID NVARCHAR(10), @ALTCARIID NVARCHAR(10), @ISLEMGRUPID1 NVARCHAR(10), @ISLEMGRUPID2 NVARCHAR(10),@ISLEMGRUPID3 NVARCHAR(10),
@HESAPID NVARCHAR(10), @ENTKAYITID NVARCHAR(10)
AS
DECLARE @SQLCUMLE NVARCHAR(200)
DECLARE @TAMSQL NVARCHAR(500)

SET @SQLCUMLE=''
IF @ISLEMID>'0'
	BEGIN
		IF @PROJEID>0 SET @SQLCUMLE=@SQLCUMLE+', PROJEID='+@PROJEID
		IF @MASMERID>0 SET @SQLCUMLE=@SQLCUMLE+', MASMERID='+@MASMERID
		IF @DAIREID>0 SET @SQLCUMLE=@SQLCUMLE+', OZELKODID='+@DAIREID
		IF @ALTCARIID>0 SET @SQLCUMLE=@SQLCUMLE+', ALTCARIID='+@ALTCARIID
		IF @ISLEMGRUPID1>0 SET @SQLCUMLE=@SQLCUMLE+', ISLEMGRUPID1='+@ISLEMGRUPID1
		IF @ISLEMGRUPID2>0 SET @SQLCUMLE=@SQLCUMLE+', ISLEMGRUPID2='+@ISLEMGRUPID2
		IF @ISLEMGRUPID3>0 SET @SQLCUMLE=@SQLCUMLE+', ISLEMGRUPID3='+@ISLEMGRUPID3
		IF @HESAPID>0 SET @SQLCUMLE=@SQLCUMLE+', HESAPID='+@HESAPID
		IF @ENTKAYITID>0 SET @SQLCUMLE=@SQLCUMLE+', ENTKAYITID='+@ENTKAYITID
		IF @ENTKAYITID>0 SET @SQLCUMLE=@SQLCUMLE+', ENTKAYNAK=''EMLAKSATIS_MUH'''
		SET @SQLCUMLE=SUBSTRING(@SQLCUMLE,2,200)
		SET @TAMSQL='UPDATE MUH_HESAPISL SET '+@SQLCUMLE+' WHERE ISLEMID=0'+@ISLEMID
		EXEC(@TAMSQL)
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TOPLUBORCFISI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TOPLUBORCFISI]  
@FISUUID uniqueidentifier,
@TARIH SMALLDATETIME,
@VADE SMALLDATETIME,
@EKLEMETARIH SMALLDATETIME,
@GELIRHESAPID INT,
@USERID INT,
@SUBEID INT,
@FIRMAID INT,
@FISTURID INT,
@AIDATFISID INT,
@DOVIZ NVARCHAR(10),
@KUR FLOAT,
@FISTURU INT
AS
BEGIN 
declare @FISID INT
declare @HATA INT
DECLARE @ISLEMGRUPID1 INT
BEGIN TRANSACTION
		SELECT @ISLEMGRUPID1=ISLEMGRUPID1 FROM AIDATFIS WHERE AIDATFISID=@AIDATFISID
		INSERT INTO MUH_FIS (FISUUID,FISHESAPID,TARIH, VADE, FISNO, FISTURU, FISTURID, ACIKLAMA, OZELKOD1, FIRMAID,SUBEID, ENTKAYNAK, ENTKAYNAKID, ADD_USERID, ADD_DATE, 
		TOPLAM, DTOPLAM, PASIF, FISDURUMID,DOVIZ,KUR,BELGENO,BELGEACIKLAMA,ODEMEYONTEMI,BELGETURU,DETAYLIENTEGRE,ISLEMGRUPID1) 
		VALUES (@FISUUID,@GELIRHESAPID,@TARIH,@VADE, DBO.FNMUH_FISNO_VER(@SUBEID,'Borç Dekontu',@TARIH), 'Borç Dekontu' ,@FISTURID,'Toplu Borçlandırma Fişi','',@FIRMAID,@SUBEID,'TOPLUBORC',@AIDATFISID, @USERID,@EKLEMETARIH, 0, 
		0, 0, 0,@DOVIZ,@KUR,@FISID,'Muhasebe Fişi','BORC',-1,0,@ISLEMGRUPID1)
		SELECT @FISID=FISID FROM MUH_FIS WHERE FISUUID=@FISUUID
		
		
		INSERT INTO MUH_HESAPISL(FISID,HESAPID,ACIKLAMA,BORC,ALACAK,KUR,DOVIZ,DBORC,DALACAK,TUTAR,DTUTAR,ISLEMGRUPID1,PROJEID, OZELKODID, 
		SILINDI,BELGETURU,BELGETARIH,ODEMEYONTEMI,BELGEACIKLAMA,ENTKAYITID,VADE) 
		SELECT @FISID,MHESAPID,ISNULL(AIDATISLEM.ACIKLAMA,'Genel Borçlandırma İşlemi'),
		ABS(AIDATISLEM.TUTAR)*KUR AS BORC, 0.00 AS ALACAK,KUR,@DOVIZ, ABS(AIDATISLEM.TUTAR) AS DBORC,0.00 AS DALACAK,ABS(AIDATISLEM.TUTAR)*KUR,ABS(AIDATISLEM.TUTAR),@ISLEMGRUPID1,
		AIDATISLEM.PROJEID,DAIREID,0,-1,@TARIH,'BORC','Muhasebe Fişi',AIDATISLEMID,VADESI 
		FROM AIDATISLEM INNER JOIN AIDATFIS ON AIDATISLEM.AIDATFISID=AIDATFIS.AIDATFISID WHERE ISNULL(FISID,0)=0 AND	AIDATISLEM.AIDATFISID=@AIDATFISID AND AIDATISLEM.TARIH=@TARIH
		

		UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(ISNULL(TUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),
		DTOPLAM=(SELECT SUM(ISNULL(DTUTAR,0)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),
		KUR=ISNULL((SELECT AVG(ISNULL(KUR,1)) FROM MUH_HESAPISL WHERE
		ISNULL(SILINDI,0)=0 AND FISID=@FISID),1)
		WHERE FIRMAID=@FIRMAID AND FISID=@FISID

		UPDATE AIDATISLEM SET FISID=@FISID, FISUUID=@FISUUID WHERE AIDATISLEMID IN
		(SELECT ENTKAYITID FROM MUH_HESAPISL WHERE FISID=@FISID)

		SET @HATA=@@ERROR
		IF @HATA > 0 
			BEGIN
				ROLLBACK TRANSACTION
			END
		ELSE
			BEGIN
				COMMIT TRANSACTION
			END

END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TOPLUBORCGIRIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TOPLUBORCGIRIS] @ODEMETIPI INT, @TARIH SMALLDATETIME, @TAKSITSAYI INT, @VADEGUN INT, @AIDATFISID INT, @PROJEID INT, @FIRMAID INT, @AIDAT FLOAT,
@DVZ NVARCHAR(5)
AS
SET NOCOUNT ON
DECLARE @VADE SMALLDATETIME
DECLARE @KUR FLOAT
DECLARE @SAYAC INT=2
DECLARE @KONTROL INT=0
DECLARE @ACIKLAMA NVARCHAR(50)
DECLARE @GRUPID INT
DECLARE @KURTIPI NVARCHAR(15)
SET @KUR=ROUND(@KUR,4)
IF @VADEGUN<=0 SET @VADE=@TARIH
IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
SELECT @GRUPID=(SELECT ISLEMGRUPID1 FROM AIDATFIS WHERE AIDATFISID=@AIDATFISID) 
SELECT @ACIKLAMA=(SELECT GRUPADI FROM MUH_GRUP WHERE GRUPID=@GRUPID)
SELECT @KONTROL=ISNULL((SELECT COUNT(*) FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID),0)

IF @KONTROL>0
BEGIN
  INSERT INTO AIDATISLEM_SIL (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,DELDATE)
  SELECT AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,GETDATE() FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID
  DELETE FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID
END
IF @DVZ='' SET @DVZ=(SELECT TOP 1 PRIMDVZ FROM MUH_GRUP WHERE ANAGRUPID=@PROJEID)


SELECT @KURTIPI=(SELECT TOP 1 ISNULL(VALUESTR,'DOVIZSATIS') FROM CONFIG  WHERE ISNULL(SIL,0)=0 AND KEYNAME='Muhasebe İşlemlerinde Kur Alan Tipi (DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID) 

		IF @KURTIPI='DOVIZALIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(DOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(DOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))

			END
		IF @KURTIPI='DOVIZSATIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(DOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(DOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
		IF @KURTIPI='MBDOVIZALIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
		IF @KURTIPI='MBDOVIZSATIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
IF @ODEMETIPI=1
	BEGIN
		IF @TAKSITSAYI<=1
			BEGIN
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*ODATIPINE GORE */
				SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
				ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
			END
		ELSE
			BEGIN
				/*ILK TAKSIT INSERT EDELIM SONRA WHILE */
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*ODATIPINE GORE */
				SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
				ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID

				WHILE @SAYAC<=@TAKSITSAYI
					BEGIN
						SET @TARIH=DATEADD(MM,1,@TARIH)
						IF @VADEGUN<=0 SET @VADE=@TARIH
						IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
						ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID						
						SET @SAYAC=@SAYAC+1
					END
			END
	END
ELSE IF @ODEMETIPI=2
	BEGIN
		IF @TAKSITSAYI<=1
			BEGIN
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIREYE GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
			END
		ELSE
			BEGIN
				/*ILK TAKSIT SONRASI WHILE */
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIREYE GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
				WHILE @SAYAC<=@TAKSITSAYI
					BEGIN
						SET @TARIH=DATEADD(MM,1,@TARIH)
						IF @VADEGUN<=0 SET @VADE=@TARIH
						IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID					
						SET @SAYAC=@SAYAC+1
					END
			END
	END
ELSE IF @ODEMETIPI=3
	BEGIN
		IF @TAKSITSAYI<=1
			BEGIN
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIRE MANUEL FIYATA GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
			END
		ELSE
			BEGIN
				/*ILK TAKSIT SONRASI WHILE */
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIRE MANUEL FIYATA GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
				WHILE @SAYAC<=@TAKSITSAYI
					BEGIN
						SET @TARIH=DATEADD(MM,1,@TARIH)
						IF @VADEGUN<=0 SET @VADE=@TARIH
						IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID				
						SET @SAYAC=@SAYAC+1
					END
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TOPLUBORCGIRIS2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TOPLUBORCGIRIS2] @SATIRACIKLAMA NVARCHAR(150), @ISLEMGRUPID INT, @ODEMETIPI INT, @TARIH SMALLDATETIME, @TAKSITSAYI INT, @VADEGUN INT, @AIDATFISID INT, @PROJEID INT, @FIRMAID INT, @AIDAT FLOAT,
@DVZ NVARCHAR(5)
AS
SET NOCOUNT ON
DECLARE @VADE SMALLDATETIME
DECLARE @KUR FLOAT
DECLARE @SAYAC INT=2
DECLARE @KONTROL INT=0
DECLARE @ACIKLAMA NVARCHAR(50)
DECLARE @GRUPID INT
DECLARE @KURTIPI NVARCHAR(15)
SET @KUR=ROUND(@KUR,4)
IF @VADEGUN<=0 SET @VADE=@TARIH
IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
SELECT @GRUPID=(SELECT ISLEMGRUPID1 FROM AIDATFIS WHERE AIDATFISID=@AIDATFISID) 
IF @SATIRACIKLAMA='' 
	BEGIN
		SELECT @ACIKLAMA=(SELECT GRUPADI FROM MUH_GRUP WHERE GRUPID=@GRUPID)
	END
ELSE
	BEGIN
		SET @ACIKLAMA=@SATIRACIKLAMA
	END
SELECT @KONTROL=ISNULL((SELECT COUNT(*) FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID),0)

IF @KONTROL>0
BEGIN
  INSERT INTO AIDATISLEM_SIL (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,DELDATE)
  SELECT AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,GETDATE() FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID
  DELETE FROM AIDATISLEM WHERE AIDATFISID=@AIDATFISID
END
IF (@DVZ='') AND (@ISLEMGRUPID>0) SET @DVZ=(SELECT TOP 1 DVZ FROM PROJEEMLAKTIP WHERE FIRMAID=@FIRMAID AND ISLEMGRUPID=@ISLEMGRUPID)
IF @DVZ='' SET @DVZ=(SELECT TOP 1 PRIMDVZ FROM MUH_GRUP WHERE ANAGRUPID=@PROJEID)

SELECT @KURTIPI=(SELECT TOP 1 ISNULL(VALUESTR,'DOVIZSATIS') FROM CONFIG  WHERE ISNULL(SIL,0)=0 AND KEYNAME='Muhasebe İşlemlerinde Kur Alan Tipi (DOVIZALIS DOVIZSATIS MBDOVIZALIS MBDOVIZSATIS' AND FIRMAID=@FIRMAID) 

		IF @KURTIPI='DOVIZALIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(DOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(DOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))

			END
		IF @KURTIPI='DOVIZSATIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(DOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(DOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
		IF @KURTIPI='MBDOVIZALIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZALIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZALIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
		IF @KURTIPI='MBDOVIZSATIS' 
			BEGIN
				SELECT @KUR=ISNULL((SELECT TOP 1 ISNULL(MBDOVIZSATIS,1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH AND KODU=@DVZ),(SELECT TOP 1 ISNULL(MAX(MBDOVIZSATIS),1) FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND  KODU=@DVZ))
			END
IF @ODEMETIPI=1
	BEGIN
		IF @ISLEMGRUPID>0
			BEGIN

				IF @TAKSITSAYI<=1
					BEGIN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
						ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID 
						WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 AND PROJEEMLAKTIP.ISLEMGRUPID=@ISLEMGRUPID
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
					END
				ELSE
					BEGIN
						/*ILK TAKSIT INSERT EDELIM SONRA WHILE */
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
						ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID AND PROJEEMLAKTIP.ISLEMGRUPID=@ISLEMGRUPID

						WHILE @SAYAC<=@TAKSITSAYI
							BEGIN
								SET @TARIH=DATEADD(MM,1,@TARIH)
								IF @VADEGUN<=0 SET @VADE=@TARIH
								IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
								INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
								/*ODATIPINE GORE */
								SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
								ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
								AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID AND PROJEEMLAKTIP.ISLEMGRUPID=@ISLEMGRUPID					
								SET @SAYAC=@SAYAC+1
							END
					END
			END
		ELSE
			BEGIN
				IF @TAKSITSAYI<=1
					BEGIN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
						ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
					END
				ELSE
					BEGIN
						/*ILK TAKSIT INSERT EDELIM SONRA WHILE */
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
						ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID

						WHILE @SAYAC<=@TAKSITSAYI
							BEGIN
								SET @TARIH=DATEADD(MM,1,@TARIH)
								IF @VADEGUN<=0 SET @VADE=@TARIH
								IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
								INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
								/*ODATIPINE GORE */
								SELECT  @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, MUH_GRUP.EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,AIDAT, DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP LEFT JOIN PROJEEMLAKTIP 
								ON  MUH_GRUP.EMLAKTIPID=PROJEEMLAKTIP.EMLAKTIPID AND MUH_GRUP.ANAGRUPID=PROJEEMLAKTIP.PROJEID WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1 
								AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID						
								SET @SAYAC=@SAYAC+1
							END
					END
			END
	END
ELSE IF @ODEMETIPI=2
	BEGIN
		IF @TAKSITSAYI<=1
			BEGIN
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIREYE GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
			END
		ELSE
			BEGIN
				/*ILK TAKSIT SONRASI WHILE */
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIREYE GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
				WHILE @SAYAC<=@TAKSITSAYI
					BEGIN
						SET @TARIH=DATEADD(MM,1,@TARIH)
						IF @VADEGUN<=0 SET @VADE=@TARIH
						IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,PRIMORAN AS AIDAT, PRIMDVZ AS DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID					
						SET @SAYAC=@SAYAC+1
					END
			END
	END
ELSE IF @ODEMETIPI=3
	BEGIN
		IF @TAKSITSAYI<=1
			BEGIN
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIRE MANUEL FIYATA GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
			END
		ELSE
			BEGIN
				/*ILK TAKSIT SONRASI WHILE */
				INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
				/*DAIRE MANUEL FIYATA GORE */
				SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR, @ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
				AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID
				WHILE @SAYAC<=@TAKSITSAYI
					BEGIN
						SET @TARIH=DATEADD(MM,1,@TARIH)
						IF @VADEGUN<=0 SET @VADE=@TARIH
						IF @VADEGUN>0 SET @VADE=@TARIH+@VADEGUN
						INSERT INTO AIDATISLEM (AIDATFISID,TARIH,VADESI,PROJEID,EMLAKTIPID,DAIREID,MHESAPID,TUTAR,DVZ,KUR,ACIKLAMA)
						/*ODATIPINE GORE */
						SELECT @AIDATFISID, @TARIH, @VADE, ANAGRUPID AS PROJEID, EMLAKTIPID, GRUPID AS DAIREID, MUSTERIHESAPID,@AIDAT AS AIDAT, @DVZ AS DVZ, @KUR,@ACIKLAMA FROM MUH_GRUP WHERE ISNULL(MUH_GRUP.SIL,0)=0 AND TIPID=8 AND AKTIF=1
						AND MUH_GRUP.FIRMAID=@FIRMAID AND MUH_GRUP.ANAGRUPID=@PROJEID				
						SET @SAYAC=@SAYAC+1
					END
			END
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUKETIMFIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUKETIMFIS]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUKETIMFIS WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUKETIMFIS_MAHSUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUKETIMFIS_MAHSUP]  @DEPOFISID INT
AS
SET NOCOUNT ON
BEGIN
DECLARE @ISLEM NVARCHAR(10)
SELECT @ISLEM=ISLEM FROM TUKETIMFIS WHERE DEPOFISID=@DEPOFISID
IF @ISLEM='SATIS'
	BEGIN
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Satış Fişi' as ACIKLAMA, TOPLAM AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(ACIKHESAPID,-999) AS HESAPID,ISNULL(TUKETIMFIS.ENO,'')+' Satış Fişi' as ACIKLAMA,0.00 AS BORC, TOPLAM AS ALACAK,0.00 AS DBORC,0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Satış Nakit Tahsilat' as ACIKLAMA, 0.00 AS BORC, NAKIT AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(NAKIT)>0
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(NAKITHESAPID,-999) AS HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Satış Nakit Tahsilat' as ACIKLAMA, NAKIT AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(NAKIT)>0	
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Satış KK Tahsilat' as ACIKLAMA, 0.00 AS BORC, KKARTI AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(KKARTI)>0
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(KKARTIHESAPID,-999) AS HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Satış KK Tahsilat' as ACIKLAMA, KKARTI AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(KKARTI)>0				
	END
ELSE
	BEGIN
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Alış Fişi' as ACIKLAMA, 0.00 AS BORC, TOPLAM AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(ACIKHESAPID,-999) AS HESAPID,ISNULL(TUKETIMFIS.ENO,'')+' AlışFişi' as ACIKLAMA, TOPLAM AS BORC, 0.00 AS ALACAK,0.00 AS DBORC,0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Alış Nakit Ödeme' as ACIKLAMA, NAKIT AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(NAKIT)>0
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(NAKITHESAPID,-999) AS HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Alış Nakit Ödeme' as ACIKLAMA, 0.00 AS BORC, NAKIT AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(NAKIT)>0	
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Alış KK Ödeme' as ACIKLAMA, KKARTI AS BORC, 0.00 AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(KKARTI)>0
		UNION ALL
		SELECT ISNULL(ACIKSUBEID,TUKETIMFIS.SUBEID) AS ACIKSUBEID, ISNULL(KKARTIHESAPID,-999) AS HESAPID, ISNULL(TUKETIMFIS.ENO,'')+' Alış KK Ödeme' as ACIKLAMA, 0.00 AS BORC, KKARTI AS ALACAK,0.00 AS DBORC, 0.00 AS DALACAK,1.00 AS KUR,'TL' AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) 
		LEFT JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID  WHERE DEPOFISID=@DEPOFISID and ABS(KKARTI)>0			
	END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUKETIMFISISL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_TUKETIMFISISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUKETIMFISISL WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUKETIMFISISL_OZET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE   PROCEDURE [dbo].[PRL_TUKETIMFISISL_OZET]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT BARKOD,STOKID,ACIKLAMA AS STOKADI,KDVORAN, '+
' SUM(FMIKTAR) AS FMIKTAR, FBFIYAT, SUM(FBFIYAT*FMIKTAR) AS TOPLAM FROM TUKETIMFISISL WHERE 1=1 '+@PARAMETRE+
' GROUP BY BARKOD,STOKID,ACIKLAMA,KDVORAN,FBIRIM,FBFIYAT'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUMGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_TUMGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SGRUP WITH (NOLOCK) WHERE GRUPTURU IN(''STOK'',''URUN'',''HIZMET'') AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUMHESAPISL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUMHESAPISL]  @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM [FNCQ_QMUHMIZAN_FATURA] ('''+@TARIH+''', '''+@TARIH2+''', '''+@FIRMAID+''') WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUMMASALAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO










CREATE PROCEDURE [dbo].[PRL_TUMMASALAR]  @DEPT NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TARIH NVARCHAR(12)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2000)
SET @SQLCUMLE='SELECT M.FIRMAID,M.SUBEID,M.DEPID,M.DEPART AS DEPKODU,M.MASAID, M.STATU, (CASE WHEN CALLSIPARISID>0 THEN M.MASANO+'' (PAKET) '' ELSE M.MASANO END) AS MASANO, ISNULL(M.KISIS,2) AS KISIS, A.ASAATI,
DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, 
DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE, A.GARSONKODU, A.TARIH, A.KISI,
A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM, INDORAN,A.FISCOUNTER,
(CASE WHEN ISNULL(M.STATU,0)=0 THEN ''BOŞ'' WHEN M.STATU=1 THEN ''DOLU'' WHEN M.STATU=2 THEN ''KİRLİ''
     WHEN M.STATU=3 THEN ''REZERVE'' WHEN M.STATU=4 THEN ''KAPALI'' ELSE '''' END) AS MASADURUM,
     ISNULL(A.ACIKLAMA,M.ACIKLAMA) AS ACIKLAMA
     FROM MASALAR AS M LEFT JOIN (SELECT * FROM ADISYON
     WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND  
	 ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND DEPID='''+@DEPT+''')
     AS A ON M.MASANO = A.MASANO AND M.DEPID=A.DEPID AND A.DEPID='''+@DEPT+'''
     WHERE ISNULL(M.SIL,0)=0 AND M.FIRMAID='+@FIRMAID+' AND M.SUBEID='+@SUBEID+' AND M.DEPID='''+@DEPT+'''
     UNION ALL
     SELECT FIRMAID,SUBEID,A.DEPID,DEPKODU,9999 AS MASAID, ISNULL(MASASTATU,1) AS STATU, A.MASANO, A.KISI AS KISIS, A.ASAATI, 
	DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE,
     A.GARSONKODU, A.TARIH,A.KISI,
     A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM,INDORAN,A.FISCOUNTER, ''DOLU'' AS MASADURUM, A.ACIKLAMA FROM ADISYON AS A
     WHERE ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND FIRMAID='+@FIRMAID+' AND 
	 SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+'''
     AND (MASANO NOT LIKE''Z%'' AND MASANO NOT IN(SELECT MASANO FROM MASALAR 
	 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+''')) ORDER BY MASANO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUMMASALAR2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO









CREATE PROCEDURE [dbo].[PRL_TUMMASALAR2]  @DEPT NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TARIH NVARCHAR(12)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2000)
SET @SQLCUMLE='SELECT M.FIRMAID,M.SUBEID,M.DEPID,M.DEPART AS DEPKODU,M.MASAID, M.STATU, (CASE WHEN CALLSIPARISID>0 THEN M.MASANO+'' (PAKET) '' ELSE M.MASANO END) AS MASANO, ISNULL(M.KISIS,2) AS KISIS, A.ASAATI,
DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, 
DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE, A.GARSONKODU, A.TARIH, A.KISI,
(A.TOPLAM/100*(100-ISNULL(A.INDORAN,0)))-(ONAKIT+OACIK+OKK+OTICKET+OTICKET2+OTICKET3+OTICKET4+OTICKET5) AS TOPLAM, INDORAN,A.FISCOUNTER,
(CASE WHEN ISNULL(M.STATU,0)=0 THEN ''BOŞ'' WHEN M.STATU=1 THEN ''DOLU'' WHEN M.STATU=2 THEN ''KİRLİ''
     WHEN M.STATU=3 THEN ''REZERVE'' WHEN M.STATU=4 THEN ''KAPALI'' ELSE '''' END) AS MASADURUM,
     ISNULL(A.ACIKLAMA,M.ACIKLAMA) AS ACIKLAMA
     FROM MASALAR AS M LEFT JOIN (SELECT * FROM ADISYON
     WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND  
	 ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND DEPID='''+@DEPT+''')
     AS A ON M.MASANO = A.MASANO AND M.DEPID=A.DEPID AND A.DEPID='''+@DEPT+'''
     WHERE ISNULL(M.SIL,0)=0 AND M.FIRMAID='+@FIRMAID+' AND M.SUBEID='+@SUBEID+' AND M.DEPID='''+@DEPT+'''
     UNION ALL
     SELECT FIRMAID,SUBEID,A.DEPID,DEPKODU,9999 AS MASAID, ISNULL(MASASTATU,1) AS STATU, A.MASANO, A.KISI AS KISIS, A.ASAATI, 
	DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE,
     A.GARSONKODU, A.TARIH,A.KISI,
     A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ONAKIT+OACIK+OKK+OTICKET+OTICKET2+OTICKET3+OTICKET4+OTICKET5) AS TOPLAM,INDORAN,A.FISCOUNTER, ''DOLU'' AS MASADURUM, A.ACIKLAMA FROM ADISYON AS A
     WHERE ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND FIRMAID='+@FIRMAID+' AND 
	 SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+'''
     AND (MASANO NOT LIKE''Z%'' AND MASANO NOT IN(SELECT MASANO FROM MASALAR 
	 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+''')) ORDER BY MASANO'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUMSTOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_TUMSTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(700)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' FIRMAID,SUBEID, MARKAID,STOKID,GRUPID,ADI,BIRIM,SFIYAT1 AS FIYAT,SFIYAT1,SFIYAT2,SFIYAT3,SFIYAT4,SFIYAT5,SALISFIYAT,
BARKOD,BARKOD2,KODU,ALISKDV,SATISKDV,FATURABIRIMI,BIRIM2,BIRIM3,BIRIM4,BIRIM5,KATSAYI2,
KATSAYI3,KATSAYI4,KATSAYI5,SALISFBFIYAT,SALISFBIRIM,SONALISF,MALIYET,SDOVIZ1,SDOVIZ2,
SDOVIZ3,SDOVIZ4,SDOVIZ5,SFIYAT1KDV,ETERAZI,PLUNO,POSTURU,TURU,SATISIND,INDVERILIR,SURE,SKOMORAN AS KOMORANI, BKOMORAN AS KOMTUTARI,SDOVIZ AS KOMDOVIZ,PSTOK
FROM STOK WITH (NOLOCK) WHERE  TURU IN(''Hammadde'',''HIZMET'',''Mamul'') and ISNULL(KKALDIR,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUR_BILET_FIS_IPTAL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUR_BILET_FIS_IPTAL] @FIRMAID INT, @MUHFISID INT
AS
IF @MUHFISID IS NULL SET @MUHFISID=-9999999
UPDATE MUH_FIS SET FISDURUMID=-2, SIL=-2, DEL_DATE=GETDATE(), OZELKOD4='FT KESILDI' WHERE FIRMAID=@FIRMAID AND FISID=@MUHFISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[PRL_TURANALIZ]  @FIRMAID NVARCHAR(10), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_TURANALIZ ('''+@FIRMAID+''')  WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURFIYATIBUL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURFIYATIBUL] @ACENTAID INT, @PROGRAMID INT, @TARIH nvarchar(10), @KISI FLOAT, @CCK FLOAT
AS
SELECT PROGRAMID, BASLANGIC, BITIS,KISIFIYAT,DBLFIYAT,CCKFIYAT,DOVIZ, 
(CASE WHEN @KISI>=2 AND DBLFIYAT>0 THEN ((DBLFIYAT/2)*(@KISI))+(ISNULL(CCKFIYAT,0)*@CCK) 
	  WHEN @KISI>=2 AND ISNULL(DBLFIYAT,0)=0 THEN (KISIFIYAT*@KISI)+(ISNULL(CCKFIYAT,0)*@CCK) ELSE (KISIFIYAT*@KISI)+(ISNULL(CCKFIYAT,0)*@CCK) END)
AS TOPLAMFIYAT  
FROM T_ACENTAFIYAT WHERE ACENTALARID=@ACENTAID AND PROGRAMID=@PROGRAMID AND @TARIH>=BASLANGIC AND @TARIH<=BITIS
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURFIYATIBUL2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURFIYATIBUL2] @ACENTAID INT, @PROGRAMID INT, @TARIH nvarchar(10), @KISI FLOAT, @CCK FLOAT, @EKKISI FLOAT
AS
SELECT PROGRAMID, BASLANGIC, BITIS,KISIFIYAT,DBLFIYAT,CCKFIYAT,EKFIYAT,DOVIZ, 
(CASE WHEN @KISI>=2 AND DBLFIYAT>0 THEN ((DBLFIYAT/2)*(@KISI))+(ISNULL(CCKFIYAT,0)*@CCK)+(ISNULL(EKFIYAT,0)*@EKKISI)
	  WHEN @KISI>=2 AND ISNULL(DBLFIYAT,0)=0 THEN (KISIFIYAT*@KISI)+(ISNULL(CCKFIYAT,0)*@CCK)+(ISNULL(EKFIYAT,0)*@EKKISI) 
	  ELSE (KISIFIYAT*@KISI)+(ISNULL(CCKFIYAT,0)*@CCK)+(ISNULL(EKFIYAT,0)*@EKKISI) END)
AS TOPLAMFIYAT  
FROM T_ACENTAFIYAT WHERE ACENTALARID=@ACENTAID AND PROGRAMID=@PROGRAMID AND @TARIH>=BASLANGIC AND @TARIH<=BITIS
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_FATURA_ISARET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_FATURA_ISARET] @FIRMAID NVARCHAR(10), 
@TARIH1 NVARCHAR(10), @TARIH2 NVARCHAR(10), @ACENTAID NVARCHAR(10), @FATID NVARCHAR(10), @PROGRAMID NVARCHAR(10)
AS
IF @PROGRAMID=''
	BEGIN
		UPDATE T_TURREZ SET FATID=@FATID, FTKESILDI=1 WHERE ISNULL(SIL,0)=0 AND FATID IS NULL AND ACENTAID=@ACENTAID AND TARIH BETWEEN @TARIH1 AND @TARIH2
		UPDATE MUH_FIS SET FISDURUMID=-2, SIL=-2, DEL_DATE=GETDATE(), OZELKOD4='FT KESILDI' WHERE FIRMAID=@FIRMAID AND 
		FISID IN(SELECT MUHFISID FROM T_TURREZ WHERE MUHFISID>0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2 AND FATID=@FATID)
	END
ELSE
	BEGIN
		UPDATE T_TURREZ SET FATID=@FATID, FTKESILDI=1 WHERE ISNULL(SIL,0)=0 AND FATID IS NULL AND ACENTAID=@ACENTAID AND PROGRAMID=@PROGRAMID AND TARIH BETWEEN @TARIH1 AND @TARIH2
		UPDATE MUH_FIS SET FISDURUMID=-2, SIL=-2, DEL_DATE=GETDATE(), OZELKOD4='FT KESILDI' WHERE FIRMAID=@FIRMAID AND 
		FISID IN(SELECT MUHFISID FROM T_TURREZ WHERE MUHFISID>0 AND FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH1 AND @TARIH2 AND FATID=@FATID)
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_OZET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_OZET]  @PARAMETRE NVARCHAR(650)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @SQLCUMLE='SELECT ACENTAID, PROGRAMID, SUM(KISI) AS KISI, SUM(FREEKISI) AS FREEKISI, SUM(CCK) AS CCK, SUM(FREECCK) AS FREECCK, 
SUM(TOPLAMKISI) AS TOPLAMKISI, SUM(TOPLAMUCRET) AS TOPLAMUCRET, DOVIZKODU, SUM(TLTUTAR) AS TLTUTAR  FROM T_TURREZ
WHERE 1=1  '+@PARAMETRE+' GROUP BY ACENTAID,PROGRAMID,DOVIZKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_OZET_ACENTA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_OZET_ACENTA]  @PARAMETRE NVARCHAR(950)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1500)
SET @PARAMETRE=REPLACE(@PARAMETRE,'FIRMAID','T_TURREZ.FIRMAID')
SET @SQLCUMLE='SELECT T_ACENTALAR.HESAPID,T_ACENTALAR.UNVANI, T_ACENTALAR.ADRES,T_ACENTALAR.ADRES2, T_ACENTALAR.VD, T_ACENTALAR.VDNO, T_ACENTALAR.EMAIL, 
ACENTAID, SUM(KISI) AS KISI, SUM(FREEKISI) AS FREEKISI, SUM(CCK) AS CCK, SUM(FREECCK) AS FREECCK, 
SUM(TOPLAMKISI) AS TOPLAMKISI, SUM(TOPLAMUCRET) AS TOPLAMUCRET, DOVIZKODU, SUM(TLTUTAR) AS TLTUTAR, 
SUM(NAKITALINAN+KKALINAN) AS RESTUTAR  FROM T_TURREZ 
INNER JOIN T_ACENTALAR ON T_TURREZ.ACENTAID=T_ACENTALAR.ACENTALARID
WHERE 1=1  '+@PARAMETRE+' GROUP BY ACENTAID,T_ACENTALAR.HESAPID,DOVIZKODU,T_ACENTALAR.UNVANI, 
T_ACENTALAR.ADRES,T_ACENTALAR.ADRES2, T_ACENTALAR.VD, T_ACENTALAR.VDNO,T_ACENTALAR.EMAIL'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_OZET_TARIHLI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_OZET_TARIHLI]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,ACENTAID, PROGRAMID, SUM(KISI) AS KISI, SUM(FREEKISI) AS FREEKISI, SUM(CCK) AS CCK, SUM(FREECCK) AS FREECCK, 
SUM(TOPLAMKISI) AS TOPLAMKISI, SUM(TOPLAMUCRET) AS TOPLAMUCRET, DOVIZKODU, SUM(TLTUTAR) AS TLTUTAR  FROM T_TURREZ
WHERE 1=1  '+@PARAMETRE+' GROUP BY TARIH,ACENTAID,PROGRAMID,DOVIZKODU'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_TAHSILAT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_TAHSILAT]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(800)
SET @SQLCUMLE='SELECT ''NAKIT'' AS TUR,TAHSILATDOVIZ, SUM(NAKITALINAN) AS TUTAR FROM T_TURREZ WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TAHSILATDOVIZ
UNION ALL
SELECT ''KREDI KARTI'' AS TUR,TAHSILATDOVIZ, SUM(KKALINAN) AS TUTAR FROM T_TURREZ WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE+' GROUP BY TAHSILATDOVIZ' 
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TURREZ_TARIHLI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TURREZ_TARIHLI]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TARIH,SUM(KISI) AS KISI, SUM(FREEKISI) AS FREEKISI, SUM(CCK) AS CCK, SUM(FREECCK) AS FREECCK, 
SUM(TOPLAMKISI) AS TOPLAMKISI, SUM(TOPLAMUCRET) AS TOPLAMUCRET, SUM(TLTUTAR) AS TLTUTAR  FROM T_TURREZ
WHERE 1=1  '+@PARAMETRE+' GROUP BY TARIH'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUSGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSGRUPISLEM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUSGRUPISLEM] @ISLEM NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TUSGRUPID NVARCHAR(10), @TUSGRUPADI NVARCHAR(20), @SIRA NVARCHAR(5)
AS
DECLARE @YENITUSGRUPID INT
IF @ISLEM='YENI'
	BEGIN 
		INSERT INTO TUSGRUP (FIRMAID,SUBEID,TUSGRUPADI,SIRA,AKTIF) VALUES(@FIRMAID,@SUBEID,@TUSGRUPADI,99,1)
		SET @YENITUSGRUPID=(SELECT SCOPE_IDENTITY() AS TUSGRUPID)
			DECLARE @SAYAC INT=1
				WHILE @SAYAC<=100
					BEGIN
						INSERT INTO TUSSTOK (TUSGRUPID,AKTIF,SIRA) values(@YENITUSGRUPID,1,@SAYAC)			
						SET @SAYAC=@SAYAC+1
					END
	END
ELSE IF @ISLEM='AD'
	BEGIN
		UPDATE TUSGRUP SET TUSGRUPADI=@TUSGRUPADI WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUSGRUPID=@TUSGRUPID
	END
ELSE IF @ISLEM='SIRA'
	BEGIN
		UPDATE TUSGRUP SET SIRA=@SIRA WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TUSGRUPID=@TUSGRUPID
	END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSSTOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUSSTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSSTOK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSSTOKEKLE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_TUSSTOKEKLE]  @MIKTAR INT, @TUSGRUPID INT
AS
SET NOCOUNT ON
BEGIN
DECLARE @SAYAC INT=1
	WHILE @SAYAC<=@MIKTAR
		BEGIN
			INSERT INTO TUSSTOK (TUSGRUPID,AKTIF,SIRA) values(@TUSGRUPID,1,@SAYAC)			
			SET @SAYAC=@SAYAC+1
		END
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSSUBE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_TUSSUBE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSSUBE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_TUSSUBEGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_TUSSUBEGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM TUSSUBEGRUP WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ULKEBARKOD]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ULKEBARKOD]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ULKEBARKOD WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_ULKELER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_ULKELER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ULKELER WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETICI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_URETICI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM URETICI WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETILECEKLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_URETILECEKLER]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT,
@FIRMAID INT
AS
SELECT TOP 1000 FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPO,CDEPO,YETKILI,EVRAKNO,ACIKLAMA,TTUTAR  

 	FROM ( 

 		SELECT FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,TUKETIMFIS.ACIKLAMA,TTUTAR  

 		 FROM TUKETIMFIS  WITH (NOLOCK)

 		 WHERE (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND  ISNULL(URETILDI,0)=0  

 			   AND DEPOFISID IN ( 

 								 SELECT DISTINCT TUKETIMFISISL.DEPOFISID  

 								  FROM  TUKETIMFIS  WITH (NOLOCK) INNER JOIN  TUKETIMFISISL WITH (NOLOCK) on TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID 
								  INNER JOIN STOK WITH (NOLOCK) ON TUKETIMFISISL.STOKID=STOK.STOKID  AND STOK.FIRMAID=@FIRMAID 
 								  WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND TUKETIMFIS.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2 
								  AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0  AND ISNULL(URETILDI,0)=0 AND 
								  STOK.TURU='Mamul' 
 								 )   

 		UNION ALL   

 		SELECT FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,DEPOFIS.YETKILI,ENO AS EVRAKNO,DEPOFIS.ACIKLAMA,TTUTAR  

 		 FROM DEPOFIS WITH (NOLOCK) 

 		 WHERE (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND ISNULL(URETILDI,0)=0 

 			   AND DEPOFISID IN ( 

 								 SELECT DISTINCT DEPOFISISL.DEPOFISID  

 								  FROM  DEPOFIS  WITH (NOLOCK) INNER JOIN  DEPOFISISL WITH (NOLOCK) on DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID 
								  INNER JOIN STOK WITH (NOLOCK) ON DEPOFISISL.STOKID=STOK.STOKID  AND STOK.FIRMAID=@FIRMAID
 								  WHERE DEPOFIS.FIRMAID=@FIRMAID AND DEPOFIS.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2 
								  AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0  AND ISNULL(URETILDI,0)=0 AND 
								  STOK.TURU='Mamul')   

 		) TBL  

 WHERE  1=1  AND (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETILENLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_URETILENLER] 
@TARIH nvarchar(10),
@TARIH2 nvarchar(10),
@SUBEID INT,
@FIRMAID INT
AS
SELECT TOP 1000 FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPO,CDEPO,YETKILI,EVRAKNO,ACIKLAMA,TTUTAR  

 	FROM ( 

 		SELECT FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,TUKETIMFIS.ACIKLAMA,TTUTAR  

 		 FROM TUKETIMFIS  WITH (NOLOCK)

 		 WHERE (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1 AND ISNULL(URETILDI,0)=1

 			   AND DEPOFISID IN ( 

 								 SELECT DISTINCT TUKETIMFISISL.DEPOFISID  

 								  FROM  TUKETIMFIS  WITH (NOLOCK) INNER JOIN  TUKETIMFISISL WITH (NOLOCK) on TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID 
								  INNER JOIN STOK WITH (NOLOCK) ON TUKETIMFISISL.STOKID=STOK.STOKID  
 								  WHERE (TUKETIMFIS.FIRMAID=@FIRMAID AND TUKETIMFIS.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND 
								  ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1 AND ISNULL(URETILDI,0)=1 AND
								  STOK.FIRMAID=@FIRMAID AND STOK.TURU IN ('Mamul','Yarı Mamul') 
 								 )   

 		UNION ALL   

 		SELECT FIRMAID,CSUBEID,GSUBEID,DEPOFISID,ISLEM,TARIH,GDEPOID AS GDEPO,CDEPOID AS CDEPO,DEPOFIS.YETKILI,ENO AS EVRAKNO,DEPOFIS.ACIKLAMA,TTUTAR  

 		 FROM DEPOFIS WITH (NOLOCK) 

 		 WHERE (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1  AND ISNULL(URETILDI,0)=1 

 			   AND DEPOFISID IN ( 

 								 SELECT DISTINCT DEPOFISISL.DEPOFISID  

 								  FROM  DEPOFIS  WITH (NOLOCK) INNER JOIN  DEPOFISISL WITH (NOLOCK) on DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID 
								  INNER JOIN STOK WITH (NOLOCK) ON DEPOFISISL.STOKID=STOK.STOKID  
 								  WHERE (DEPOFIS.FIRMAID=@FIRMAID AND DEPOFIS.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2) 
								  AND ISNULL(LOGOAKTAR,0)=0 AND ISNULL(URUNFISID,0)=0 AND 1=1  AND ISNULL(URETILDI,0)=1 AND
								  STOK.FIRMAID=@FIRMAID AND STOK.TURU IN ('Mamul','Yarı Mamul'))   

 		) TBL  

 WHERE  1=1  AND (FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIM_ANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URETIM_ANALIZ] @FIRMAID INT, @ILKTARIH NVARCHAR(10), @SONTARIH NVARCHAR(10)
AS
SELECT DEPOFIS.DEPOFISID AS DEPOFISID,  DEPO.DEPOADI, URETIMRECETE.URETIMRECETEID AS URETIMRECETEID, DEPOFIS.TARIH, URETIMRECETE.TARIH AS RECETETARIH, GSUBEID,GDEPOID,ENO,DEPOFISISL.ACIKLAMA,ISLREFID,
						DEPOFISISL.STOKID AS GIRISSTOKID, STOK.ADI AS GIRISSTOKADI, RECETEDETAY.STOKID AS CIKISSTOKID, STOK2.ADI AS CIKISSTOKADI, STOK2.BIRIM, FMIKTAR,
						DEPOFISISL.MIKTAR AS GIRISMIKTAR, RECETEDETAY.MIKTAR AS CIKISMIKTAR, RECETEDETAY.MIKTAR*DEPOFISISL.FMIKTAR AS TOPLAMCIKIS, 
						RECETEDETAY.RECETEMALIYET AS BIRIMMALIYET, RECETEDETAY.RECETEMALIYET*DEPOFISISL.FMIKTAR AS TOPLAMMALIYET, DEPOFISISL.FMIKTAR*FBFIYAT AS TOPLAMSATISFIYAT, FBFIYAT,BFIYAT,FBMALIYET,DEPOFISISL.BMALIYET 
						FROM DEPOFIS INNER JOIN DEPOFISISL ON DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID
						INNER JOIN DEPO ON DEPOFIS.GDEPOID=DEPO.DEPOID AND DEPO.FIRMAID=@FIRMAID
						INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID AND STOK.FIRMAID=@FIRMAID
						INNER JOIN URETIMRECETE ON DEPOFISISL.ISLREFID=URETIMRECETE.URETIMRECETEID AND URETIMRECETE.FIRMAID=@FIRMAID
						INNER JOIN RECETEDETAY ON URETIMRECETE.URETIMRECETEID=RECETEDETAY.URETIMRECETEID
						INNER JOIN STOK AS STOK2 ON RECETEDETAY.STOKID=STOK2.STOKID AND STOK2.FIRMAID=@FIRMAID
						WHERE ISNULL(DEPOFIS.SIL,0)=0 AND DEPOFISISL.ISLREFID>0 AND DEPOFIS.FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIM_EMRI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URETIM_EMRI]  
@TARIH SMALLDATETIME,
@URETIMDEPOFISID INT,
@CDEPOID INT,
@SUBEID INT,
@FIRMAID INT
AS
BEGIN
DECLARE
@GUID uniqueidentifier = NEWID(),
@DEPOFISID INT
SELECT TOP 10 * FROM DEPOFIS
						INSERT INTO DEPOFIS (DEPOFISUUID, URUNFISID, TARIH,YETKILI,ISLEM,ACIKLAMA,CDEPOID,FIRMAID,SUBEID,CSUBEID,ADD_DATE) 
						SELECT @GUID, @URETIMDEPOFISID, @TARIH, 'SYSTEM' AS YETKILI,'TUKETIM' AS ISLEM,'ÜRETİM EMRİ' AS ACIKLAMA, @CDEPOID, @FIRMAID,@SUBEID, @SUBEID,GETDATE()

						SELECT @DEPOFISID=DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE DEPOFISUUID=@GUID

						INSERT INTO DEPOFISISL (DEPOFISID,TEMPITSID,STOKID,ISLREFID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,FBFIYAT,FBMALIYET,BMALIYET, YETKILI,ACIKLAMA)

						SELECT @DEPOFISID, DEPOFIS.DEPOFISID, RECETEDETAY.STOKID, DEPOFISISL.STOKID, RECETEDETAY.MIKTAR*DEPOFISISL.FMIKTAR,STOK2.BIRIM,RECETEDETAY.MIKTAR*DEPOFISISL.FMIKTAR,
						RECETEDETAY.BIRIMMALIYET,RECETEDETAY.BIRIMMALIYET,RECETEDETAY.BIRIMMALIYET,RECETEDETAY.BIRIMMALIYET,'SYSTEM','Üretim Emri ile Tüketim'
						FROM DEPOFIS INNER JOIN DEPOFISISL ON DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID
						INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID
						INNER JOIN URETIMRECETE ON DEPOFISISL.ISLREFID=URETIMRECETE.URETIMRECETEID
						INNER JOIN RECETEDETAY ON URETIMRECETE.URETIMRECETEID=RECETEDETAY.URETIMRECETEID
						INNER JOIN STOK AS STOK2 ON RECETEDETAY.STOKID=STOK2.STOKID
						WHERE DEPOFISISL.ISLREFID>0 AND DEPOFIS.DEPOFISID=@URETIMDEPOFISID ORDER BY STOK2.STOKID,DEPOFISISL.STOKID

						
						UPDATE DEPOFIS SET TADET=(SELECT SUM(MIKTAR) FROM DEPOFISISL WHERE DEPOFISID=@DEPOFISID),
						TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WITH (NOLOCK) WHERE DEPOFISID=@DEPOFISID) WHERE DEPOFISID=@DEPOFISID

						UPDATE DEPOFIS SET URUNFISID=@DEPOFISID WHERE DEPOFISID=@URETIMDEPOFISID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIM_SIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URETIM_SIL] @FIRMAID INT, @DEPOFISID INT, @USERID INT
AS
UPDATE DEPOFIS SET SIL=-2, DEL_DATE=GETDATE(), DEL_USERID=@USERID WHERE DEPOFIS.FIRMAID=@FIRMAID AND DEPOFIS.DEPOFISID=@DEPOFISID
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMMAHSUBUSIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_URETIMMAHSUBUSIL]  
@TARIH SMALLDATETIME,
@TARIH2 SMALLDATETIME,
@SUBEID INT,
@FIRMAID INT
AS
BEGIN
	DELETE FROM MUH_HESAPISL WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH BETWEEN @TARIH AND @TARIH2 AND OZELKOD1='POSURETIM')
	DELETE FROM MUH_FIS WHERE FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND FISTURID=41 AND TARIH BETWEEN @TARIH AND @TARIH2 AND OZELKOD1='POSURETIM'
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMMAKINE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_URETIMMAKINE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM URETIMMAKINE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMRECETE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URETIMRECETE]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM URETIMRECETE WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMSIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_URETIMSIL]  
@TARIH NVARCHAR(10),
@TARIH2 NVARCHAR(10),
@SUBEID INT,
@FIRMAID INT
AS
DELETE FROM TUKETIMFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0    AND TARIH BETWEEN @TARIH AND @TARIH2)
--5
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND   ABS(ISNULL(URUNFISID,0))>0    AND TARIH BETWEEN @TARIH AND @TARIH2
--4
UPDATE TUKETIMFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  1=1  AND TARIH BETWEEN @TARIH AND @TARIH2
--3
DELETE FROM DEPOFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0    AND TARIH BETWEEN @TARIH AND @TARIH2)
--2
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND   ABS(ISNULL(URUNFISID,0))>0    AND TARIH BETWEEN @TARIH AND @TARIH2
--1
UPDATE DEPOFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  1=1  AND TARIH BETWEEN @TARIH AND @TARIH2
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMYAP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URETIMYAP]  
@TARIH NVARCHAR(10),
@TARIH2 NVARCHAR(10),
@SUBEID INT,
@FIRMAID INT,
@SUBEKODU NVARCHAR(10)
AS
DELETE FROM TUKETIMFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0  
AND TARIH BETWEEN @TARIH AND @TARIH2)
/*13 */
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2
/*14 */
UPDATE TUKETIMFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2
/*15 */
DELETE FROM DEPOFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2)
/*16 */
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2
/*17 */
UPDATE DEPOFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2
/*18 */
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
/*19 */
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND TARIH BETWEEN @TARIH AND @TARIH2
/*20 */
INSERT INTO TUKETIMFIS (FIRMAID,SUBEID,TARIH,YETKILI,ISLEM,ENO,CDEPOID,SDEPART,CSUBEID,ACIKLAMA,MUHFC) 
 SELECT DISTINCT FIRMAID,SUBEID,TARIH,T.YETKILI,ISLEM,'S'+ENO,S.SARFDEPOID,T.SDEPART,T.CSUBEID,'NovaV5 Uretim Aktarimi~',T.DEPOFISID 
 FROM TUKETIMFIS T WITH (NOLOCK) INNER JOIN 
      TUKETIMFISISL TI WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
(SELECT STOKID ,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID AND ABS(ISNULL(S.SARFDEPOID,0))>0  
WHERE ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~' AND (T.FIRMAID=@FIRMAID AND T.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*21 */
INSERT INTO TUKETIMFISISL (STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,RCDEPOID,TEMPITSID) 
 SELECT TI.STOKID,TI.MIKTAR,TI.FBIRIM,TI.FMIKTAR,TI.BFIYAT,TI.YETKILI,TI.RCDEPOID,T.DEPOFISID 
 FROM TUKETIMFIS T  WITH (NOLOCK) INNER JOIN 
      TUKETIMFISISL TI  WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
      (SELECT STOKID ,SARFDEPOID FROM STOK  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID AND ABS(ISNULL(S.SARFDEPOID,0))>0  
 WHERE ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~' AND (T.FIRMAID=@FIRMAID AND T.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

/*TUKETIMFIS=MUHC ILE TUKETIMFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM */
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL INNER JOIN TUKETIMFIS ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='NovaV5 Uretim Aktarimi~'

/*22 */
UPDATE TUKETIMFISISL SET SARFDEPOID=S.SARFDEPOID FROM TUKETIMFISISL INNER JOIN (SELECT STOKID,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID AND ISNULL(SARFDEPOID,0)<>0 ) S ON TUKETIMFISISL.STOKID=S.STOKID  
WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2))
/*23 */
INSERT INTO TUKETIMFIS  (FIRMAID,SUBEID,CSUBEID,ISLEM,TARIH,GDEPOID,CDEPOID ,GSKODU,CSKODU,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)
 SELECT FIRMAID,SUBEID,CSUBEID,CASE WHEN ISLEM = 'TRANSFER' THEN ISLEM WHEN ISLEM IN ('ZAYI','ZAYİ','ZAYII','ZAYİİ') THEN 'ZAYI' ELSE 'TUKETIM' END AS ISLEM,
 TARIH,GDEPOID ,CDEPOID ,@SUBEKODU,@SUBEKODU,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,'Oto.Üretim' AS ACIKLAMA
 ,(TUKETIMFIS.DEPOFISID+7000000)*-1,ISLEM,2,TUKETIMFIS.DEPOFISID FROM TUKETIMFIS  WITH (NOLOCK)
 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(URUNFISID,0)=0  AND (TARIH BETWEEN @TARIH AND @TARIH2) 
 AND DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFISISL  WITH (NOLOCK) INNER JOIN STOK  WITH (NOLOCK) ON TUKETIMFISISL.STOKID=STOK.STOKID
 WHERE STOK.FIRMAID=@FIRMAID AND STOK.TURU IN ('Mamul','Yarı Mamul')  AND ISNULL(STOK.URETILMEZ,0)=0 ) AND ISNULL(URETILDI,0)=0 ORDER BY TARIH
/*24 */
UPDATE TUKETIMFIS SET URETILDI=1 FROM TUKETIMFIS,TUKETIMFISISL,(SELECT STOKID,TURU,URETILMEZ FROM STOK WHERE FIRMAID=@FIRMAID) STOK  
WHERE    TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID  AND TUKETIMFISISL.STOKID=STOK.STOKID AND 
ISNULL(STOK.URETILMEZ,0)=0 AND STOK.TURU IN ('Mamul','Yarı Mamul') AND ISNULL(URUNFISID,0)=0 AND ISNULL(LOGOAKTAR,0)=0 AND 1=1  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*25 */
INSERT INTO TUKETIMFISISL (STOKID,ACIKLAMA,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,RCDEPOID,TEMPITSID)
 SELECT STOK2.STOKID,'Oto.Üretimv5',
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END 
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS MIKTAR,
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS TMIKTAR,
        ISNULL(FIYATLAR.ORTFIYAT,0) AS BFIYAT, ISNULL(FIYATLAR.ORTFIYAT,0) AS FBFIYAT, STOK2.BIRIM,1,ISNULL(RECETE.SARFDEPOID,RCDEPOID) AS RCDEPOID,DEPOFISID 
        FROM (
               SELECT D.DEPOFISID,D.MIKTAR,D.STOKID,STOK.KODU,ISNULL(RCDEPOID,CDEPOID) RCDEPOID FROM TUKETIMFIS AS M WITH (NOLOCK),TUKETIMFISISL AS D WITH (NOLOCK),STOK WITH (NOLOCK)
                      WHERE M.FIRMAID=@FIRMAID AND  M.DEPOFISID=D.DEPOFISID AND STOK.STOKID=D.STOKID AND STOK.FIRMAID=@FIRMAID AND (M.CSUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
                            AND ISNULL(URETILMEZ,0)=0 AND 1=1 AND ISNULL(URUNFISID,0)=0
                            AND ISNULL(LOGOAKTAR,0)=0 AND TURU IN ('Mamul','Yarı Mamul') 
							AND ISNULL(D.SARFDEPOID,0)=0 
              ) AS TBL INNER JOIN 
                 RECETE WITH (NOLOCK)       ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK   WITH (NOLOCK)       ON TBL.STOKID    = STOK.STOKID   INNER JOIN 
                 STOK AS STOK2 WITH (NOLOCK) ON RECETE.STOKID = STOK2.STOKID  LEFT OUTER JOIN 
                (SELECT STOKID,ALISKDV ,SUM(GCADET) AS TADET, ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT, SUM(TOPLAMMALIYET) AS TTUTAR 
                  FROM [FNCQ_STOKISLEMLER] ('2000-01-01',@TARIH2,@FIRMAID) WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 
                  GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0) AS FIYATLAR ON STOK2.STOKID = FIYATLAR.STOKID AND STOK.FIRMAID=@FIRMAID AND STOK2.FIRMAID=@FIRMAID 
        GROUP BY DEPOFISID,STOK2.STOKID,STOK2.SALISFIYAT,STOK2.BIRIM,ISNULL(FIYATLAR.ORTFIYAT,0),ISNULL(RECETE.SARFDEPOID,RCDEPOID)  

/*TUKETIMFIS=MUHC ILE TUKETIMFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM */
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='Oto.Üretimv5' and TUKETIMFISISL.ACIKLAMA='Oto.Üretimv5'

/*26 */
SELECT D.DEPOFISID FROM TUKETIMFISISL D INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON S.STOKID=D.STOKID  
INNER JOIN (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON M.DEPOFISID=D.DEPOFISID AND D.URETSEVIYE=1
/*27  AŞAĞIDA MUHTEMELEN BOŞ FİŞLERİ SİLİYORUZ KONTROL EDELİM SONRA 20.02.2021 */
/*DELETE FROM TUKETIMFIS WHERE ACIKLAMA='Oto.Üretimv5' AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM TUKETIMFISISL) */
/*28 */
UPDATE TUKETIMFIS SET TADET  = ADEDI,TTUTAR=TUTARI 
FROM (SELECT TUKETIMFISISL.DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  FROM TUKETIMFISISL WITH (NOLOCK) GROUP BY TUKETIMFISISL.DEPOFISID) DI INNER JOIN TUKETIMFIS ON DI.DEPOFISID = TUKETIMFIS.DEPOFISID 
WHERE  FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*29 */
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (TARIH BETWEEN @TARIH AND @TARIH2)) 
/*30 */
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*31 */
DELETE FROM DEPOFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
/*32 */
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (TARIH BETWEEN @TARIH AND @TARIH2)
/*33 */
INSERT INTO DEPOFIS (TARIH,YETKILI,ISLEM,ENO,CDEPOID,SDEPART,FIRMAID,SUBEID,CSUBEID,ACIKLAMA,MUHFC) 

 SELECT DISTINCT TARIH,T.YETKILI,ISLEM,'S'+ENO,S.SARFDEPOID,T.SDEPART,T.FIRMAID,T.SUBEID,T.CSUBEID,'NovaV5 Uretim Aktarimi~',T.DEPOFISID 

 FROM DEPOFIS T INNER JOIN 

      DEPOFISISL TI ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 

     (SELECT STOKID ,SARFDEPOID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID   
	 WHERE T.FIRMAID=@FIRMAID AND ABS(ISNULL(S.SARFDEPOID,0))>0 AND ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

/*34 */
INSERT INTO DEPOFISISL (STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,RCDEPOID,TEMPITSID) 
 SELECT TI.STOKID,TI.MIKTAR,TI.FBIRIM,TI.FMIKTAR,TI.BFIYAT,TI.YETKILI,TI.RCDEPOID,T.DEPOFISID 
 FROM DEPOFIS T WITH (NOLOCK) INNER JOIN 
      DEPOFISISL TI WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
      (SELECT STOKID ,SARFDEPOID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID 
 WHERE T.FIRMAID=@FIRMAID AND ABS(ISNULL(S.SARFDEPOID,0))>0 AND ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

/*DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM */
UPDATE DEPOFISISL SET DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID FROM DEPOFISISL WITH (NOLOCK) INNER JOIN DEPOFIS WITH (NOLOCK) ON DEPOFISISL.TEMPITSID=DEPOFIS.MUHFC WHERE DEPOFIS.FIRMAID=@FIRMAID AND
DEPOFIS.CSUBEID=@SUBEID AND DEPOFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND DEPOFIS.ACIKLAMA='NovaV5 Uretim Aktarimi~'

/*35 */
UPDATE DEPOFISISL SET SARFDEPOID=S.SARFDEPOID FROM DEPOFISISL INNER JOIN (SELECT STOKID,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID AND ISNULL(SARFDEPOID,0)<>0 ) S ON DEPOFISISL.STOKID=S.STOKID  
WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2))
/*36 */
/*bizim pos satışı aşağıdaki kısımdan üretime geliyor. */
INSERT INTO DEPOFIS  (FIRMAID,SUBEID,CSUBEID,GSUBEID,ISLEM,TARIH,GDEPOID,CDEPOID ,GSKODU,CSKODU,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)
 SELECT FIRMAID,SUBEID,CSUBEID,GSUBEID,CASE WHEN ISLEM = 'TRANSFER' THEN ISLEM WHEN ISLEM IN ('ZAYI','ZAYİ','ZAYII','ZAYİİ') THEN 'ZAYI' ELSE 'TUKETIM' END AS ISLEM,
 TARIH,GDEPOID ,CDEPOID ,'01','01',DEPOFIS.YETKILI,ENO AS EVRAKNO,'Oto.Üretimv5' AS ACIKLAMA
 ,(DEPOFIS.DEPOFISID+7000000)*-1,ISLEM,2,DEPOFIS.DEPOFISID FROM DEPOFIS WITH (NOLOCK)
 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(URUNFISID,0)=0  AND (TARIH BETWEEN @TARIH AND @TARIH2) 
 AND DEPOFIS.DEPOFISID IN (SELECT DEPOFISISL.DEPOFISID FROM DEPOFISISL WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON DEPOFISISL.STOKID=STOK.STOKID INNER JOIN DEPOFIS WITH (NOLOCK) ON DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID
 WHERE DEPOFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND STOK.FIRMAID=@FIRMAID 
 AND STOK.TURU IN ('Mamul','Yarı Mamul')  AND ISNULL(STOK.URETILMEZ,0)=0 ) AND ISNULL(URETILDI,0)=0 ORDER BY TARIH
/*37 */
UPDATE DEPOFIS SET URETILDI=1 FROM DEPOFIS,DEPOFISISL,(SELECT STOKID,TURU,URETILMEZ FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) STOK  
WHERE  DEPOFIS.FIRMAID=@FIRMAID AND DEPOFIS.CSUBEID=@SUBEID AND DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID  
AND DEPOFISISL.STOKID=STOK.STOKID AND ISNULL(STOK.URETILMEZ,0)=0 AND STOK.TURU IN ('Mamul','Yarı Mamul') 
AND ISNULL(URUNFISID,0)=0 AND ISNULL(LOGOAKTAR,0)=0 AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*38 */
INSERT INTO DEPOFISISL (STOKID,ACIKLAMA,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,RCDEPOID,TEMPITSID)
 SELECT RECETE.STOKID,'Oto.Üretimv5',
        SUM(TBL.MIKTAR*ORAN) AS TMIKTAR,SUM(TBL.MIKTAR*ORAN) AS TMIKTAR,
        ISNULL((SELECT ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT
		FROM  [FNCQ_STOKISLEMLER] ('2000-01-01',@TARIH2,@FIRMAID)  AS FNC WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 AND FNC.STOKID=RECETE.STOKID
		 GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0),0) AS BFIYAT, ISNULL((SELECT ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT
		FROM  [FNCQ_STOKISLEMLER] ('2000-01-01',@TARIH2,@FIRMAID)  AS FNC WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 AND FNC.STOKID=RECETE.STOKID
		 GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0),0) AS FBFIYAT, RECETE.BIRIM,1,ISNULL(RECETE.SARFDEPOID,RCDEPOID) AS RCDEPOID,DEPOFISID 
        FROM (
               SELECT D.DEPOFISID,D.MIKTAR,D.STOKID,STOK.KODU,ISNULL(RCDEPOID,CDEPOID) RCDEPOID FROM DEPOFIS AS M WITH (NOLOCK),DEPOFISISL AS D WITH (NOLOCK),STOK WITH (NOLOCK)
                      WHERE   M.DEPOFISID=D.DEPOFISID AND STOK.STOKID=D.STOKID   AND (M.CSUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
                            AND ISNULL(URETILMEZ,0)=0 AND 1=1 AND ISNULL(URUNFISID,0)=0
                            AND ISNULL(LOGOAKTAR,0)=0 AND TURU IN ('Mamul','Yarı Mamul') AND M.CSUBEID=@SUBEID AND STOK.FIRMAID=@FIRMAID
                            AND ISNULL(D.SARFDEPOID,0)=0 
              ) AS TBL INNER JOIN 
                 RECETE WITH (NOLOCK)       ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK  WITH (NOLOCK)        ON TBL.STOKID    = STOK.STOKID 
                 where STOK.FIRMAID=@FIRMAID 
        GROUP BY DEPOFISID,ISNULL(RECETE.SARFDEPOID,RCDEPOID),RECETE.STOKID,RECETE.BIRIM  

/*DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM */
UPDATE DEPOFISISL SET DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID FROM DEPOFISISL INNER JOIN DEPOFIS ON DEPOFISISL.TEMPITSID=DEPOFIS.MUHFC WHERE DEPOFIS.FIRMAID=@FIRMAID AND
DEPOFIS.CSUBEID=@SUBEID AND DEPOFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND DEPOFIS.ACIKLAMA='Oto.Üretimv5'


/*39 */
SELECT D.DEPOFISID FROM DEPOFISISL D INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON S.STOKID=D.STOKID  
INNER JOIN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON M.DEPOFISID=D.DEPOFISID AND D.URETSEVIYE=1
/*40 BURADA BOŞ FİŞ TEMİZLİYORUZ AMA TÜM KAYITLARA BAKMAK OLMAZ 20.02.2021 */
/*DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND ACIKLAMA='Oto.Üretimv5' AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM DEPOFISISL WITH (NOLOCK)) */
/*41 */
UPDATE DEPOFIS SET TADET  = ADEDI,TTUTAR=TUTARI FROM (SELECT DEPOFISISL.DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  
FROM DEPOFISISL GROUP BY DEPOFISISL.DEPOFISID) DI INNER JOIN DEPOFIS WITH (NOLOCK) ON DI.DEPOFISID = DEPOFIS.DEPOFISID WHERE  DEPOFIS.FIRMAID=@FIRMAID  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*42 */
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*43 */
DELETE FROM DEPOFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
/*44 */
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Faturadan Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
/*45 */
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Faturadan Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
/*46 */
INSERT INTO TUKETIMFIS 
 (FIRMAID,SUBEID,CSUBEID,ISLEM,TARIH,CDEPOID,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)

 SELECT FIRMAID,SUBEID,SUBEID,'TUKETIM' ISLEM,TARIH,DEPOID,KAYDEDEN,'Fatura' ENO ,'NovaV5 Faturadan Uretim Aktarimi~' ACIKLAMA,

  FATID URUNFISID,TURADI,2 URETILDI,FATID
 FROM 

     (SELECT F.FIRMAID,F.SUBEID,FATID,TARIH,SUBSTRING(QFT.FISTURADI,1,20) TURADI,F.FATNO, US.ADSOYAD KAYDEDEN,F.DEPOID CDEPOID,F.DEPOID,F.ACIKLAMA 

             FROM FATURA F WITH (NOLOCK)
             INNER JOIN QMUH_FISTUR QFT WITH (NOLOCK) ON QFT.FISTURID=F.FISTURID 
             INNER JOIN [NOVAUSER] US WITH (NOLOCK) ON US.NOVAUSERID=F.ADD_USERID 
             WHERE F.FIRMAID=@FIRMAID AND F.SUBEID=@SUBEID AND F.FISTURID=52 AND F.FATID IN (SELECT FATID FROM FATISL WITH (NOLOCK) INNER JOIN 

             STOK S WITH (NOLOCK) ON S.STOKID = FATISL.STOKID AND S.TURU IN ('Mamul','Yarı Mamul') AND S.FIRMAID=@FIRMAID)  

  ) TBL   

  WHERE SUBEID=@SUBEID AND (TARIH BETWEEN @TARIH AND @TARIH2) ORDER BY TARIH
/*47 */
INSERT INTO TUKETIMFISISL (STOKID,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,TEMPITSID)
 SELECT STOK2.STOKID,
        SUM(ADET*ORAN) AS MIKTAR,
        SUM(ADET*ORAN) AS TMIKTAR,
        ISNULL(FIYATLAR.ORTFIYAT,0) AS BFIYAT, ISNULL(FIYATLAR.ORTFIYAT,0) AS FBFIYAT, STOK2.BIRIM,1 SEVIYE,FATID
        FROM (
                   SELECT M.FATID,SUM(D.ADET) ADET,D.STOKID,STOK.KODU  

                   FROM FATURA M WITH (NOLOCK) INNER JOIN  

                        FATISL D  WITH (NOLOCK) ON M.FATID = D.FATID INNER JOIN 

                        STOK WITH (NOLOCK) ON STOK.STOKID = D.STOKID AND STOK.TURU IN ('Mamul','Yarı Mamul') AND M.SUBEID=@SUBEID

                   WHERE STOK.FIRMAID=@FIRMAID AND  M.FIRMAID=@FIRMAID  AND (M.SUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
               GROUP BY M.FATID,M.SUBEID,M.FISTURID,M.TARIH,M.DEPOID,M.[ADD_USERID],D.STOKID,STOK.KODU              ) AS TBL INNER JOIN 
                 RECETE        ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK          ON TBL.STOKID    = STOK.STOKID   INNER JOIN 
                 STOK AS STOK2 ON RECETE.STOKID = STOK2.STOKID  LEFT OUTER JOIN 
                (SELECT STOKID,ALISKDV ,SUM(GCADET) AS TADET, ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT, SUM(TOPLAMMALIYET) AS TTUTAR 
                  FROM [FNCQ_STOKISLEMLER] ('2000-01-01',@TARIH2,@FIRMAID) WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 
                  GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0) AS FIYATLAR ON (STOK2.STOKID = FIYATLAR.STOKID) AND STOK.FIRMAID=@FIRMAID AND STOK2.FIRMAID=@FIRMAID
        GROUP BY FATID,STOK2.STOKID,STOK2.SALISFIYAT,STOK2.BIRIM,ISNULL(FIYATLAR.ORTFIYAT,0)


/*DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM */
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='NovaV5 Faturadan Uretim Aktarimi~'


/*48 */
SELECT D.DEPOFISID FROM TUKETIMFISISL D WITH (NOLOCK) INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON D.STOKID=S.STOKID INNER JOIN 
 (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON D.DEPOFISID=M.DEPOFISID AND D.URETSEVIYE=1
/*49 BOŞ FİŞLER SİLİMYOR 20.02.2021 */
/*DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK)) */
/*50 */
UPDATE TUKETIMFIS SET TADET  = ADEDI,TTUTAR=TUTARI FROM 
(SELECT DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  FROM TUKETIMFISISL WITH (NOLOCK) GROUP BY DEPOFISID) DI INNER JOIN TUKETIMFIS WITH (NOLOCK) ON DI.DEPOFISID = TUKETIMFIS.DEPOFISID 
WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  1=1  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PRL_URETIMYAP_08032021]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




create PROCEDURE [dbo].[PRL_URETIMYAP_08032021]  
@TARIH NVARCHAR(10),
@TARIH2 NVARCHAR(10),
@SUBEID INT,
@FIRMAID INT,
@SUBEKODU NVARCHAR(10)
AS
DELETE FROM TUKETIMFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0  
AND TARIH BETWEEN @TARIH AND @TARIH2)
--13
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2
--14
UPDATE TUKETIMFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2
--15
DELETE FROM DEPOFISISL WHERE  DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2)
--16
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ABS(ISNULL(URUNFISID,0))>0 AND TARIH BETWEEN @TARIH AND @TARIH2
--17
UPDATE DEPOFIS SET URETILDI=0 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2
--18
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
--19
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND TARIH BETWEEN @TARIH AND @TARIH2
--20
INSERT INTO TUKETIMFIS (FIRMAID,SUBEID,TARIH,YETKILI,ISLEM,ENO,CDEPOID,SDEPART,CSUBEID,ACIKLAMA,MUHFC) 
 SELECT DISTINCT FIRMAID,SUBEID,TARIH,T.YETKILI,ISLEM,'S'+ENO,S.SARFDEPOID,T.SDEPART,T.CSUBEID,'NovaV5 Uretim Aktarimi~',T.DEPOFISID 
 FROM TUKETIMFIS T WITH (NOLOCK) INNER JOIN 
      TUKETIMFISISL TI WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
(SELECT STOKID ,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID AND ABS(ISNULL(S.SARFDEPOID,0))>0  
WHERE ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~' AND (T.FIRMAID=@FIRMAID AND T.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--21
INSERT INTO TUKETIMFISISL (STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,RCDEPOID,TEMPITSID) 
 SELECT TI.STOKID,TI.MIKTAR,TI.FBIRIM,TI.FMIKTAR,TI.BFIYAT,TI.YETKILI,TI.RCDEPOID,T.DEPOFISID 
 FROM TUKETIMFIS T  WITH (NOLOCK) INNER JOIN 
      TUKETIMFISISL TI  WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
      (SELECT STOKID ,SARFDEPOID FROM STOK  WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID AND ABS(ISNULL(S.SARFDEPOID,0))>0  
 WHERE ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~' AND (T.FIRMAID=@FIRMAID AND T.CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

--TUKETIMFIS=MUHC ILE TUKETIMFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL INNER JOIN TUKETIMFIS ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='NovaV5 Uretim Aktarimi~'

--22
UPDATE TUKETIMFISISL SET SARFDEPOID=S.SARFDEPOID FROM TUKETIMFISISL INNER JOIN (SELECT STOKID,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID AND ISNULL(SARFDEPOID,0)<>0 ) S ON TUKETIMFISISL.STOKID=S.STOKID  
WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2))
--23
INSERT INTO TUKETIMFIS  (FIRMAID,SUBEID,CSUBEID,ISLEM,TARIH,GDEPOID,CDEPOID ,GSKODU,CSKODU,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)
 SELECT FIRMAID,SUBEID,CSUBEID,CASE WHEN ISLEM = 'TRANSFER' THEN ISLEM WHEN ISLEM IN ('ZAYI','ZAYİ','ZAYII','ZAYİİ') THEN 'ZAYI' ELSE 'TUKETIM' END AS ISLEM,
 TARIH,GDEPOID ,CDEPOID ,@SUBEKODU,@SUBEKODU,TUKETIMFIS.YETKILI,ENO AS EVRAKNO,'Oto.Üretim' AS ACIKLAMA
 ,(TUKETIMFIS.DEPOFISID+7000000)*-1,ISLEM,2,TUKETIMFIS.DEPOFISID FROM TUKETIMFIS  WITH (NOLOCK)
 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(URUNFISID,0)=0  AND (TARIH BETWEEN @TARIH AND @TARIH2) 
 AND DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFISISL  WITH (NOLOCK) INNER JOIN STOK  WITH (NOLOCK) ON TUKETIMFISISL.STOKID=STOK.STOKID
 WHERE STOK.FIRMAID=@FIRMAID AND STOK.TURU IN ('Mamul','Yarı Mamul')  AND ISNULL(STOK.URETILMEZ,0)=0 ) AND ISNULL(URETILDI,0)=0 ORDER BY TARIH
--24
UPDATE TUKETIMFIS SET URETILDI=1 FROM TUKETIMFIS,TUKETIMFISISL,(SELECT STOKID,TURU,URETILMEZ FROM STOK WHERE FIRMAID=@FIRMAID) STOK  
WHERE    TUKETIMFIS.DEPOFISID=TUKETIMFISISL.DEPOFISID  AND TUKETIMFISISL.STOKID=STOK.STOKID AND 
ISNULL(STOK.URETILMEZ,0)=0 AND STOK.TURU IN ('Mamul','Yarı Mamul') AND ISNULL(URUNFISID,0)=0 AND ISNULL(LOGOAKTAR,0)=0 AND 1=1  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--25
INSERT INTO TUKETIMFISISL (STOKID,ACIKLAMA,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,RCDEPOID,TEMPITSID)
 SELECT STOK2.STOKID,'Oto.Üretimv5',
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END 
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS MIKTAR,
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS TMIKTAR,
        ISNULL(FIYATLAR.ORTFIYAT,0) AS BFIYAT, ISNULL(FIYATLAR.ORTFIYAT,0) AS FBFIYAT, STOK2.BIRIM,1,ISNULL(RECETE.SARFDEPOID,RCDEPOID) AS RCDEPOID,DEPOFISID 
        FROM (
               SELECT D.DEPOFISID,D.MIKTAR,D.STOKID,STOK.KODU,ISNULL(RCDEPOID,CDEPOID) RCDEPOID FROM TUKETIMFIS AS M WITH (NOLOCK),TUKETIMFISISL AS D WITH (NOLOCK),STOK WITH (NOLOCK)
                      WHERE M.FIRMAID=@FIRMAID AND  M.DEPOFISID=D.DEPOFISID AND STOK.STOKID=D.STOKID AND STOK.FIRMAID=@FIRMAID AND (M.CSUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
                            AND ISNULL(URETILMEZ,0)=0 AND 1=1 AND ISNULL(URUNFISID,0)=0
                            AND ISNULL(LOGOAKTAR,0)=0 AND TURU IN ('Mamul','Yarı Mamul') 
							AND ISNULL(D.SARFDEPOID,0)=0 
              ) AS TBL INNER JOIN 
                 RECETE WITH (NOLOCK)       ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK   WITH (NOLOCK)       ON TBL.STOKID    = STOK.STOKID   INNER JOIN 
                 STOK AS STOK2 WITH (NOLOCK) ON RECETE.STOKID = STOK2.STOKID  LEFT OUTER JOIN 
                (SELECT STOKID,ALISKDV ,SUM(GCADET) AS TADET, ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT, SUM(TOPLAMMALIYET) AS TTUTAR 
                  FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH2,@FIRMAID) WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 
                  GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0) AS FIYATLAR ON STOK2.STOKID = FIYATLAR.STOKID AND STOK.FIRMAID=@FIRMAID AND STOK2.FIRMAID=@FIRMAID 
        GROUP BY DEPOFISID,STOK2.STOKID,STOK2.SALISFIYAT,STOK2.BIRIM,ISNULL(FIYATLAR.ORTFIYAT,0),ISNULL(RECETE.SARFDEPOID,RCDEPOID)  

--TUKETIMFIS=MUHC ILE TUKETIMFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='Oto.Üretimv5' and TUKETIMFISISL.ACIKLAMA='Oto.Üretimv5'

--26
SELECT D.DEPOFISID FROM TUKETIMFISISL D INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON S.STOKID=D.STOKID  
INNER JOIN (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON M.DEPOFISID=D.DEPOFISID AND D.URETSEVIYE=1
--27  AŞAĞIDA MUHTEMELEN BOŞ FİŞLERİ SİLİYORUZ KONTROL EDELİM SONRA 20.02.2021
--DELETE FROM TUKETIMFIS WHERE ACIKLAMA='Oto.Üretimv5' AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM TUKETIMFISISL)
--28
UPDATE TUKETIMFIS SET TADET  = ADEDI,TTUTAR=TUTARI 
FROM (SELECT TUKETIMFISISL.DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  FROM TUKETIMFISISL WITH (NOLOCK) GROUP BY TUKETIMFISISL.DEPOFISID) DI INNER JOIN TUKETIMFIS ON DI.DEPOFISID = TUKETIMFIS.DEPOFISID 
WHERE  FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--29
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (TARIH BETWEEN @TARIH AND @TARIH2)) 
--30
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--31
DELETE FROM DEPOFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
--32
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (TARIH BETWEEN @TARIH AND @TARIH2)
--33
INSERT INTO DEPOFIS (TARIH,YETKILI,ISLEM,ENO,CDEPOID,SDEPART,FIRMAID,SUBEID,CSUBEID,ACIKLAMA,MUHFC) 

 SELECT DISTINCT TARIH,T.YETKILI,ISLEM,'S'+ENO,S.SARFDEPOID,T.SDEPART,T.FIRMAID,T.SUBEID,T.CSUBEID,'NovaV5 Uretim Aktarimi~',T.DEPOFISID 

 FROM DEPOFIS T INNER JOIN 

      DEPOFISISL TI ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 

     (SELECT STOKID ,SARFDEPOID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID   
	 WHERE T.FIRMAID=@FIRMAID AND ABS(ISNULL(S.SARFDEPOID,0))>0 AND ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

--34
INSERT INTO DEPOFISISL (STOKID,MIKTAR,FBIRIM,FMIKTAR,BFIYAT,YETKILI,RCDEPOID,TEMPITSID) 
 SELECT TI.STOKID,TI.MIKTAR,TI.FBIRIM,TI.FMIKTAR,TI.BFIYAT,TI.YETKILI,TI.RCDEPOID,T.DEPOFISID 
 FROM DEPOFIS T WITH (NOLOCK) INNER JOIN 
      DEPOFISISL TI WITH (NOLOCK) ON T.DEPOFISID =TI.DEPOFISID INNER JOIN 
      (SELECT STOKID ,SARFDEPOID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) S ON S.STOKID= TI.STOKID 
 WHERE T.FIRMAID=@FIRMAID AND ABS(ISNULL(S.SARFDEPOID,0))>0 AND ISNULL(T.ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)

--DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM
UPDATE DEPOFISISL SET DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID FROM DEPOFISISL WITH (NOLOCK) INNER JOIN DEPOFIS WITH (NOLOCK) ON DEPOFISISL.TEMPITSID=DEPOFIS.MUHFC WHERE DEPOFIS.FIRMAID=@FIRMAID AND
DEPOFIS.CSUBEID=@SUBEID AND DEPOFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND DEPOFIS.ACIKLAMA='NovaV5 Uretim Aktarimi~'

--35
UPDATE DEPOFISISL SET SARFDEPOID=S.SARFDEPOID FROM DEPOFISISL INNER JOIN (SELECT STOKID,SARFDEPOID FROM STOK WHERE FIRMAID=@FIRMAID AND ISNULL(SARFDEPOID,0)<>0 ) S ON DEPOFISISL.STOKID=S.STOKID  
WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')<>'NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2))
--36
--bizim pos satışı aşağıdaki kısımdan üretime geliyor.
INSERT INTO DEPOFIS  (FIRMAID,SUBEID,CSUBEID,GSUBEID,ISLEM,TARIH,GDEPOID,CDEPOID ,GSKODU,CSKODU,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)
 SELECT FIRMAID,SUBEID,CSUBEID,GSUBEID,CASE WHEN ISLEM = 'TRANSFER' THEN ISLEM WHEN ISLEM IN ('ZAYI','ZAYİ','ZAYII','ZAYİİ') THEN 'ZAYI' ELSE 'TUKETIM' END AS ISLEM,
 TARIH,GDEPOID ,CDEPOID ,'01','01',DEPOFIS.YETKILI,ENO AS EVRAKNO,'Oto.Üretimv5' AS ACIKLAMA
 ,(DEPOFIS.DEPOFISID+7000000)*-1,ISLEM,2,DEPOFIS.DEPOFISID FROM DEPOFIS WITH (NOLOCK)
 WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  ISNULL(URUNFISID,0)=0  AND (TARIH BETWEEN @TARIH AND @TARIH2) 
 AND DEPOFIS.DEPOFISID IN (SELECT DEPOFISISL.DEPOFISID FROM DEPOFISISL WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON DEPOFISISL.STOKID=STOK.STOKID INNER JOIN DEPOFIS WITH (NOLOCK) ON DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID
 WHERE DEPOFIS.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2 AND STOK.FIRMAID=@FIRMAID 
 AND STOK.TURU IN ('Mamul','Yarı Mamul')  AND ISNULL(STOK.URETILMEZ,0)=0 ) AND ISNULL(URETILDI,0)=0 ORDER BY TARIH
--37
UPDATE DEPOFIS SET URETILDI=1 FROM DEPOFIS,DEPOFISISL,(SELECT STOKID,TURU,URETILMEZ FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID) STOK  
WHERE  DEPOFIS.FIRMAID=@FIRMAID AND DEPOFIS.CSUBEID=@SUBEID AND DEPOFIS.DEPOFISID=DEPOFISISL.DEPOFISID  
AND DEPOFISISL.STOKID=STOK.STOKID AND ISNULL(STOK.URETILMEZ,0)=0 AND STOK.TURU IN ('Mamul','Yarı Mamul') 
AND ISNULL(URUNFISID,0)=0 AND ISNULL(LOGOAKTAR,0)=0 AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--38
INSERT INTO DEPOFISISL (STOKID,ACIKLAMA,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,RCDEPOID,TEMPITSID)
 SELECT STOK2.STOKID,'Oto.Üretimv5',
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END 
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS MIKTAR,
        SUM(TBL.MIKTAR*ORAN * CASE WHEN ISNULL(STOK2.RECETEKATSAYISI,0)=0 THEN 1 ELSE (1/STOK2.RECETEKATSAYISI) END
        / CASE WHEN (STOK.KISISAYISI IS NULL) OR (STOK.KISISAYISI=0) THEN 1 ELSE STOK.KISISAYISI END) AS TMIKTAR,
        ISNULL(FIYATLAR.ORTFIYAT,0) AS BFIYAT, ISNULL(FIYATLAR.ORTFIYAT,0) AS FBFIYAT, STOK2.BIRIM,1,ISNULL(RECETE.SARFDEPOID,RCDEPOID) AS RCDEPOID,DEPOFISID 
        FROM (
               SELECT D.DEPOFISID,D.MIKTAR,D.STOKID,STOK.KODU,ISNULL(RCDEPOID,CDEPOID) RCDEPOID FROM DEPOFIS AS M WITH (NOLOCK),DEPOFISISL AS D WITH (NOLOCK),STOK WITH (NOLOCK)
                      WHERE   M.DEPOFISID=D.DEPOFISID AND STOK.STOKID=D.STOKID   AND (M.CSUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
                            AND ISNULL(URETILMEZ,0)=0 AND 1=1 AND ISNULL(URUNFISID,0)=0
                            AND ISNULL(LOGOAKTAR,0)=0 AND TURU IN ('Mamul','Yarı Mamul') AND M.CSUBEID=@SUBEID AND STOK.FIRMAID=@FIRMAID
                            AND ISNULL(D.SARFDEPOID,0)=0 
              ) AS TBL INNER JOIN 
                 RECETE WITH (NOLOCK)       ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK  WITH (NOLOCK)        ON TBL.STOKID    = STOK.STOKID   INNER JOIN 
                 STOK AS STOK2 WITH (NOLOCK) ON RECETE.STOKID = STOK2.STOKID  LEFT OUTER JOIN 
                (SELECT STOKID,ALISKDV ,SUM(GCADET) AS TADET, ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT, SUM(TOPLAMMALIYET) AS TTUTAR 
                  FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH2,@FIRMAID) WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 
                  GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0) AS FIYATLAR ON (STOK2.STOKID = FIYATLAR.STOKID) AND STOK.FIRMAID=@FIRMAID AND STOK2.FIRMAID=@FIRMAID
        GROUP BY DEPOFISID,STOK2.STOKID,STOK2.SALISFIYAT,STOK2.BIRIM,ISNULL(FIYATLAR.ORTFIYAT,0),ISNULL(RECETE.SARFDEPOID,RCDEPOID)  

--DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM
UPDATE DEPOFISISL SET DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID FROM DEPOFISISL INNER JOIN DEPOFIS ON DEPOFISISL.TEMPITSID=DEPOFIS.MUHFC WHERE DEPOFIS.FIRMAID=@FIRMAID AND
DEPOFIS.CSUBEID=@SUBEID AND DEPOFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND DEPOFIS.ACIKLAMA='Oto.Üretimv5'


--39
SELECT D.DEPOFISID FROM DEPOFISISL D INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON S.STOKID=D.STOKID  
INNER JOIN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON M.DEPOFISID=D.DEPOFISID AND D.URETSEVIYE=1
--40 BURADA BOŞ FİŞ TEMİZLİYORUZ AMA TÜM KAYITLARA BAKMAK OLMAZ 20.02.2021
--DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND ACIKLAMA='Oto.Üretimv5' AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM DEPOFISISL WITH (NOLOCK))
--41
UPDATE DEPOFIS SET TADET  = ADEDI,TTUTAR=TUTARI FROM (SELECT DEPOFISISL.DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  
FROM DEPOFISISL GROUP BY DEPOFISISL.DEPOFISID) DI INNER JOIN DEPOFIS WITH (NOLOCK) ON DI.DEPOFISID = DEPOFIS.DEPOFISID WHERE  DEPOFIS.FIRMAID=@FIRMAID  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--42
DELETE FROM DEPOFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--43
DELETE FROM DEPOFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM DEPOFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
--44
DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Faturadan Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
--45
DELETE FROM TUKETIMFISISL WHERE DEPOFISID IN (SELECT DEPOFISID FROM TUKETIMFIS WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND ISNULL(ACIKLAMA,'')='NovaV5 Faturadan Uretim Aktarimi~'  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) 
--46
INSERT INTO TUKETIMFIS 
 (FIRMAID,SUBEID,CSUBEID,ISLEM,TARIH,CDEPOID,YETKILI,ENO,ACIKLAMA,URUNFISID,ISLEMDETAY,URETILDI,MUHFC)

 SELECT FIRMAID,SUBEID,SUBEID,'TUKETIM' ISLEM,TARIH,DEPOID,KAYDEDEN,'Fatura' ENO ,'NovaV5 Faturadan Uretim Aktarimi~' ACIKLAMA,

  FATID URUNFISID,TURADI,2 URETILDI,FATID
 FROM 

     (SELECT F.FIRMAID,F.SUBEID,FATID,TARIH,SUBSTRING(QFT.FISTURADI,1,20) TURADI,F.FATNO, US.ADSOYAD KAYDEDEN,F.DEPOID CDEPOID,F.DEPOID,F.ACIKLAMA 

             FROM FATURA F WITH (NOLOCK)
             INNER JOIN QMUH_FISTUR QFT WITH (NOLOCK) ON QFT.FISTURID=F.FISTURID 
             INNER JOIN [NOVAUSER] US WITH (NOLOCK) ON US.NOVAUSERID=F.ADD_USERID 
             WHERE F.FIRMAID=@FIRMAID AND F.SUBEID=@SUBEID AND F.FISTURID=52 AND F.FATID IN (SELECT FATID FROM FATISL WITH (NOLOCK) INNER JOIN 

             STOK S WITH (NOLOCK) ON S.STOKID = FATISL.STOKID AND S.TURU IN ('Mamul','Yarı Mamul') AND S.FIRMAID=@FIRMAID)  

  ) TBL   

  WHERE SUBEID=@SUBEID AND (TARIH BETWEEN @TARIH AND @TARIH2) ORDER BY TARIH
--47
INSERT INTO TUKETIMFISISL (STOKID,MIKTAR,FMIKTAR,BFIYAT,FBFIYAT,FBIRIM,URETSEVIYE,TEMPITSID)
 SELECT STOK2.STOKID,
        SUM(ADET*ORAN) AS MIKTAR,
        SUM(ADET*ORAN) AS TMIKTAR,
        ISNULL(FIYATLAR.ORTFIYAT,0) AS BFIYAT, ISNULL(FIYATLAR.ORTFIYAT,0) AS FBFIYAT, STOK2.BIRIM,1 SEVIYE,FATID
        FROM (
                   SELECT M.FATID,SUM(D.ADET) ADET,D.STOKID,STOK.KODU  

                   FROM FATURA M WITH (NOLOCK) INNER JOIN  

                        FATISL D  WITH (NOLOCK) ON M.FATID = D.FATID INNER JOIN 

                        STOK WITH (NOLOCK) ON STOK.STOKID = D.STOKID AND STOK.TURU IN ('Mamul','Yarı Mamul') AND M.SUBEID=@SUBEID

                   WHERE STOK.FIRMAID=@FIRMAID AND  M.FIRMAID=@FIRMAID  AND (M.SUBEID=@SUBEID AND M.TARIH BETWEEN @TARIH AND @TARIH2) 
               GROUP BY M.FATID,M.SUBEID,M.FISTURID,M.TARIH,M.DEPOID,M.[ADD_USERID],D.STOKID,STOK.KODU              ) AS TBL INNER JOIN 
                 RECETE        ON TBL.STOKID    = RECETE.URUNID INNER JOIN 
                 STOK          ON TBL.STOKID    = STOK.STOKID   INNER JOIN 
                 STOK AS STOK2 ON RECETE.STOKID = STOK2.STOKID  LEFT OUTER JOIN 
                (SELECT STOKID,ALISKDV ,SUM(GCADET) AS TADET, ROUND(SUM(TOPLAMMALIYET)/SUM(GCADET),5) AS ORTFIYAT, SUM(TOPLAMMALIYET) AS TTUTAR 
                  FROM [FNCQ_STOKISLEMLER] (@TARIH,@TARIH2,@FIRMAID) WHERE SUBEID=@SUBEID AND FISTIPI IN ('FATURA','SAYIM')  AND GCADET>0 
                  GROUP BY STOKID,ALISKDV HAVING SUM(GCADET)<>0) AS FIYATLAR ON (STOK2.STOKID = FIYATLAR.STOKID) AND STOK.FIRMAID=@FIRMAID AND STOK2.FIRMAID=@FIRMAID
        GROUP BY FATID,STOK2.STOKID,STOK2.SALISFIYAT,STOK2.BIRIM,ISNULL(FIYATLAR.ORTFIYAT,0)


--DEPOFIS=MUHC ILE DEPOFISISL=TEMPITSID ILE FİŞİ BİRLEŞTİRELİM
UPDATE TUKETIMFISISL SET TUKETIMFISISL.DEPOFISID=TUKETIMFIS.DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK) INNER JOIN TUKETIMFIS WITH (NOLOCK) ON TUKETIMFISISL.TEMPITSID=TUKETIMFIS.MUHFC WHERE TUKETIMFIS.FIRMAID=@FIRMAID AND
TUKETIMFIS.CSUBEID=@SUBEID AND TUKETIMFISISL.DEPOFISID IS NULL  AND TARIH BETWEEN @TARIH AND @TARIH2 AND TUKETIMFIS.ACIKLAMA='NovaV5 Faturadan Uretim Aktarimi~'


--48
SELECT D.DEPOFISID FROM TUKETIMFISISL D WITH (NOLOCK) INNER JOIN (SELECT STOKID FROM STOK WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TURU IN ('Mamul','Yarı Mamul')) S ON D.STOKID=S.STOKID INNER JOIN 
 (SELECT DEPOFISID FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)) M ON D.DEPOFISID=M.DEPOFISID AND D.URETSEVIYE=1
--49 BOŞ FİŞLER SİLİMYOR 20.02.2021
--DELETE FROM TUKETIMFIS WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND DEPOFISID NOT IN (SELECT DEPOFISID FROM TUKETIMFISISL WITH (NOLOCK))
--50
UPDATE TUKETIMFIS SET TADET  = ADEDI,TTUTAR=TUTARI FROM 
(SELECT DEPOFISID, COUNT(*) ADEDI,SUM(MIKTAR*BFIYAT) TUTARI  FROM TUKETIMFISISL WITH (NOLOCK) GROUP BY DEPOFISID) DI INNER JOIN TUKETIMFIS WITH (NOLOCK) ON DI.DEPOFISID = TUKETIMFIS.DEPOFISID 
WHERE FIRMAID=@FIRMAID AND CSUBEID=@SUBEID AND  1=1  AND (CSUBEID=@SUBEID AND TARIH BETWEEN @TARIH AND @TARIH2)
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[PRL_URUN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM STOK WITH (NOLOCK) WHERE TURU=''Mamul'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUNANAGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_URUNANAGRUP]  @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT ANAGRUPADI FROM SGRUP WITH (NOLOCK) WHERE ISNULL(ANAGRUPADI,'''')<>'''' AND GRUPTURU=''URUN'' and 1=1 '+@PARAMETRE+' GROUP BY ANAGRUPADI
UNION ALL
SELECT ''TÜMÜ'''
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUNEKOZELLIK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_URUNEKOZELLIK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1000)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM URUNEKOZELLIK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE+
' UNION ALL SELECT NULL AS URUNEKOZELLIKID, NULL AS STOKID,EKOZELLIKID,NULL AS ACIKLAMA,FIYAT FROM EKOZELLIK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND  TUMURUNLER=1 AND 
FIRMAID IN(SELECT FIRMAID FROM STOK WHERE 1=1 '+@PARAMETRE+')'
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUNEKOZELLIK2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URUNEKOZELLIK2]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(1000)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM URUNEKOZELLIK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUNGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_URUNGRUP]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM SGRUP WITH (NOLOCK) WHERE GRUPTURU=''URUN'' and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_URUNSATIS_MOBIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_URUNSATIS_MOBIL] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
SELECT STOK.ADI AS URUNADI, SUM(ADET) AS MIKTAR, SUM( (ADET*BIRIMFIYAT)/100*(100-ADISYON.INDORAN)) AS TOPLAM 
FROM ADSSATIR WITH (NOLOCK) INNER JOIN STOK WITH (NOLOCK) ON ADSSATIR.STOKID=STOK.STOKID
INNER JOIN ADISYON WITH (NOLOCK) ON ADSSATIR.FISCOUNTER=ADISYON.FISCOUNTER
WHERE ISNULL(ADSSATIR.SIL,0)=0 AND ISNULL(ADISYON.SIL,0)=0 AND ADISYON.FIRMAID=@FIRMAID AND TARIH BETWEEN @TARIH AND @TARIH2
GROUP BY STOK.ADI ORDER BY SUM(ADET) DESC
GO
/****** Object:  StoredProcedure [dbo].[PRL_USERGRID]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRL_USERGRID]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM USERGRID WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_VARDIYA_ANALIZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_VARDIYA_ANALIZ]  @FIRMAID NVARCHAR(10), @YIL NVARCHAR(4), @AY NVARCHAR(2), @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT * FROM FNCQ_VARDIYA_ANALIZ ('+@FIRMAID+','+@YIL+','+@AY+') WHERE  1=1  '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_VARDIYATARIH]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_VARDIYATARIH]  
 (@IKVARDIYAID INT, @DONEMBASI SMALLDATETIME, @DONEMSONU SMALLDATETIME) AS 
BEGIN 
	DECLARE 
	@IKVARDIYATANIMID INT,
	@PSICILID INT,
	@GUN1 INT,
	@GUN2 INT,
	@GUN3 INT,
	@GUN4 INT,
	@GUN5 INT,
	@GUN6 INT,
	@GUN7 INT

			DELETE FROM IKVARDIYATARIH WHERE IKVARDIYAID=@IKVARDIYAID
			DECLARE PERSONEL_EKLE CURSOR FOR
					
			SELECT PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7  FROM IKVARDIYADETAY WHERE IKVARDIYAID=@IKVARDIYAID

			OPEN PERSONEL_EKLE		

			FETCH NEXT FROM PERSONEL_EKLE INTO @PSICILID,@GUN1,@GUN2,@GUN3,@GUN4,@GUN5,@GUN6,@GUN7

	WHILE @@FETCH_STATUS=0
		BEGIN
					IF @GUN1>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI,@PSICILID,@GUN1,1)
						END
					IF @GUN2>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+1,@PSICILID,@GUN2,1)
						END
					IF @GUN3>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+2,@PSICILID,@GUN3,1)
						END
					IF @GUN4>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+3,@PSICILID,@GUN4,1) 
						END
					IF @GUN5>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+4,@PSICILID,@GUN5,1)					 
						END
					IF @GUN6>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+5,@PSICILID,@GUN6,1)					 
						END
					IF @GUN7>0 
						BEGIN	
							INSERT INTO IKVARDIYATARIH (IKVARDIYAID,TARIH,PSICILID,IKVARDIYATANIMID,SAY)
							VALUES(@IKVARDIYAID,@DONEMBASI+6,@PSICILID,@GUN7,1)					 
						END
			FETCH NEXT FROM PERSONEL_EKLE  INTO @PSICILID,@GUN1,@GUN2,@GUN3,@GUN4,@GUN5,@GUN6,@GUN7		
		END
	CLOSE PERSONEL_EKLE
	DEALLOCATE PERSONEL_EKLE
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_VARDIYAUPDATE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRL_VARDIYAUPDATE] @IKVARDIYAID INT, @HAFTABASI NVARCHAR(10), @HAFTASONU NVARCHAR(10), 
@FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @DEPARTMANID NVARCHAR(10)
AS
UPDATE IKVARDIYADETAY SET IKVARDIYADETAY.ISTENAYRILIS=IKPERSONEL.ISTENAYRILIS FROM IKVARDIYADETAY INNER JOIN IKPERSONEL ON IKVARDIYADETAY.PSICILID=
IKPERSONEL.PSICILID WHERE IKVARDIYADETAY.IKVARDIYAID=@IKVARDIYAID AND FIRMAID=@FIRMAID and SUBEID=@SUBEID
        AND IKPERSONEL.DEPARTMANID=@DEPARTMANID 

INSERT INTO IKVARDIYADETAY (IKVARDIYAID,IKVARDIYATANIMID,PSICILID,GUN1,GUN2,GUN3,GUN4,GUN5,GUN6,GUN7,CALISMAGUN,DIGERGUN,ISEGIRIS,ISTENAYRILIS)
SELECT @IKVARDIYAID,NULL,PSICILID,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,ISEGIRIS,ISTENAYRILIS FROM IKPERSONEL WHERE FIRMAID=@FIRMAID and SUBEID=@SUBEID
        AND ISNULL(SIL,0)=0 AND ISNULL(CALISIYOR,1)=1 and DEPARTMANID=@DEPARTMANID
        and ISEGIRIS<=@HAFTASONU AND (ISTENAYRILIS IS NULL OR ISTENAYRILIS>@HAFTASONU) AND PSICILID NOT IN(SELECT PSICILID FROM IKVARDIYADETAY WHERE IKVARDIYAID=@IKVARDIYAID)
GO
/****** Object:  StoredProcedure [dbo].[PRL_YEMEKSEPETI_Options]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_YEMEKSEPETI_Options]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM YEMEKSEPETI_Options WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_YEVFATURAKONTROL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_YEVFATURAKONTROL] @FIRMAID INT, @SUBEID INT, @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10)
AS
BEGIN
SELECT FATID FROM FATURA 
   WHERE ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND FISDURUMID>=0 AND TARIH BETWEEN @TARIH AND @TARIH2 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_YEVMIYEDEFTERI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_YEVMIYEDEFTERI] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE @SQL NVARCHAR(500)
SET @SQL='SELECT * FROM [FNCQ_QMUH_HESAPISLYEVMIYE] ('''+@TARIH+''','''+@TARIH2+''','''+@FIRMAID+''') WHERE SUBEID='''+@SUBEID+''''+@PARAMETRE
EXEC(@SQL)
END
GO
/****** Object:  StoredProcedure [dbo].[PRL_YEVMIYENOVER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRL_YEVMIYENOVER]  
(@FIRMAID INT, @SUBEID INT, @ESKIYEVMNOSIL BIT,@USERID INT,@DONEMBASI NVARCHAR(10),@DONEMSONU NVARCHAR(10),@BASTARIH NVARCHAR(10),@BITTARIH NVARCHAR(10))
AS
BEGIN


  IF @DONEMBASI=NULL
  BEGIN
   RAISERROR('Dönem Bilgileri Olmadan Yevmiye No Verilemez',16,1)
   RETURN 1
  END

  -- Bu işi Try içinde transaction ile yapalım ne olur ne olmaz
  BEGIN TRY  

  DECLARE @Trans VARCHAR(20);  
  SELECT @Trans = 'YevmiyeNoVerelim';  

  BEGIN TRANSACTION @Trans

  IF ISNULL(@ESKIYEVMNOSIL,0)=1
  BEGIN
   UPDATE MUH_FIS SET FISDURUMID=ISNULL(ESKIFISDURUMID,1), -- eski fişdurumu zaten tutmustuk yoksa 1 muhasebeleştiye alıyoruz
   YEVMNO=NULL,YEVMTARIH=NULL,YEVMACIKLAMA=NULL ,YEVSATIRSIRANO=NULL
   WHERE ISNULL(SIL,0)=0 AND  ISNULL(FISDURUMID,0)>-1 AND YEVMNO IS NOT NULL AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID IN (SELECT SUBEID FROM SUBELER WITH (NOLOCK) WHERE SUBEID=@SUBEID)

   UPDATE MUH_HESAPISL
   SET YEVSATIRSIRANO=NULL
   WHERE FISID IN 
   (
   SELECT FISID FROM MUH_FIS WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID IN (SELECT SUBEID FROM SUBELER WITH (NOLOCK)  WHERE SUBEID=@SUBEID)
   )
  END

  -- O dönem içindeki en son yevmiyenoyu bir bulalım not edelim 
  DECLARE @SONYEVMNO INT  
  SELECT @SONYEVMNO = MAX(ISNULL(CONVERT(INT,YEVMNO),0)) FROM MUH_FIS WITH (NOLOCK)  
  WHERE ISNULL(SIL,0)=0 AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  AND SUBEID IN (SELECT SUBEID FROM SUBELER WHERE SUBEID=@SUBEID)

  -- hadi artık no verelim 
   UPDATE MUH_FIS 
   SET  
   MUH_FIS.EDIT_USERID  =  @USERID,
   MUH_FIS.EDIT_DATE    =  GetDate(),
   MUH_FIS.YEVMNO       = TBLYEV.YEVMNO, 
   MUH_FIS.ESKIFISDURUMID   =  TBLYEV.FISDURUMID,
   MUH_FIS.FISDURUMID   =  3,
   MUH_FIS.YEVMTARIH    = TBLYEV.TARIH, 
   MUH_FIS.YEVMACIKLAMA = TBLYEV.ACIKLAMA 
   FROM MUH_FIS   INNER JOIN 
   (
	 SELECT (ROW_NUMBER() OVER (ORDER BY TARIH,SIRA,FISTURID,FISID))+@SONYEVMNO AS YEVMNO,FISTURU, 
	 TARIH,ACIKLAMA,FISID,FISTURID,SUBEID,FISDURUMID FROM 
	 (
	  -- Açılış Fişi ilk önce olmalı 
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURU,-1 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS  WITH (NOLOCK) 
	  WHERE  ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND   SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (49) -- Varsa diğer şartlar
	  -- Dönem Fişlerini ekleyelim
	  UNION ALL 
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURU,0 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS WITH (NOLOCK) 
	  WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND   SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
	   AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID NOT IN (48,49)
	  -- Kapanış Fişi en Sonra olmalı
	  UNION ALL
	  SELECT FISID,TARIH,ACIKLAMA,FISTURID,FISTURU, 1 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS WITH (NOLOCK)  
	  WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND   SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (48) -- Varsa diğer şartlar
	 ) TBL
   ) TBLYEV  ON MUH_FIS.FISID=TBLYEV.FISID
  WHERE ISNULL(MUH_FIS.SIL,0)=0 AND  MUH_FIS.FIRMAID=@FIRMAID  AND MUH_FIS.SUBEID=@SUBEID AND MUH_FIS.TARIH BETWEEN @DONEMBASI AND @DONEMSONU AND ISNULL(MUH_FIS.YEVMNO,0)=0 AND MUH_FIS.TARIH<=@BITTARIH  
 
  COMMIT TRANSACTION @Trans
 
  DECLARE @SATIRYEVMNO INT
 
  
 --EVE VERELİM Mİ NUMARA DÜŞÜNÜYORUM SIRALI OLMAYACAK BU COZER AMA SIRA OLMAZ
  DECLARE @CFISID INT
  DECLARE @CTARIH DATETIME
  DECLARE FIS_CURSOR CURSOR FOR 
  SELECT FISID,TARIH  FROM 
  (
    -- Açılış Fişi ilk önce olmalı 
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURU,-1 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS WITH (NOLOCK)  
	  WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (49) -- Varsa diğer şartlar
	  -- Dönem Fişlerini ekleyelim
	  UNION ALL 
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURU,0 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS WITH (NOLOCK)  
	  WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND  SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU
	   AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID NOT IN (48,49)
	  -- Kapanış Fişi en Sonra olmalı
	  UNION ALL
	  SELECT YEVMNO,FISID,TARIH,ACIKLAMA,FISTURID,FISTURU, 1 AS SIRA,SUBEID,FISDURUMID FROM MUH_FIS WITH (NOLOCK)  
	  WHERE ISNULL(SIL,0)=0 AND ISNULL(FISDURUMID,0)>=0 AND FIRMAID=@FIRMAID AND SUBEID=@SUBEID AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU 
		AND TARIH BETWEEN @BASTARIH AND @BITTARIH AND FISTURID IN (48) -- Varsa diğer şartlar
  ) TBLFIS 
  ORDER BY YEVMNO --,TARIH  --SIRA
  OPEN FIS_CURSOR 
  FETCH NEXT FROM FIS_CURSOR INTO @CFISID,@CTARIH   

  WHILE (@@FETCH_STATUS=0 )
  BEGIN
    -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
    SELECT @SATIRYEVMNO=ISNULL(MAX(YEVSATIRSIRANO),0) FROM [FNCQ_QMUH_HESAPISL2] (@DONEMBASI,@DONEMSONU,@FIRMAID) QMUH_HESAPISL2  
    WHERE  SUBEID=@SUBEID AND TARIH<=@CTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  

	  -- hadi satırlarada numara verelim
	  UPDATE MUH_HESAPISL SET YEVSATIRSIRANO=SATIRNO FROM MUH_HESAPISL
	  INNER JOIN 
	  (
	   SELECT ISLEMID,(ROW_NUMBER() OVER (ORDER BY CASE WHEN MUH_HESAPISL.ALACAK>0 THEN 1 ELSE 0 END,MUH_HESAP.KODU,ISLEMID))+@SATIRYEVMNO AS SATIRNO  FROM MUH_HESAPISL WITH (NOLOCK)  
	   INNER JOIN MUH_HESAP WITH (NOLOCK)  ON MUH_HESAP.HESAPID=MUH_HESAPISL.HESAPID 
	   WHERE MUH_HESAPISL.FISID=@CFISID AND abs(FISID)>0 AND ISNULL(MUH_HESAPISL.SILINDI,0)=0) TBL 
	   ON MUH_HESAPISL.ISLEMID=TBL.ISLEMID

	  -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
	 -- SELECT @SATIRYEVMNO=MAX(YEVSATIRSIRANO) FROM QMUH_HESAPISL2  
	 -- WHERE  SUBEID=@SUBEID AND TARIH<@BASTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  
	  -- hadi başlıklara numara verelim
    -- o dönem içindeki son satır nosunu verelim bu bize edefterde de lazım olacak
     SELECT @SATIRYEVMNO=ISNULL(MAX(YEVSATIRSIRANO),0) FROM [FNCQ_QMUH_HESAPISL2] (@DONEMBASI,@DONEMSONU,@FIRMAID) QMUH_HESAPISL2  
     WHERE  SUBEID=@SUBEID AND TARIH<=@CTARIH AND TARIH BETWEEN @DONEMBASI AND @DONEMSONU  
	 UPDATE MUH_FIS SET YEVSATIRSIRANO=SATIRNO FROM MUH_FIS 
	  INNER JOIN 
	  (
	   SELECT FISID,(ROW_NUMBER() OVER (ORDER BY CASE WHEN QMUH_HESAPISL2.ALACAK>0 THEN 1 ELSE 0 END,MUH_HESAP.KODU,ISLEMID))+@SATIRYEVMNO AS SATIRNO  
	   FROM [FNCQ_QMUH_HESAPISL2] (@DONEMBASI,@DONEMSONU,@FIRMAID) QMUH_HESAPISL2  
	   INNER JOIN MUH_HESAP ON MUH_HESAP.HESAPID=QMUH_HESAPISL2.HESAPID 
	   WHERE QMUH_HESAPISL2.SUBEID=@SUBEID AND MUH_HESAP.SUBEID=@SUBEID AND ISNULL(SIL,0)=0 AND FISID=@CFISID AND abs(FISID)>0 AND FISHESAPID IS NOT NULL
	  ) AS TBL2 ON MUH_FIS.FISID=TBL2.FISID

  FETCH NEXT FROM FIS_CURSOR INTO @CFISID ,@CTARIH
  END 

  CLOSE FIS_CURSOR 
  DEALLOCATE FIS_CURSOR 
 
  SELECT 0 HataNo,'' HataMesaji
  END TRY 
  BEGIN CATCH  
    -- Execute error retrieval routine.
	
    CLOSE FIS_CURSOR 
    DEALLOCATE FIS_CURSOR 
    
    ROLLBACK TRANSACTION @Trans
    SELECT  
     ERROR_NUMBER() AS HataNo
    ,ERROR_MESSAGE() AS HataMesaji  
 END CATCH;   


 END
GO
/****** Object:  StoredProcedure [dbo].[PRL_YEVMIYESIL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRL_YEVMIYESIL]  
(@FIRMAID INT, @SUBEID INT, @DONEMBASI nvarchar(10),@DONEMSONU nvarchar(10),@BASTARIH nvarchar(10),@BITTARIH nvarchar(10))
AS
BEGIN
  IF @DONEMBASI=NULL
  BEGIN
   RAISERROR('Dönem Bilgileri Olmadan Yevmiye No Silinemez',16,1)
   RETURN 1
  END
   UPDATE MUH_FIS SET FISDURUMID=ISNULL(ESKIFISDURUMID,1), -- eski fişdurumu zaten tutmustuk yoksa 1 muhasebeleştiye alıyoruz
   YEVMNO=NULL,YEVMTARIH=NULL,YEVMACIKLAMA=NULL, YEVSATIRSIRANO=NULL 
   WHERE ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID=@SUBEID AND FIRMAID=@FIRMAID

   UPDATE MUH_HESAPISL SET  YEVSATIRSIRANO=NULL   WHERE FISID IN(SELECT FISID FROM MUH_FIS WHERE ISNULL(FISDURUMID,0)>-1 AND 
   TARIH BETWEEN @DONEMBASI AND @DONEMSONU and TARIH BETWEEN @BASTARIH AND @BITTARIH AND SUBEID=@SUBEID AND FIRMAID=@FIRMAID)

END
GO
/****** Object:  StoredProcedure [dbo].[PRLE_VERSIYONGUNCELLE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRLE_VERSIYONGUNCELLE]  @SQL NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
EXEC (@SQL)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_ALTHESAPBAKIYE_FATURA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO






CREATE PROCEDURE [dbo].[PRLQ_ALTHESAPBAKIYE_FATURA]  @TARIHFIRMASUBE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX),
@SQLCUMLE9 NVARCHAR(MAX),
@PARAMTUKETIMFIS NVARCHAR(150)
SET @PARAMTUKETIMFIS=REPLACE(@TARIHFIRMASUBE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @PARAMTUKETIMFIS=REPLACE(@PARAMTUKETIMFIS,'SUBEID','TUKETIMFIS.SUBEID')
SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
	F.HESAPID, F.ALTCARIID, M.KODU AS KODU,
	M.UNVANI AS HESAPADI, SUM(F.BORC) AS BORC, SUM(F.ALACAK) AS ALACAK, M.DOVIZ, SUM(F.DBORC) AS DBORC,
	SUM(F.DALACAK) AS DALACAK
	 FROM (SELECT F.FIRMAID, F.SUBEID,  HI.HESAPID, HI.ALTCARIID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              HI.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT  F.FIRMAID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, 
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT F.FIRMAID, F.SUBEID, F.FISHESAPID, F.ALTCARIID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(HI.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 F.DOVIZ AS HDOVIZ FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4=' UNION ALL
--SERVIS FORMU
    SELECT FIRMAID,SUBEID,CARIID AS HESAPID, ALTCARIID, NETTOPLAM AS BORC, 0.00 AS ALACAK,
  NETTOPLAM AS DBORC, 0.00 AS DALACAK, ''TL'' AS DOVIZ
  FROM SERVISFORM WITH (NOLOCK)  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '
SET @SQLCUMLE5=' UNION ALL
--FATURA SATIS
    SELECT FIRMAID,SUBEID,FISHESAPID AS HESAPID,ALTCARIID,GTOPLAM AS BORC, 0.00 AS ALACAK, 
DTOPLAM AS DBORC, 0.00 AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND  FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE6=' UNION ALL
--FATURA ALIS
    SELECT FIRMAID,SUBEID,FISHESAPID AS HESAPID,ALTCARIID,0.00 AS BORC, GTOPLAM AS ALACAK, 
0.00 AS DBORC, DTOPLAM AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE7=' UNION ALL
--TUKETIMFIS ACIK
    SELECT TUKETIMFIS.FIRMAID,DEPO.ACIKSUBEID AS SUBEID,HESAPID AS HESAPID,ALTCARIID,TOPLAM AS BORC, 0.00 AS ALACAK, 
TOPLAM AS DBORC, 0.00 AS DALACAK,DKODU AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID WHERE ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0  AND 1=1 '
SET @SQLCUMLE8=' ) AS F 
 INNER JOIN  dbo.MUH_HESAP_ALTCARI M            WITH (NOLOCK)   ON F.ALTCARIID           = M.ALTCARIID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 WHERE 1=1 GROUP BY F.HESAPID,F.ALTCARIID,M.KODU,M.UNVANI,M.DOVIZ'
SET @SQLCUMLE9=' '
EXEC (@SQLCUMLE1+@TARIHFIRMASUBE+@SQLCUMLE2+@TARIHFIRMASUBE+@SQLCUMLE3+@TARIHFIRMASUBE+@SQLCUMLE4+@TARIHFIRMASUBE+@SQLCUMLE5+@TARIHFIRMASUBE+@SQLCUMLE6+@TARIHFIRMASUBE+@SQLCUMLE7+@PARAMTUKETIMFIS+@SQLCUMLE8+@SQLCUMLE9)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_EFATURA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRLQ_EFATURA]  @PARAMETRE NVARCHAR(300)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT 
   FISTURID,ISNULL(DOVIZ,'''') FATURADOVIZI, ISNULL(ISNULL(EFATURAACIKLAMA, ACIKLAMA),'''') ACIKLAMA,EFATURAACIKLAMA2,F.FATID,
   F.FISHESAPID AS CARIID,UUID,FATNO,EFATNO,EFATURADURUM,EDEVLET_ILETIMYONTEMI,ISNULL(EDEVLETDURUM,1) EDEVLETDURUM,
   TARIH,SAAT,ROUND(TOPLAM,2) AS FATURATOPLAM,ROUND((TOPLAM+OTV),2) AS FATURAOTVLITOPLAM,ROUND(GTOPLAM,2) AS GENELTOPLAM,
   ROUND((ISNULL(F.IND1,0)+ISNULL(F.IND2,0)+ISNULL(F.IND3,0)+ISNULL(F.EK1,0)+ISNULL(F.EK2,0)+ISNULL(F.EK3,0)+ISNULL(F.SIND,0)),2) AS FATURAINDIRIM,
   ROUND(KDV,2) AS FATURAKDV,ROUND(OTV,2) AS FATURAOTV,ROUND(NTOPLAM,2) AS FATURANETTOPLAM,
   F.UNVANI,ISNULL(ADRES1,'''') FATURADRES,ISNULL(ADRES2,'''') FATURADRES2, ISNULL(ADRES3,'''') AS FATURADRES3,VD,
   VDNO,TEL TEL1,FAX,EMAIL, WEB, EFATURAZARF, EFATURAINDYOK,
   EFATURA_LOG, EFATURA_SONGONTAR, ''TL'' AS DOVIZ, EFATURA_ENTREFNO, F.FIRMAID, F.SUBEID, CASE WHEN ISNULL(F.KUR,1) = 0 THEN 1 ELSE ISNULL(F.KUR,1) END AS KUR,  ISNULL(EFATTURU,0) AS EFATTURU,
   EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,EFATURA_CEVAPREFNO,EFATURA_CEVAP_UUID,EFATURA_CEVAPNO, KDVACIKLAMA,KDVSIZLIKKODU,      SIPARISNO, SIPARISTARIHI, IRSALIYENO,IRSALIYETARIHI,
   EFATURA_PKUTUSU, EFATURA_KABULREDNOTU, SUBEID GSUBEID, EFATURAACIKLAMA, VADE,
   ISNULL(ONLINE,0) ONLINE,ONLINE_WEBADRES,ONLINE_ODEMESEKLI,ONLINE_ODEME_TARIHI,ONLINE_GONDERIM_TARIHI,ONLINE_GONDERIM_TASIYANTURU,
   ONLINE_GONDERIM_TASIYANKIMLIKNO,ONLINE_GONDERIM_TASIYANADI,GBEYANNO, GBEYANTARIHI, GMAKBUZNO, GMAKBUZTARIHI, GIRISGUMRUK, ALISYAPILANFIRMA,ALISFNO, ALISFTARIHI, MODELYILI,SASINO,RENK,MOTORNO,  
   EI_SATICIVKNO	,EI_SATICIUNVAN	,EI_ALICIVKNO,EI_ALICIUNVAN	,EI_ISLEMBASLATANVKNO, 
   EI_ISLEMBASLATANUNVAN	,EI_TASIYICIVKNO	,EI_TASIYICIUNVAN,EI_ARACPLAKA	,EI_DORSEPLAKA	,
   EI_ARACSOFORADISOYADI ,EI_ARACSOFORID,EI_TESLIMATTANIM,EI_TESLIMATADRES,EI_TESLIMATILCE,EI_TESLIMATIL,EI_TESLIMATULKE 
   FROM FATURA AS F LEFT JOIN FATURADETAY ON F.FATID=FATURADETAY.FATID LEFT JOIN FATURAEK ON F.FATID=FATURAEK.FATID 
   WHERE ISNULL(EFATURADURUM,0)>0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_HESAPBAKIYE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[PRLQ_HESAPBAKIYE]  @TARIHFIRMASUBE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX)

SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
	F.HESAPID, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI, SUM(F.BORC) AS BORC, SUM(F.ALACAK) AS ALACAK, M.DOVIZ, SUM(F.DBORC) AS DBORC,
	SUM(F.DALACAK) AS DALACAK
	 FROM (SELECT F.FIRMAID, F.SUBEID,  HI.HESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              HI.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT  F.FIRMAID, F.SUBEID, F.FISHESAPID, 
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT F.FIRMAID, F.SUBEID, F.FISHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4=' UNION ALL
--SERVIS FORMU
    SELECT FIRMAID,SUBEID,CARIID AS HESAPID, NETTOPLAM AS BORC, 0.00 AS ALACAK,
  NETTOPLAM AS DBORC, 0.00 AS DALACAK, ''TL'' AS DOVIZ
  FROM SERVISFORM WITH (NOLOCK)  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '
SET @SQLCUMLE5=' ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 WHERE 1=1 GROUP BY F.HESAPID,M.KODU,M.ACIKLAMA,M.DOVIZ'
SET @SQLCUMLE6=' '
EXEC (@SQLCUMLE1+@TARIHFIRMASUBE+@SQLCUMLE2+@TARIHFIRMASUBE+@SQLCUMLE3+@TARIHFIRMASUBE+@SQLCUMLE4+@TARIHFIRMASUBE+@SQLCUMLE5+@SQLCUMLE6)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_HESAPBAKIYE_EMLAKSITE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRLQ_HESAPBAKIYE_EMLAKSITE]  @TARIHFIRMASUBE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX),
@SQLCUMLE9 NVARCHAR(MAX),
@SQLCUMLE10 NVARCHAR(MAX),
@SQLCUMLE11 NVARCHAR(MAX),
@PARAMTUKETIMFIS NVARCHAR(150)
SET @PARAMTUKETIMFIS=REPLACE(@TARIHFIRMASUBE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @PARAMTUKETIMFIS=REPLACE(@PARAMTUKETIMFIS,'SUBEID','TUKETIMFIS.SUBEID')
SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
	OZELKODID, F.HESAPID, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI, SUM(F.BORC) AS BORC, SUM(F.ALACAK) AS ALACAK, M.DOVIZ, SUM(F.DBORC) AS DBORC,
	SUM(F.DALACAK) AS DALACAK
	 FROM (SELECT F.FIRMAID, F.SUBEID, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, HI.HESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              HI.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT  F.FIRMAID, F.SUBEID, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID,  F.FISHESAPID, 
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT F.FIRMAID, F.SUBEID, ISNULL(HI.OZELKODID,F.OZELKODID) AS OZELKODID, F.FISHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4=' UNION ALL
--SERVIS FORMU
    SELECT FIRMAID,SUBEID,NULL AS OZELKODID,CARIID AS HESAPID, NETTOPLAM AS BORC, 0.00 AS ALACAK,
  NETTOPLAM AS DBORC, 0.00 AS DALACAK, ''TL'' AS DOVIZ
  FROM SERVISFORM WITH (NOLOCK)  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '
SET @SQLCUMLE5=' UNION ALL
--FATURA SATIS
    SELECT FIRMAID,SUBEID,NULL AS OZELKODID, FISHESAPID AS HESAPID,GTOPLAM AS BORC, 0.00 AS ALACAK, 
DTOPLAM AS DBORC, 0.00 AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND  FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE6=' UNION ALL
--FATURA ALIS
    SELECT FIRMAID,SUBEID,NULL AS OZELKODID, FISHESAPID AS HESAPID,0.00 AS BORC, GTOPLAM AS ALACAK, 
0.00 AS DBORC, DTOPLAM AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE7=' UNION ALL
--FATURA ALIS ODEMELERI
    SELECT FIRMAID,SUBEID,NULL AS OZELKODID, FISHESAPID AS HESAPID,ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, 
ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC, 0.00 AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE8=' UNION ALL
--TUKETIMFIS ACIK
    SELECT TUKETIMFIS.FIRMAID,DEPO.ACIKSUBEID AS SUBEID,NULL AS OZELKODID, HESAPID AS HESAPID,ISNULL(ACIK,0) AS BORC, 0.00 AS ALACAK, 
ISNULL(ACIK,0) AS DBORC, 0.00 AS DALACAK,DKODU AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID 
WHERE ABS(ACIK)>0 AND ISLEM=''SATIS'' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0  AND 1=1 '
SET @SQLCUMLE9=' UNION ALL
SELECT TUKETIMFIS.FIRMAID,DEPO.ACIKSUBEID AS SUBEID,NULL AS OZELKODID, HESAPID AS HESAPID,0.00 AS BORC, ISNULL(ACIK,0) AS ALACAK, 
0.00 AS DBORC, ISNULL(ACIK,0) AS DALACAK,DKODU AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID 
WHERE ABS(ACIK)>0 AND ISLEM=''ALIS'' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0  AND 1=1 '
SET @SQLCUMLE10=' ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 WHERE F.HESAPID IN(SELECT MUSTERIHESAPID FROM MUH_GRUP WHERE TIPID=8 AND MUSTERIHESAPID>0) GROUP BY OZELKODID, F.HESAPID,M.KODU,M.ACIKLAMA,M.DOVIZ'
SET @SQLCUMLE11=' '
EXEC (@SQLCUMLE1+@TARIHFIRMASUBE+@SQLCUMLE2+@TARIHFIRMASUBE+@SQLCUMLE3+@TARIHFIRMASUBE+@SQLCUMLE4+@TARIHFIRMASUBE+@SQLCUMLE5+@TARIHFIRMASUBE+@SQLCUMLE6+@TARIHFIRMASUBE+@SQLCUMLE7+@TARIHFIRMASUBE+@SQLCUMLE8+@PARAMTUKETIMFIS+@SQLCUMLE9+@PARAMTUKETIMFIS+@SQLCUMLE10+@SQLCUMLE11)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_HESAPBAKIYE_FATURA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRLQ_HESAPBAKIYE_FATURA]  @TARIHFIRMASUBE NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX),
@SQLCUMLE9 NVARCHAR(MAX),
@SQLCUMLE10 NVARCHAR(MAX),
@SQLCUMLE11 NVARCHAR(MAX),
@PARAMTUKETIMFIS NVARCHAR(150)
SET @PARAMTUKETIMFIS=REPLACE(@TARIHFIRMASUBE,'FIRMAID','TUKETIMFIS.FIRMAID')
SET @PARAMTUKETIMFIS=REPLACE(@PARAMTUKETIMFIS,'SUBEID','TUKETIMFIS.SUBEID')
SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
	F.HESAPID, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI, SUM(F.BORC) AS BORC, SUM(F.ALACAK) AS ALACAK, M.DOVIZ, SUM(F.DBORC) AS DBORC,
	SUM(F.DALACAK) AS DALACAK
	 FROM (SELECT F.FIRMAID, F.SUBEID, HI.HESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              HI.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT  F.FIRMAID, F.SUBEID, F.FISHESAPID, 
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT F.FIRMAID, F.SUBEID, F.FISHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             (CASE WHEN F.KUR>0 THEN HI.ALACAK/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DALACAK,HI.ALACAK) END) AS DBORC,
			 (CASE WHEN F.KUR>0 THEN HI.BORC/NULLIF(ISNULL(F.KUR,1),0) ELSE ISNULL(HI.DBORC,HI.BORC) END) AS DALACAK,
			 ISNULL(F.DOVIZ,HI.DOVIZ) AS HDOVIZ FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.SIL,0)>=0 AND  ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4=' UNION ALL
--SERVIS FORMU
    SELECT FIRMAID,SUBEID,CARIID AS HESAPID, NETTOPLAM AS BORC, 0.00 AS ALACAK,
  NETTOPLAM AS DBORC, 0.00 AS DALACAK, ''TL'' AS DOVIZ
  FROM SERVISFORM WITH (NOLOCK)  WHERE ISNULL(FATID,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '
SET @SQLCUMLE5=' UNION ALL
--FATURA SATIS
    SELECT FIRMAID,SUBEID,FISHESAPID AS HESAPID,GTOPLAM AS BORC, 0.00 AS ALACAK, 
DTOPLAM AS DBORC, 0.00 AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND  FISTURID IN(52,53,62,63,66)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE6=' UNION ALL
--FATURA ALIS
    SELECT FIRMAID,SUBEID, FISHESAPID AS HESAPID,0.00 AS BORC, GTOPLAM AS ALACAK, 
0.00 AS DBORC, DTOPLAM AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE7=' UNION ALL
--FATURA ALIS ODEMELERI
    SELECT FIRMAID,SUBEID,FISHESAPID AS HESAPID,ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS BORC, 0.00 AS ALACAK, 
ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0) AS DBORC, 0.00 AS DALACAK,DOVIZ FROM FATURA WITH (NOLOCK) 
WHERE ABS(ISNULL(ODENENTUTAR,0)+ISNULL(ODENENTUTAR2,0))>0 AND FISDURUMID>=0 AND FISTURID IN(51,54,61,64,65,67)  AND ISNULL(FISIVAR,0)=0 AND ISNULL(SIL,0)=0 AND GTOPLAM>0 AND 1=1 '
SET @SQLCUMLE8=' UNION ALL
--TUKETIMFIS ACIK
    SELECT TUKETIMFIS.FIRMAID,DEPO.ACIKSUBEID AS SUBEID,HESAPID AS HESAPID,ISNULL(ACIK,0) AS BORC, 0.00 AS ALACAK, 
ISNULL(ACIK,0) AS DBORC, 0.00 AS DALACAK,DKODU AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.CDEPOID=DEPO.DEPOID 
WHERE ABS(ACIK)>0 AND ISLEM=''SATIS'' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0  AND 1=1 '
SET @SQLCUMLE9=' UNION ALL
SELECT TUKETIMFIS.FIRMAID,DEPO.ACIKSUBEID AS SUBEID,HESAPID AS HESAPID,0.00 AS BORC, ISNULL(ACIK,0) AS ALACAK, 
0.00 AS DBORC, ISNULL(ACIK,0) AS DALACAK,DKODU AS DOVIZ FROM TUKETIMFIS WITH (NOLOCK) INNER JOIN DEPO WITH (NOLOCK) ON TUKETIMFIS.GDEPOID=DEPO.DEPOID 
WHERE ABS(ACIK)>0 AND ISLEM=''ALIS'' AND ISNULL(MUHFC,0)=0 AND ISNULL(MUHFISID,0)=0 AND ISNULL(TUKETIMFIS.SIL,0)=0  AND 1=1 '
SET @SQLCUMLE10=' ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 WHERE 1=1 GROUP BY  F.HESAPID,M.KODU,M.ACIKLAMA,M.DOVIZ'
SET @SQLCUMLE11=' '
EXEC (@SQLCUMLE1+@TARIHFIRMASUBE+@SQLCUMLE2+@TARIHFIRMASUBE+@SQLCUMLE3+@TARIHFIRMASUBE+@SQLCUMLE4+@TARIHFIRMASUBE+@SQLCUMLE5+@TARIHFIRMASUBE+@SQLCUMLE6+@TARIHFIRMASUBE+@SQLCUMLE7+@TARIHFIRMASUBE+@SQLCUMLE8+@PARAMTUKETIMFIS+@SQLCUMLE9+@PARAMTUKETIMFIS+@SQLCUMLE10+@SQLCUMLE11)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_HESAPDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO







CREATE PROCEDURE [dbo].[PRLQ_HESAPDETAY]  @LIMIT NVARCHAR(150), 
@PARAMETREHESAPID NVARCHAR(150),
@PARAMETREFISHESAPID NVARCHAR(150),@PARAMETREHIHESAPID NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX)

SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN ''B'' ELSE ''A'' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO,F.BORC,F.ALACAK,KUR,
	F.DOVIZ AS DOVIZ,
	F.DBORC AS DBORC,
	F.DALACAK AS DALACAK,
	CASE WHEN ISNULL(F.ACIKLAMA,'''')='''' THEN ISNULL(F.BELGENO,'''')+'' Nolu ''+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'''')+'' ''+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.BELGETURU,F.BELGETARIH, 
	MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'''')='''' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+'' ''+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+'' ''+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,
	M.DOVIZ AS HESAPDOVIZ,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	F.FISHESAPID,F.FISTURID,FT.FISTURADI, F.FISDURUMID, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, 
	F.ADD_DATE, F.ADD_USERID,F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'''') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'''') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'''') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,''ODENMEYEN'' AS ODENMEYENALANI,''MUH_HESAPISL'' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID,  F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , 
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'''' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,''ODENMEYEN'' AS ODENMEYENALANI,''MUH_FIS'' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,   F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(F.KUR,0)<>0 THEN ROUND(HI.ALACAK/HI.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(F.KUR,0)<>0 THEN ROUND(HI.BORC/HI.KUR,2) ELSE 0 END AS DALACAK,
			 HI.DOVIZ AS HDOVIZ,HI.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID, ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'''') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, ''ODENMEYEN2'' AS ODENMEYENALANI,''MUH_HESAPISL'' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4='  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1 '
SET @SQLCUMLE5=' ORDER BY TARIH'
EXEC (@SQLCUMLE1+@PARAMETREHIHESAPID+@SQLCUMLE2+@PARAMETREFISHESAPID+@SQLCUMLE3+@PARAMETREFISHESAPID+@SQLCUMLE4+@PARAMETREHESAPID+@SQLCUMLE5)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_HESAPISL2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRLQ_HESAPISL2]  @LIMIT NVARCHAR(150), 
@PARAMETREHESAPID NVARCHAR(150),
@PARAMETREFISHESAPID NVARCHAR(150),@PARAMETREHIHESAPID NVARCHAR(150)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX)

SET @SQLCUMLE1='SELECT  TOP 100 PERCENT
 	CAST(CAST(F.TARIH AS FLOAT) AS VARCHAR(15)) + ''_'' + CAST(F.FISID AS nvarchar(20)) +
	''_'' + ISNULL(MK.KODU,'''') + ''_'' + CAST(ISLEMID AS NVARCHAR(30)) SIRANO,
	F.FISID,F.ALTCARIID,AC.UNVANI AS ALTCARIUNVANI, F.ISLEMID,CASE WHEN BORC>0 THEN ''B'' ELSE ''A'' END AS BATIPI,
	  F.TARIH,  ISNULL(F.VADE,F.TARIH) AS VADE, YEAR(F.TARIH) AS YIL, MONTH(F.TARIH) AS AY,
	DATEPART(WEEK, F.TARIH)  AS HAFTA, CAST(DATEPART(quarter  , TARIH) AS NVARCHAR(1))+''.Çeyrek'' AS CEYREKADI,
	dbo.FN_AYISMI(MONTH(TARIH)) AS AYADI, CAST(DATEPART(week  , TARIH) AS NVARCHAR(2))+''.Hft'' AS HAFTAADI,
    F.FISNO, F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA,F.BELGENO, ISNULL(F.TFISID,F.FISID) AS TFISID,
	ISNULL(F.TFISNO,F.FISNO) AS TFISNO,ISNULL(F.TFISTARIH,F.TARIH) AS TFISTARIH,
	ISNULL(F.TFISACIKLAMA,F.ACIKLAMA) AS TFISACIKLAMA, F.BORC,F.ALACAK,KUR,
	ISNULL(F.BORC,0)-ISNULL(F.ALACAK,0) AS BORCBAKIYE,
	CASE WHEN ISNULL(M.DOVIZ,''TL'')=''''  THEN ''TL'' ELSE M.DOVIZ END AS DOVIZ,
	CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL''  THEN F.BORC ELSE F.DBORC END AS DBORC,
	CASE WHEN ISNULL(M.DOVIZ,''TL'')=''TL''  THEN F.ALACAK ELSE F.DALACAK END AS DALACAK,
	ISNULL(F.DBORC,0)-ISNULL(F.DALACAK,0) AS DBORCBAKIYE,
	CASE WHEN ISNULL(F.ACIKLAMA,'''')='''' THEN ISNULL(F.BELGENO,'''')+'' Nolu ''+ISNULL(ISNULL(AC.UNVANI,MK.ACIKLAMA),'''')+'' ''+FT.FISTURADI ELSE F.ACIKLAMA END ACIKLAMA,
	F.BELGEACIKLAMA,F.MERKEZIFC,  F.OZELKOD1, F.OZELKOD2, F.OZELKOD3, F.SSIRA,F.BELGETURU,BTURU.BELGETURUADI,BTURU.GIBBELGETURUADI,F.BELGETARIH, 
	KARSIHESAPID,MK.KODU AS KARSIHESAPKODU,MK.ACIKLAMA AS KARSIHESAPADI, F.HESAPID,M.KODU AS HESAPKODU,
	CASE WHEN ISNULL(M.MERKEZKODU,'''')='''' THEN M.KODU ELSE M.MERKEZKODU END AS MERKEZHESAPKODU, M.KODU AS KODU,
	M.ACIKLAMA AS HESAPADI,M.ACIKLAMA2 AS HESAPADI2,M.KODU+'' ''+M.ACIKLAMA AS HESAPKODUveADI,
	AC.KODU AS ALTCARIKODU,AC.KODU+'' ''+AC.UNVANI AS ALTCARIKODUveUNVANI, M.CALISMASEKLI,LEN(M.KODU) AS KODUZUNLUK,
	M.DOVIZ AS HESAPDOVIZ,M.SEVIYE AS HESAPSEVIYE,M.UCHESAP,M.VADEGUN,DATEADD(DAY,ISNULL(M.VADEGUN,0),F.TARIH) AS OPSTARIH,
	ISNULL(M.GRUPFIRMAHESAPID,M.HESAPID) AS GRUPFIRMAHESAPID,ISNULL(MGF.KODU+'' ''+MGF.ACIKLAMA,M.KODU+'' ''+M.ACIKLAMA)  AS GRUPFIRMAHESAPKODUveADI,
	CASE WHEN CHARINDEX(''.'',M.KODU)>0 THEN SUBSTRING(M.KODU,1,CHARINDEX(''.'',M.KODU)-1) ELSE M.KODU END AS ANAHESAPKODU,
	REVERSE(SUBSTRING(REVERSE(M.KODU),CHARINDEX(''.'',REVERSE(M.KODU))+1,100)) USTHESAPKODU,  F.FISHESAPID,
	M.HESAPTIPID,HT.HESAPTIPADI , M.HESAPGRUPID1,	M.HESAPGRUPID2,M.OZELKOD1 AS HESAPOZELKOD1,
	M.OZELKOD2 AS HESAPOZELKOD2, F.FISTURID,FT.FISTURADI, F.FISDURUMID,FD.FISDURUM, F.SUBEID, dbo.SUBELER.SUBEKODU,
	dbo.SUBELER.SUBEADI, F.YETKIID, ISLEMGRUPID1,	ISLEMGRUPID2,ISLEMGRUPID3,F.MASMERID,  MG4.GRUPKODU AS MASMERKODU,    MG4.GRUPADI AS MASMERADI,
	MG4.ANAGRUBU AS MASMERGRUBU, PROJEID, 
	F.ADD_DATE, F.ADD_USERID,  F.EDIT_DATE,F.EDIT_USERID,
	F.DEL_DATE ,F.DEL_USERID,
	F.KDV,F.BABSTUTAR,ISNULL(F.ENTKAYNAK,'''') AS ENTKAYNAK,
	F.ENTKAYITID,SILINDI,  F.TEVKIFATKODU,F.TEVKIFATYUZDE,F.TVKKDVPAY,F.TVKKDVPAYDA,F.CEKID ,F.ODENMEYEN,
	F.ODENMEYENALANI,F.TABLOADI,F.TABLOKAYITID, F.YEVSATIRSIRANO,F.FISTOPLAM,ODEMEYONTEMI
 FROM (SELECT    F.FIRMAID, F.FISID, HI.ALTCARIID AS ALTCARIID, HI.HESAPID,F.FISHESAPID AS KARSIHESAPID, HI.BORC,  HI.ALACAK,HI.DBORC,  HI.DALACAK,
              ISNULL(HI.DOVIZ,F.DOVIZ) AS DOVIZ, HI.KUR, ISNULL(HI.BELGENO,'''') AS BELGENO,HI.BELGEACIKLAMA, F.TARIH, F.FISNO,
			  F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			  F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			  F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			  ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			  ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			  ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			  ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			  HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'''') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
              HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,HI.BELGETURU,HI.BELGETARIH  ,
              HI.ODENMEYEN,''ODENMEYEN'' AS ODENMEYENALANI,''MUH_HESAPISL'' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID,ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
              F.TOPLAM FISTOPLAM,HI.ODEMEYONTEMI,HI.YEVSATIRSIRANO    FROM       MUH_FIS F WITH (NOLOCK) INNER JOIN
  MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.PASIF,0)=0 AND (F.FISDURUMID>=0) AND (ISNULL(HI.SILINDI,0)=0) AND 1=1 '
SET @SQLCUMLE2=' UNION ALL
--Fis Baslik Tek Satir
   SELECT   F.FIRMAID,  F.FISID,F.ALTCARIID, F.FISHESAPID, NULL AS KARSIHESAPID,
              CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.TOPLAM   ELSE 0 END AS BORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.TOPLAM   ELSE 0 END AS ALACAK,
               CASE WHEN FT.ALANTIPI=''BORC''   THEN  F.DTOPLAM  ELSE 0 END AS DBORC,
               CASE WHEN FT.ALANTIPI=''ALACAK'' THEN  F.DTOPLAM  ELSE 0 END AS DALACAK,
               F.DOVIZ AS DOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA, F.TARIH, F.FISNO,
			   F.YEVMNO,F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			   F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID, F.FISHESAPID,
			   F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			   ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			   ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			   ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			   ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			   NULL ISLEMID,NULL KDV,NULL BABSTUTAR,'''' AS ENTKAYNAK,NULL ENTKAYITID,0 AS SILINDI,
               NULL TEVKIFATKODU,NULL TEVKIFATYUZDE,NULL TVKKDVPAY,NULL TVKKDVPAYDA, NULL CEKID,NULL SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH ,
               F.ODENMEYEN AS ODENMEYEN,''ODENMEYEN'' AS ODENMEYENALANI,''MUH_FIS'' AS TABLOADI,F.FISID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA,  
               F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO   FROM       MUH_FIS F WITH (NOLOCK)
 LEFT OUTER JOIN QMUH_FISTUR FT WITH (NOLOCK) ON  F.FISTURID =  FT.FISTURID
 FULL JOIN MUH_HESAPISL HI WITH (NOLOCK) ON HI.ISLEMID=-1
 WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=0 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0 AND (F.FISHESAPID IS NOT NULL) AND 1=1 ' 

SET @SQLCUMLE3=' UNION ALL
--Fis Baslik Detayli
  SELECT  F.FIRMAID,   F.FISID,F.ALTCARIID, F.FISHESAPID, HI.HESAPID AS KARSIHESAPID, HI.ALACAK AS BORC,  HI.BORC AS ALACAK,
             CASE WHEN ISNULL(F.KUR,0)<>0 THEN ROUND(HI.ALACAK/F.KUR,2) ELSE 0 END AS DBORC,
			 CASE WHEN ISNULL(F.KUR,0)<>0 THEN ROUND(HI.BORC/F.KUR,2) ELSE 0 END AS DALACAK,
			 F.DOVIZ AS HDOVIZ,F.KUR,F.BELGENO,F.BELGEACIKLAMA,   F.TARIH, F.FISNO, F.YEVMNO,
			 F.YEVMTARIH,F.YEVMACIKLAMA, F.TFISID,F.TFISNO,F.TFISTARIH,TFISACIKLAMA, F.ADD_DATE, F.ADD_USERID,
			 F.EDIT_DATE,F.EDIT_USERID,  F.DEL_DATE ,F.DEL_USERID, F.MERKEZIFC, F.FISTURID, F.FISDURUMID, F.YETKIID,
			 F.FISHESAPID, F.SUBEID , ISNULL(HI.OZELKOD1,F.OZELKOD1) AS OZELKOD1,  ISNULL(HI.OZELKOD2,F.OZELKOD2) AS OZELKOD2,
			 ISNULL(HI.OZELKOD3,F.OZELKOD3) AS OZELKOD3,  ISNULL(HI.ISLEMGRUPID1,F.ISLEMGRUPID1) AS ISLEMGRUPID1,
			 ISNULL(HI.ISLEMGRUPID2,F.ISLEMGRUPID2) AS ISLEMGRUPID2,  ISNULL(HI.ISLEMGRUPID3,F.ISLEMGRUPID3) AS ISLEMGRUPID3,
			 ISNULL(HI.MASMERID,F.MASMERID)         AS MASMERID,      ISNULL(HI.PROJEID,F.PROJEID)           AS PROJEID,
			 ISNULL(ISNULL(HI.VADE,F.VADE),F.TARIH) AS VADE,          ISNULL(HI.ACIKLAMA,F.ACIKLAMA)         AS ACIKLAMA      ,
			 HI.ISLEMID,HI.KDV,HI.BABSTUTAR,ISNULL(HI.ENTKAYNAK,'''') AS ENTKAYNAK,HI.ENTKAYITID,SILINDI,
      HI.TEVKIFATKODU,HI.TEVKIFATYUZDE,HI.TVKKDVPAY,HI.TVKKDVPAYDA, HI.CEKID,SSIRA,F.BELGETURU AS BELGETURU ,F.TARIH BELGETARIH  ,
			 HI.ODENMEYEN2 AS ODENMEYEN, ''ODENMEYEN2'' AS ODENMEYENALANI,''MUH_HESAPISL'' AS TABLOADI,HI.ISLEMID AS TABLOKAYITID, ISNULL (F.ACIKLAMA,HI.ACIKLAMA)   AS  FISACIKLAMA ,  
      F.TOPLAM FISTOPLAM,F.ODEMEYONTEMI,F.YEVSATIRSIRANO    FROM        MUH_FIS F WITH (NOLOCK)
  INNER JOIN MUH_HESAPISL HI WITH (NOLOCK) ON  F.FISID =  HI.FISID
  WHERE ISNULL(F.FISTURID,1)>=0 AND ISNULL(F.DETAYLIENTEGRE,0)=1 AND ISNULL(F.PASIF,0)=0 AND F.FISDURUMID>=0
  AND F.FISHESAPID IS NOT NULL AND ISNULL(HI.SILINDI,0)=0 AND 1=1 '
SET @SQLCUMLE4='  ) AS F 
 INNER JOIN  dbo.MUH_HESAP M            WITH (NOLOCK)   ON F.HESAPID           = M.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP MK       WITH (NOLOCK)   ON F.KARSIHESAPID      = MK.HESAPID
 LEFT OUTER JOIN dbo.MUH_HESAP_ALTCARI AC WITH (NOLOCK) ON F.ALTCARIID       = AC.ALTCARIID
 LEFT OUTER JOIN dbo.MUH_HESAP MGF      WITH (NOLOCK)   ON M.GRUPFIRMAHESAPID  = MGF.HESAPID
 LEFT OUTER JOIN dbo.QMUH_FISTUR FT     WITH (NOLOCK)   ON F.FISTURID          = FT.FISTURID
 LEFT OUTER JOIN dbo.QMUH_FISDURUM FD   WITH (NOLOCK)   ON F.FISDURUMID        = FD.FISDURUMID
 LEFT OUTER JOIN dbo.QMUH_HESAPTIP HT   WITH (NOLOCK)   ON M.HESAPTIPID        = HT.HESAPTIPID
 LEFT OUTER JOIN dbo.QMUH_BELGETURU BTURU ON  F.BELGETURU=BTURU.BELGETURUID  
 LEFT OUTER JOIN dbo.SUBELER            WITH (NOLOCK)   ON F.SUBEID            = dbo.SUBELER.SUBEID
 LEFT OUTER JOIN dbo.MUH_GRUP MG4       WITH (NOLOCK)   ON F.MASMERID          = MG4.GRUPID
 WHERE 1=1 '
SET @SQLCUMLE5=' '
EXEC (@SQLCUMLE1+@PARAMETREHIHESAPID+@SQLCUMLE2+@PARAMETREFISHESAPID+@SQLCUMLE3+@PARAMETREFISHESAPID+@SQLCUMLE4+@PARAMETREHESAPID+@SQLCUMLE5)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_STOKDETAY]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRLQ_STOKDETAY]  @PARAMETRE NVARCHAR(350), @PARAMETRE2 NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX)


SET @SQLCUMLE1='SELECT 1 AS FTIPI,FI.FATISLID AS SATIRKNO,F.FATID,F.TARIH,F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,F.ADD_DATE AS ISLEMTARIH,1 AS SAYIMSIRA,
''FATURA'' AS FISTIPI,ISNULL(FI.RGDEPOID,F.DEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,
CASE WHEN FISTURID IN (51,54,61) THEN ''ALIS'' ELSE ''SATIS'' END AS ISLEM,
FI.STOKID,SG.GRUPKODU,SG.GRUPADI,FI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
F.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) AS GCADET,
FI.FADET,FI.FBIRIM,FI.FBFIYAT,FI.BFIYAT * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,
		  ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)   
           / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))   
          / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
FI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,BMALIYET,FBMALIYET,BKATSAYI,
((CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * STOK.SALISFIYAT) AS TOPLAMMALIYET,
SATIRIND,SATIRIND2,SATIRIND3,SATIRIND4,F.FATNO,CARI.KODU AS CARIKODU,CARI.ACIKLAMA AS CARIUNVANI,F.TOPLAM,FI.KDV AS KDVORAN,STOK.ALISKDV,
F.ALTCARIID,ALTCARI.UNVANI AS ALTCARIUNVAN,
CAST(NULL AS INTEGER) KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,F.SUBEID,SUBELER.SUBEKODU,SUBELER.SUBEADI
    FROM  FU_FATISL FI WITH (NOLOCK) INNER JOIN   
          FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN   
          MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN   
            MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN   
          STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN            
          DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN            
          SGRUP SG    WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN          
          SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID    
     WHERE ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0   
	 AND 1=1  '

SET @SQLCUMLE2=' UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GercekTarih AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,
''DEPOFIS'' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU,KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI
FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN    
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID    
    WHERE ISNULL(DF.SIL,0)=0 AND (DF.GDEPOID) > 0  AND 1=1  '   

SET @SQLCUMLE3=' UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GercekTarih AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,
''DEPOFIS'' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,''TUKETIM'' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,NULL AS CARIKODU,
NULL AS CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
NULL AS KDEPOID,NULL AS KDEPOKODU,NULL AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS DF WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN    
          SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID  
    WHERE  ISNULL(DF.SIL,0)=0 AND    (DF.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 AND 1=1 '

SET @SQLCUMLE4=' UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GercekTarih AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,
''DEPOFIS'' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,''TUKETIM'' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
KDEPO.KODU CARIKODU, KDEPO.DEPOADI CARIUNVANI,DF.TTUTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM  STOK  WITH (NOLOCK) INNER JOIN   
          DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
          DEPOFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN      
          SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN   
          DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
          DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
          SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID  
   WHERE  ISNULL(DF.SIL,0)=0 AND   DF.CDEPOID > 0  AND 1=1   '

SET @SQLCUMLE5=' UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GercekTarih AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,
''TUKETIMFIS'' AS FISTIPI,ISNULL(RGDEPOID,DF.CDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,DF.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND  DF.CDEPOID > 0  AND 1=1  ' 

SET @SQLCUMLE6=' UNION ALL
SELECT 1 AS FTIPI,DF.DEPOFISID AS SATIRKNO,DF.DEPOFISID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.GercekTarih AS ISLEMTARIH,
CASE WHEN DF.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,
''TUKETIMFIS'' AS FISTIPI,ISNULL(RGDEPOID,DF.GDEPOID) AS DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,DF.ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,DFI.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
DF.ACIKLAMA,DFI.MIKTAR * - 1 AS GCADET,
DFI.FMIKTAR AS FADET,DFI.FBIRIM,DFI.FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BMALIYET,DFI.FBMALIYET,DFI.BKATSAYI,
DFI.FMIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.ENO AS FATNO,
H1.KODU CARIKODU, H1.ACIKLAMA AS CARIUNVANI,(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,
KDEPO.DEPOID AS KDEPOID,KDEPO.KODU AS KDEPOKODU, KDEPO.DEPOADI AS KDEPOADI,STOK.TURU,
DF.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN   
         TUKETIMFIS    DF  WITH (NOLOCK) ON DFI.DEPOFISID = DF.DEPOFISID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN   
		 DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN    
         DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,DF.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN   
         SUBELER  WITH (NOLOCK) ON DF.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN   
         DEPART  WITH (NOLOCK) ON DEPART.KODU = DF.SDEPART
		 LEFT JOIN MUH_HESAP AS H1 ON DF.HESAPID=H1.HESAPID
    WHERE ISNULL(DF.SIL,0)=0 AND  DF.GDEPOID > 0 AND 1=1  ' 
--SERVİS FORMU
SET @SQLCUMLE8=' UNION ALL
SELECT 1 AS FTIPI,DF.ARACKABULID AS SATIRKNO,DF.ARACKABULID AS FATID,DF.TARIH,DF.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE,DF.TARIH AS ISLEMTARIH,
3 SAYIMSIRA,''SATIS'' AS FISTIPI,DF.DEPOID,DEPO.KODU AS DEPOKODU,DEPO.DEPOADI,''SATIS'' AS ISLEM,
DFI.STOKID,SG.GRUPKODU,SG.GRUPADI,STOK.BARKOD AS BARKOD,STOK.KODU AS STOKKODU,STOK.ADI AS STOKADI,STOK.BIRIM,
''Servis Formu'' as ACIKLAMA, DFI.MIKTAR * - 1 AS GCADET,
DFI.MIKTAR AS FADET,STOK.BIRIM AS FBIRIM,DFI.BFIYAT AS FBFIYAT,DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT,STOK.SALISFIYAT AS BIRIMMALIYET,DFI.BFIYAT AS BMALIYET,DFI.BFIYAT AS FBMALIYET, 1 AS BKATSAYI,
DFI.MIKTAR * STOK.SALISFIYAT AS TOPLAMMALIYET,
0.00 AS SATIRIND,0.00 AS SATIRIND2,0.00 AS SATIRIND3,0.00 AS SATIRIND4,DF.FORMNO AS FATNO,
CAST(DF.CARIID AS NVARCHAR(10)) AS CARIKODU, DF.UNVANI AS CARIUNVANI,DFI.BFIYAT * DFI.MIKTAR AS TOPLAM, STOK.ALISKDV AS KDVORAN,STOK.ALISKDV,
NULL AS ALTCARIID,NULL AS ALTCARIUNVAN,NULL AS KDEPOID, NULL AS KDEPOKODU, NULL AS KDEPOADI,STOK.TURU,
DF.SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI

    FROM STOK  WITH (NOLOCK) INNER JOIN   
         ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN   
         ARACKABUL    DF  WITH (NOLOCK) ON DFI.ARACKABULID   = DF.ARACKABULID LEFT JOIN    
         SGRUP SG  WITH (NOLOCK) ON STOK.GRUP= SG.GRUPKODU LEFT JOIN 
		 SUBELER WITH (NOLOCK) ON DF.SUBEID=SUBELER.SUBEID LEFT JOIN
		 DEPO WITH (NOLOCK) ON DF.DEPOID=DEPO.DEPOID
    WHERE  ISNULL(DF.SIL,0)=0  AND ISNULL(FATID,0)=0 AND 1=1   '    
EXEC (@SQLCUMLE1+@PARAMETRE2+@SQLCUMLE2+@PARAMETRE+@SQLCUMLE3+@PARAMETRE+@SQLCUMLE4+@PARAMETRE+@SQLCUMLE5+@PARAMETRE+@SQLCUMLE6+@PARAMETRE+@SQLCUMLE7+@PARAMETRE+@SQLCUMLE8+@PARAMETRE+'  ORDER BY TARIH')
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_STOKDETAY2]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRLQ_STOKDETAY2]  @PARAMETRE NVARCHAR(350), @PARAMETRE2 NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX)


SET @SQLCUMLE1='SELECT 0 as SIL, 1 AS FTIPI, F.FATID,ISNULL(F.IRSALIYETARIHI,F.TARIH) AS TARIH, 
YEAR(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEYIL, MONTH(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEAY, 
F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.ADD_DATE,F.TARIH) AS ISLEMTARIH, 1 SAYIMSIRA,''FATURA'' FISTIPI, ISNULL(FI.RGDEPOID,F.DEPOID) DEPOID, DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
CASE WHEN FISTURID IN (51,54,61) THEN ''ALIS'' ELSE ''SATIS'' END AS ISLEM ,       F.ACIKLAMA FACIKLAMA, FI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, FI.ACIKLAMA,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) GCADET,
FI.BFIYAT * (100 - FI.SATIRIND)
ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)
BFIYAT,ISNULL(DBFIYAT,BFIYAT) AS DBFIYAT,FI.SATIRIND, FI.SATIRIND2, F.FATNO, CARI.KODU, CARI.ACIKLAMA AS CARIUNVANI,
FI.BFIYAT * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
STOK.SALISFIYAT, FI.BARKOD BARKOD, F.VADE, 
CAST(NULL AS INTEGER) KDEPOID, F.SUBEID SUBEID, SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,FI.KDV KDV,
ISNULL(F.DOVIZ,''TL'') AS DOVIZ,CARI.HESAPID,NULL KDEPOKODU,NULL KDEPOADI,CARI.HESAPID AS CARIID ,STOK.TURU TURU,SAYIMBIRIMI,FI.FBIRIM FBIRIM, FI.FADET ,
FI.FBFIYAT FBFIYAT, ISNULL(FI.DFBFIYAT,FI.FBFIYAT) AS DFBFIYAT,
FI.TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,F.OZELKOD1,F.OZELKOD2,F.OZELKOD3,
CASE
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, CASE WHEN FISTURID IN (52,62) THEN ''SATIS'' ELSE ''ALIS'' END SDEPART, 
CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET, BMALIYET,FBMALIYET,BKATSAYI,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.FISDURUMID AS DURUM, F.MUHFC, STOK.SFIYAT1, CONVERT(NVARCHAR(5),F.KTARIH,108) SAAT,NULL STOK.ALISKDV,
ALTCARI.UNVANI AS ALTCARIUNVANI ,F.ALTCARIID,F.EVRAKSIRANO
FROM  FU_FATISL FI WITH (NOLOCK) INNER JOIN
FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN
MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN
STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN
DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN
SGRUP SG    WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
WHERE (ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)>=-1
AND ( ISNULL(F.FISDURUMID,0)=-1 OR  ( (ISNULL(F.FISDURUMID,0)<>-1) AND ( ISNULL(FI.IRSISLID,0) =0) ) ))  and 1=1  '

SET @SQLCUMLE2=' UNION ALL
SELECT 0 as SIL, ISNULL(F.FTIPI,1) AS FTIPI, F.DEPOFISID AS FATID, F.TARIH AS TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, 
ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH,  3 SAYIMSIRA,  ''TUKETIMFIS'' FISTIPI, ISNULL(RCDEPOID,CDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI,
STOK.KODU STOKKODU,STOK.ADI, DFI.ACIKLAMA, DFI.MIKTAR * - 1 GCADET,
(DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) AS NFIYAT, DFI.DFIYATNET AS DNFIYAT,
DFI.BFIYAT, DFI.DFIYATNET AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,CARI.KODU, CARI.ACIKLAMA AS CARIUNVANI,
(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 TOPLAM, DFI.DFIYATNET * DFI.FMIKTAR * - 1 DTOPLAM, 
 STOK.SALISFIYAT, DFI.BARKOD BARKOD, NULL VADE, F.GDEPOID KDEPOID, F.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ISNULL(DFI.DTURU,F.DKODU) AS DOVIZ,F.HESAPID AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,F.HESAPID as CARIID, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.SFIYAT FBFIYAT, DFI.DFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE  WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, F.SDEPART,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC, STOK.SFIYAT1,SAAT,STOK.ALISKDV,NULL AS FATISLID,ALTCARI.UNVANI AS ALTCARIUNVANI,F.ALTCARIID,ENO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
TUKETIMFIS    F  WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
MUH_HESAP CARI  WITH (NOLOCK) ON F.HESAPID = CARI.HESAPID  LEFT OUTER JOIN
MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID
WHERE ISNULL(F.SIL,0)=0 AND  F.CDEPOID > 0  AND 1=1  '   

SET @SQLCUMLE3=' UNION ALL
SELECT  0 as SIL, 1 AS FTIPI, F.DEPOFISID AS FATID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, 
3 SAYIMSIRA,  ''DEPOFIS'' FISTIPI, ISNULL(RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, ''TUKETIM'' AS ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI,
DFI.ACIKLAMA,(-1) * DFI.MIKTAR GCADET, DFI.BFIYAT NFIYAT, DFI.BFIYAT DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,NULL KODU, NULL  CARIUNVANI,
DFI.BFIYAT * (-1) * DFI.MIKTAR TOPLAM, DFI.BFIYAT * (-1) * DFI.MIKTAR DTOPLAM, 
STOK.SALISFIYAT, DFI.BARKOD BARKOD,
NULL VADE, NULL AS KDEPOID,
F.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ''TL'' AS DOVIZ,
NULL AS HESAPID,
NULL KDEPOKODU,NULL KDEPOADI,NULL AS CARIID, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, '''' AS SDEPART,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
(-1) * DFI.MIKTAR *  CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.DURUM, F.MUHFC, STOK.SFIYAT1 , NULL SAAT  ,STOK.ALISKDV,     
NULL AS FATISLID,NULL AS ALTCARIUNVANI,NULL AS ALTCARIID,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS F WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.GSUBEID = SUBELER.SUBEID
WHERE  ISNULL(F.SIL,0)=0 AND    (F.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 AND 1=1 '

SET @SQLCUMLE4=' UNION ALL
SELECT  0 as SIL, 1 AS FTIPI, F.DEPOFISID AS FATID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, 
CASE WHEN F.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA, ''DEPOFIS'' FISTIPI, ISNULL(RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI,
DFI.ACIKLAMA, DFI.MIKTAR GCADET, DFI.BFIYAT NFIYAT, DFI.BFIYAT AS DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI,
DFI.BFIYAT * DFI.MIKTAR TOPLAM, DFI.BFIYAT * DFI.MIKTAR DTOPLAM, STOK.SALISFIYAT, DFI.BARKOD BARKOD,
NULL VADE, CDEPOID KDEPOID,
F.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ''TL'' AS DOVIZ,NULL AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL AS CARIID,  STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, '''' SDEPART, 
CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,
 DFI.BMALIYET,FBMALIYET,BKATSAYI,DFI.MIKTAR *  CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.DURUM, F.MUHFC, STOK.SFIYAT1 , NULL SAAT,STOK.ALISKDV,  NULL AS ALTCARIUNVANI,NULL AS ALTCARIID,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS F WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.GSUBEID = SUBELER.SUBEID
WHERE ISNULL(F.SIL,0)=0 AND     (((F.GDEPOID) > 0))  AND 1=1   '

SET @SQLCUMLE5=' UNION ALL
SELECT  0 as SIL, 1 AS FTIPI, F.DEPOFISID AS FATID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, 
CASE WHEN F.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA, ''DEPOFIS'' FISTIPI, ISNULL(RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI,
DFI.ACIKLAMA, DFI.MIKTAR GCADET, DFI.BFIYAT NFIYAT, DFI.BFIYAT AS DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI,
DFI.BFIYAT * DFI.MIKTAR TOPLAM, DFI.BFIYAT * DFI.MIKTAR DTOPLAM, STOK.SALISFIYAT, DFI.BARKOD BARKOD,
NULL VADE, CDEPOID KDEPOID,
F.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ''TL'' AS DOVIZ,NULL AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL AS CARIID,  STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, '''' SDEPART, 
CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,
 DFI.BMALIYET,FBMALIYET,BKATSAYI,DFI.MIKTAR *  CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.DURUM, F.MUHFC, STOK.SFIYAT1 , NULL SAAT,STOK.ALISKDV,  NULL AS ALTCARIUNVANI,NULL AS ALTCARIID,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS F WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.GSUBEID = SUBELER.SUBEID
WHERE ISNULL(F.SIL,0)=0 AND     (((F.CDEPOID) > 0))  AND 1=1  ' 

SET @SQLCUMLE6=' UNION ALL
SELECT 0 as SIL, ISNULL(F.FTIPI,1) AS FTIPI, F.DEPOFISID AS FATID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, 3 SAYIMSIRA,  
''TUKETIMFIS'' FISTIPI, ISNULL(DFI.RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, DFI.ACIKLAMA,
CASE WHEN ISNULL(TUKETILEN,0)=0 THEN DFI.MIKTAR ELSE -1*DFI.MIKTAR END  GCADET,  DFI.NETFIYAT AS NFIYAT, DFI.DFIYATNET AS DNFIYAT,
DFI.BFIYAT, DFI.DFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO, KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI,
DFI.NETFIYAT * DFI.FMIKTAR  TOPLAM, DFI.DFIYATNET * DFI.FMIKTAR  DTOPLAM, STOK.SALISFIYAT, DFI.BARKOD BARKOD, NULL VADE,  ISNULL(RCDEPOID,CDEPOID)  KDEPOID, F.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ISNULL(DFI.DTURU,F.DKODU) AS DOVIZ,F.HESAPID AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL AS CARIID, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.SFIYAT FBFIYAT, DFI.DFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1  END ISLEMKATSAYISI, '''' SDEPART, 
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI
ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC, STOK.SFIYAT1,NULL SAAT,STOK.ALISKDV ,NULL AS ALTCARIUNVANI,NULL AS ALTCARIID,ENO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
TUKETIMFIS    F  WITH (NOLOCK) ON DFI.DEPOFISID   = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP         = SG.GRUPKODU LEFT JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.CSUBEID = SUBELER.SUBEID
WHERE  ISNULL(F.SIL,0)=0 AND  F.GDEPOID > 0 AND 1=1  ' 
--SERVİS FORMU
SET @SQLCUMLE8=' UNION ALL
SELECT 0 as SIL, 1 AS FTIPI, F.ARACKABULID,ISNULL(F.TESLIMTARIH,F.TARIH) AS TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL,
MONTH(F.TARIH+SG.VADEGUN) AS VADEAY,
F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, F.TARIH AS ISLEMTARIH, 3 SAYIMSIRA,
''SATIS'' FISTIPI, 1 DEPOID, ''01'' DEPOKODU, ''ANADEPO'' AS DEPOADI, CAST(0 as bit) AS ANADEPO,
''SATIS'' AS ISLEM, ''Servis Formu'' FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, ''Servis Formu'' as ACIKLAMA,
DFI.MIKTAR*-1 GCADET,  DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, F.FORMNO FATNO, ''01'' AS KODU, F.UNVANI AS CARIUNVANI,
DFI.BFIYAT * DFI.MIKTAR  AS TOPLAM, DFI.BFIYAT*MIKTAR AS DTOPLAM, STOK.SALISFIYAT, STOK.BARKOD BARKOD, NULL VADE, 1 AS KDEPOID, 1 AS SUBEID, ''01'' AS SUBEKODU, ''MERKEZ'' AS SUBEADI,
STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,NULL AS KDV, ''TL'' AS DOVIZ,F.CARIID AS HESAPID,
''01'' AS  KDEPOKODU,''ANADEPO'' AS KDEPOADI,NULL AS CARIID, STOK.TURU TURU,SAYIMBIRIMI,STOK.BIRIM FBIRIM, DFI.MIKTAR AS FADET, DFI.BFIYAT FBFIYAT, DFI.BFIYAT DFBFIYAT,
'''' TEVORAN, ''01'' AS SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
1 AS ISLEMKATSAYISI, ''01'' SDEPART,
BFIYAT AS  BIRIMMALIYET,  DFI.BFIYAT AS BMALIYET,BFIYAT AS FBMALIYET,1 AS BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC,  STOK.SFIYAT1,NULL SAAT,STOK.ALISKDV ,NULL AS ALTCARIUNVANI,NULL AS ALTCARIID,FORMNO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN
ARACKABUL    F  WITH (NOLOCK) ON DFI.ARACKABULID   = F.ARACKABULID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU
WHERE  ISNULL(F.SIL,0)=0  AND ISNULL(FATID,0)=0 AND 1=1   '    
EXEC (@SQLCUMLE1+@PARAMETRE2+@SQLCUMLE2+@PARAMETRE+@SQLCUMLE3+@PARAMETRE+@SQLCUMLE4+@PARAMETRE+@SQLCUMLE5+@PARAMETRE+@SQLCUMLE6+@PARAMETRE+@SQLCUMLE7+@PARAMETRE+@SQLCUMLE8+@PARAMETRE+'  ORDER BY TARIH')
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_STOKISL]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRLQ_STOKISL]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE1 NVARCHAR(MAX),
@SQLCUMLE2 NVARCHAR(MAX),
@SQLCUMLE3 NVARCHAR(MAX),
@SQLCUMLE4 NVARCHAR(MAX),
@SQLCUMLE5 NVARCHAR(MAX),
@SQLCUMLE6 NVARCHAR(MAX),
@SQLCUMLE7 NVARCHAR(MAX),
@SQLCUMLE8 NVARCHAR(MAX)


SET @SQLCUMLE1='SELECT 0 as SIL, 1 AS FTIPI, F.FATID,ISNULL(F.IRSALIYETARIHI,F.TARIH) AS TARIH, YEAR(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEYIL, MONTH(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.ADD_DATE,F.TARIH) AS ISLEMTARIH, NULL AS ISLEMGRUBU1,1 SAYIMSIRA,''FATURA'' FISTIPI, ISNULL(FI.RGDEPOID,F.DEPOID) DEPOID, DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
CASE WHEN FISTURID IN (51,54,61) THEN ''ALIS'' ELSE ''SATIS'' END AS ISLEM ,       F.ACIKLAMA FACIKLAMA, FI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, FI.ACIKLAMA,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) GCADET,
FI.BFIYAT * (100 - FI.SATIRIND)
ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND)
BFIYAT,ISNULL(DBFIYAT,BFIYAT) AS DBFIYAT,FI.SATIRIND, FI.SATIRIND2, F.FATNO, CARI.KODU, CARI.ACIKLAMA AS CARIUNVANI,
FI.BFIYAT * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
F.INDORAN1, F.EKORAN1, F.INDORAN2, F.EKORAN2, F.INDORAN3, F.EKORAN3, F.BAYIID, F.SATISTID, STOK.SALISFIYAT, ISNULL(BAYI.BAYI,'''') BAYI,
SATIST.SATIST, FI.BARKOD BARKOD, F.VADE, SATIST.SKOMORAN SATICIKOMORAN, STOK.SKOMORAN STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,
NULL AS FATGRUP, CAST(NULL AS INTEGER) KDEPOID, F.SUBEID SUBEID, SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
CAST(TUR AS NVARCHAR(15)) ISLEMDETAY, FI.FATISLID SATIRKNO ,STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV KDV,
F.TOPLAM FTTOPLAM, F.KDV FTKDV, F.GTOPLAM FTGTOPLAM, ISNULL(F.DTOPLAM,F.GTOPLAM) AS FTDTOPLAM, ISNULL(F.DOVIZ,''TL'') AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU,  2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU,  4)) USTGRUPKODU,
SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI,
CARI.HESAPID,NULL KDEPOKODU,NULL KDEPOADI,CARI.HESAPID AS CARIID ,STOK.TURU TURU,SAYIMBIRIMI,FI.FBIRIM FBIRIM, FI.FADET ,
FI.FBFIYAT FBFIYAT, ISNULL(FI.DFBFIYAT,FI.FBFIYAT) AS DFBFIYAT,
FI.TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,F.OZELKOD1,F.OZELKOD2,F.OZELKOD3,
CASE
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, CASE WHEN FISTURID IN (52,62) THEN ''SATIS'' ELSE ''ALIS'' END SDEPART, CAST('''' AS NVARCHAR(50)) SDEPARTADI,
CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET, BMALIYET,FBMALIYET,BKATSAYI,
(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.FISDURUMID AS DURUM, F.MUHFC, FI.SKTARIHI ,STOK.SFIYAT1, CONVERT(NVARCHAR(5),F.KTARIH,108) SAAT,NULL ISLREFID,STOK.ALISKDV,F.FATID AS FATCOUNTER,NULL  SBOLUMID,NULL SBOLUMADI,FI.FATISLID
,ALTCARI.UNVANI AS ALTCARIUNVANI ,F.ALTCARIID,F.EVRAKSIRANO
FROM  FU_FATISL FI WITH (NOLOCK) INNER JOIN
FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
MUH_HESAP CARI  WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN
MUH_HESAP_ALTCARI ALTCARI  WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.ALTCARIID  LEFT OUTER JOIN
STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID  LEFT JOIN
DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)  LEFT JOIN
SGRUP SG    WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SGRUP SG1   WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU,  1)) = SG1.GRUPKODU  LEFT OUTER JOIN
SGRUP SG2   WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU,  2)) = SG2.GRUPKODU  LEFT OUTER JOIN
SGRUP SG3   WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU, 3)) = SG3.GRUPKODU  LEFT OUTER JOIN
MUH_HESAP HSP150    WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT JOIN
MUH_HESAP HSP600    WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT JOIN
MUH_HESAP HSP740    WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT JOIN
BAYI  WITH (NOLOCK) ON F.BAYIID = BAYI.BAYIID LEFT JOIN
SATIST  WITH (NOLOCK) ON FI.SATISTID = SATIST.SATISID LEFT JOIN
SUBELER  WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
WHERE (ISNULL(F.SIL,0)=0 AND  ISNULL(FI.ISLREFID,0)=0 AND ISNULL(FI.SILINDI,0)=0 AND ISNULL(F.FISDURUMID,0)>=-1
AND ( ISNULL(F.FISDURUMID,0)=-1 OR  ( (ISNULL(F.FISDURUMID,0)<>-1) AND ( ISNULL(FI.IRSISLID,0) =0) ) ))  and 1=1 '

SET @SQLCUMLE2=' UNION ALL
SELECT 0 as SIL, ISNULL(F.FTIPI,1) AS FTIPI, F.DEPOFISID, F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, MG.GRUPADI AS ISLEMGRUBU1, 3 SAYIMSIRA,  ''TUKETIMFIS'' FISTIPI, ISNULL(RCDEPOID,CDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI,
STOK.KODU STOKKODU,STOK.ADI, DFI.ACIKLAMA, DFI.MIKTAR * - 1 GCADET,
(DFI.BFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) AS NFIYAT, DFI.DFIYATNET AS DNFIYAT,
DFI.BFIYAT, DFI.DFIYATNET AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO, H1.KODU KODU, H1.ACIKLAMA CARIUNVANI,
(DFI.FBFIYAT/100*(100-ISNULL(DFI.INDORAN,0))) * DFI.FMIKTAR * - 1 TOPLAM, DFI.DFIYATNET * DFI.FMIKTAR * - 1 DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2,
0 EKORAN2, 0 INDORAN3, 0 EKORAN3, NULL BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, DFI.BARKOD BARKOD, NULL VADE, NULL SATICIKOMORAN,
0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE, '''' FATGRUP, F.GDEPOID KDEPOID, F.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
ISLEMDETAY,DFI.DEPOFISISLID SATIRKNO, STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL,NULL, ISNULL(DFI.DTURU,F.DKODU) AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI,    SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) USTGRUPKODU, SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU,6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI, F.HESAPID AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,F.HESAPID as CARIID, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.SFIYAT FBFIYAT, DFI.DFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE  WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, ''SATIS'' AS SDEPART, DEPART.ADI SDEPARTADI,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC, SKTARIHI, STOK.SFIYAT1,SAAT,ISLREFID,STOK.ALISKDV,NULL FATCOUNTER,NULL SBOLUMID,NULL SBOLUMADI ,NULL AS FATISLID,NULL,NULL  AS ALTCARIUNVANI ,ENO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
TUKETIMFIS    F  WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU, 1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU, 2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU,3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT OUTER JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
DEPART  WITH (NOLOCK) ON DEPART.KODU = F.SDEPART
LEFT JOIN MUH_HESAP AS H1 ON F.HESAPID=H1.HESAPID
LEFT JOIN MUH_HESAP AS H2 ON F.KHESAPID=H2.HESAPID
LEFT JOIN MUH_GRUP AS MG ON F.ISLEMGRUPID1=MG.GRUPID
WHERE ISNULL(F.SIL,0)=0 AND  F.CDEPOID > 0  AND 1=1 '   

SET @SQLCUMLE3=' UNION ALL
SELECT  0 as SIL, 1 AS FTIPI, F.DEPOFISID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, NULL AS ISLEMGRUBU1, 3 SAYIMSIRA,  ''DEPOFIS'' FISTIPI, ISNULL(RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, ''TUKETIM'', F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI,
DFI.ACIKLAMA,(-1) * DFI.MIKTAR GCADET, DFI.BFIYAT NFIYAT, DFI.BFIYAT DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,NULL KODU, NULL  CARIUNVANI,
DFI.BFIYAT * (-1) * DFI.MIKTAR TOPLAM, DFI.BFIYAT * (-1) * DFI.MIKTAR DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2, 0 EKORAN2, 0 INDORAN3,
0 EKORAN3, NULL BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, DFI.BARKOD BARKOD,
NULL VADE, 0 SATICIKOMORAN, 0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE, '''' FATGRUP,  NULL AS KDEPOID,
F.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
ISLEMDETAY,DFI.DEPOFISISLID SATIRKNO, STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL, NULL, ''TL'' AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU,  2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU,  4)) USTGRUPKODU, SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI, NULL,
NULL KDEPOKODU,NULL KDEPOADI,NULL , STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, DEPART.KODU SDEPART, DEPART.ADI SDEPARTADI,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
(-1) * DFI.MIKTAR *  CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.DURUM, F.MUHFC, SKTARIHI, STOK.SFIYAT1 , NULL SAAT,ISLREFID  ,STOK.ALISKDV,     NULL FATCOUNTER,F.SBOLUMID,SBOLUM.BOLUMADI SBOLUMADI,NULL AS FATISLID,NULL,NULL AS ALTCARIUNVANI,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS F WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU,  1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU,  2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU, 3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN
SBOLUM  WITH (NOLOCK) ON SBOLUM.SBOLUMID = F.SBOLUMID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
DEPART  WITH (NOLOCK) ON DEPART.KODU = F.SDEPART
WHERE  ISNULL(F.SIL,0)=0 AND    (F.GDEPOID > 0) AND ISNULL(DFI.OTOTUKETISL,0)=1 AND 1=1 '

SET @SQLCUMLE4=' UNION ALL
SELECT  0 as SIL, 1 AS FTIPI, F.DEPOFISID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, NULL AS ISLEMGRUBU1, CASE WHEN F.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA, ''DEPOFIS'' FISTIPI, ISNULL(RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU,
DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI,
DFI.ACIKLAMA, DFI.MIKTAR GCADET, DFI.BFIYAT NFIYAT, DFI.BFIYAT AS DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI,
DFI.BFIYAT * DFI.MIKTAR TOPLAM, DFI.BFIYAT * DFI.MIKTAR DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2, 0 EKORAN2, 0 INDORAN3,
0 EKORAN3, NULL BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, DFI.BARKOD BARKOD,
NULL VADE, 0 SATICIKOMORAN, 0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE, '''' FATGRUP,  CDEPOID KDEPOID,
F.GSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
ISLEMDETAY,DFI.DEPOFISISLID SATIRKNO, STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL,NULL,''TL'' AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU,  2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU,  4)) USTGRUPKODU, SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI, NULL,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL , STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, DEPART.KODU SDEPART, DEPART.ADI SDEPARTADI,
CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,
DFI.MIKTAR *  CASE
WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
F.DURUM, F.MUHFC, SKTARIHI, STOK.SFIYAT1 , NULL SAAT,ISLREFID  ,STOK.ALISKDV,     NULL FATCOUNTER,F.SBOLUMID,SBOLUM.BOLUMADI SBOLUMADI,NULL AS FATISLID,NULL,NULL AS ALTCARIUNVANI,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS F WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU,  1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU,  2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU, 3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT OUTER JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = DEPO.DEPOID LEFT OUTER JOIN
SBOLUM  WITH (NOLOCK) ON SBOLUM.SBOLUMID = F.SBOLUMID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.GSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
DEPART  WITH (NOLOCK) ON DEPART.KODU = F.SDEPART
WHERE ISNULL(F.SIL,0)=0 AND     (((F.GDEPOID) > 0))  AND 1=1   '

SET @SQLCUMLE5=' UNION ALL
SELECT 0 as SIL, 1 AS FTIPI, F.DEPOFISID, F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) as ISLEMTARIH, NULL AS ISLEMGRUBU1, CASE WHEN F.ISLEM IN (''TUKETIM'',''TÜKETİM'') THEN 3 ELSE 2 END SAYIMSIRA,''DEPOFIS'' FISTIPI, ISNULL(DFI.RCDEPOID,F.CDEPOID) DEPOID,
DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO, F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI,
STOK.KODU STOKKODU,STOK.ADI, DFI.ACIKLAMA, DFI.MIKTAR * - 1 GCADET,  BFIYAT NFIYAT, BFIYAT DNFIYAT, DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO,
KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI, BFIYAT * DFI.MIKTAR * - 1 TOPLAM, BFIYAT * DFI.MIKTAR * - 1 DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2, 0 EKORAN2, 0 INDORAN3, 0 EKORAN3, NULL
BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, DFI.BARKOD BARKOD, NULL VADE, NULL SATICIKOMORAN, 0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE,
'''' FATGRUP, ISNULL(RGDEPOID,F.GDEPOID) KDEPOID,  F.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI, ISLEMDETAY,DFI.DEPOFISISLID SATIRKNO,
STOK.BIRIM  SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL, NULL, ''TL'' AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU,  2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI,  SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU,  4)) USTGRUPKODU,
SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI, SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI,NULL,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.FBFIYAT FBFIYAT, DFI.FBFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL  OZELKOD2,NULL OZELKOD3,
CASE WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)   WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1 END ISLEMKATSAYISI, DEPART.KODU SDEPART, DEPART.ADI SDEPARTADI,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
F.DURUM, F.MUHFC, SKTARIHI, STOK.SFIYAT1,NULL SAAT,ISLREFID ,STOK.ALISKDV ,NULL FATCOUNTER,F.SBOLUMID,SBOLUM.BOLUMADI SBOLUMADI,NULL AS FATISLID,NULL ,NULL AS ALTCARIUNVANI,ENO AS EVRAKSIRANO
FROM  STOK  WITH (NOLOCK) INNER JOIN
DEPOFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
DEPOFIS    F  WITH (NOLOCK) ON DFI.DEPOFISID = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU, 1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU, 2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU,3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT OUTER JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN
SBOLUM  WITH (NOLOCK) ON SBOLUM.SBOLUMID = F.SBOLUMID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
DEPART  WITH (NOLOCK) ON DEPART.KODU = F.SDEPART
WHERE  ISNULL(F.SIL,0)=0 AND   F.CDEPOID > 0  AND 1=1  ' 
SET @SQLCUMLE6=' UNION ALL
SELECT 0 as SIL, ISNULL(F.FTIPI,1) AS FTIPI, F.DEPOFISID,F.TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL, MONTH(F.TARIH+SG.VADEGUN) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.GercekTarih,F.TARIH) AS ISLEMTARIH, NULL AS ISLEMGRUBU1, 3 SAYIMSIRA,  ''TUKETIMFIS'' FISTIPI, ISNULL(DFI.RGDEPOID,F.GDEPOID) DEPOID, DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
F.ISLEM, F.ACIKLAMA FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, DFI.ACIKLAMA,
CASE WHEN ISNULL(TUKETILEN,0)=0 THEN DFI.MIKTAR ELSE -1*DFI.MIKTAR END  GCADET,  DFI.NETFIYAT AS NFIYAT, DFI.DFIYATNET AS DNFIYAT,
DFI.BFIYAT, DFI.DFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, ENO FATNO, KDEPO.KODU KODU, KDEPO.DEPOADI CARIUNVANI,
DFI.NETFIYAT * DFI.FMIKTAR  TOPLAM, DFI.DFIYATNET * DFI.FMIKTAR  DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2,
0 EKORAN2, 0 INDORAN3, 0 EKORAN3, NULL BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, DFI.BARKOD BARKOD, NULL VADE, NULL SATICIKOMORAN,
0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE, '''' FATGRUP, ISNULL(RCDEPOID,CDEPOID)  KDEPOID, F.CSUBEID SUBEID,SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
ISLEMDETAY,DFI.DEPOFISISLID SATIRKNO, STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL,NULL, ISNULL(DFI.DTURU,F.DKODU) AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) USTGRUPKODU, SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU,6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI, SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI, F.HESAPID AS HESAPID,
KDEPO.KODU KDEPOKODU,KDEPO.DEPOADI KDEPOADI,NULL, STOK.TURU TURU,SAYIMBIRIMI,DFI.FBIRIM FBIRIM, DFI.FMIKTAR FADET, DFI.SFIYAT FBFIYAT, DFI.DFIYAT DFBFIYAT,
'''' TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
CASE WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM2,'''')     THEN ISNULL(KATSAYI2,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM3,'''')     THEN ISNULL(KATSAYI3,1)
WHEN ISNULL(DFI.FBIRIM,'''') = ISNULL(BIRIM4,'''')     THEN ISNULL(KATSAYI4,1)
ELSE 1  END ISLEMKATSAYISI, DEPART.KODU SDEPART, DEPART.ADI SDEPARTADI,
CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI
ELSE 0 END  BIRIMMALIYET,  DFI.BMALIYET,FBMALIYET,BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC, SKTARIHI, STOK.SFIYAT1,NULL SAAT,ISLREFID,STOK.ALISKDV ,NULL FATCOUNTER,NULL SBOLUMID,NULL SBOLUMADI ,NULL AS FATISLID,NULL ,NULL AS ALTCARIUNVANI,ENO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
TUKETIMFISISL DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID INNER JOIN
TUKETIMFIS    F  WITH (NOLOCK) ON DFI.DEPOFISID   = F.DEPOFISID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP         = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU, 1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU, 2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU,3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT OUTER JOIN
DEPO KDEPO  WITH (NOLOCK) ON ISNULL(DFI.RCDEPOID,F.CDEPOID) = KDEPO.DEPOID LEFT OUTER JOIN
DEPO  WITH (NOLOCK) ON ISNULL(DFI.RGDEPOID,F.GDEPOID)  = DEPO.DEPOID LEFT OUTER JOIN
SUBELER  WITH (NOLOCK) ON F.CSUBEID = SUBELER.SUBEID LEFT OUTER JOIN
DEPART  WITH (NOLOCK) ON DEPART.KODU = F.SDEPART
WHERE  ISNULL(F.SIL,0)=0 AND  F.GDEPOID > 0 AND 1=1  ' 
--SERVİS FORMU
SET @SQLCUMLE8=' UNION ALL
SELECT 0 as SIL, 1 AS FTIPI, F.ARACKABULID,ISNULL(F.TESLIMTARIH,F.TARIH) AS TARIH, YEAR(F.TARIH+SG.VADEGUN) AS VADEYIL,
MONTH(F.TARIH+SG.VADEGUN) AS VADEAY,
F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, F.TARIH AS ISLEMTARIH, NULL AS ISLEMGRUBU1, 3 SAYIMSIRA,
''SATIS'' FISTIPI, 1 DEPOID, ''01'' DEPOKODU, ''ANADEPO'' AS DEPOADI, CAST(0 as bit) AS ANADEPO,
''SATIS'' AS ISLEM, ''Servis Formu'' FACIKLAMA, DFI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF, SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, ''Servis Formu'' as ACIKLAMA,
DFI.MIKTAR*-1 GCADET,  DFI.BFIYAT AS NFIYAT, DFI.BFIYAT AS DNFIYAT,
DFI.BFIYAT, DFI.BFIYAT AS DBFIYAT, 0 SATIRIND, 0 SATIRIND2, F.FORMNO FATNO, ''01'' AS KODU, F.UNVANI AS CARIUNVANI,
DFI.BFIYAT * DFI.MIKTAR  AS TOPLAM, DFI.BFIYAT*MIKTAR AS DTOPLAM, 0 INDORAN1, 0 EKORAN1, 0 INDORAN2,
0 EKORAN2, 0 INDORAN3, 0 EKORAN3, NULL BAYIID, NULL SATISTID, STOK.SALISFIYAT, NULL BAYI, NULL SATIST, STOK.BARKOD BARKOD, NULL VADE, NULL SATICIKOMORAN,
0 STKOMORAN, 0 BKOMORAN, 0 IRSALIYE, '''' FATGRUP, 1 AS KDEPOID, 1 AS SUBEID, ''01'' AS SUBEKODU, ''MERKEZ'' AS SUBEADI,
'''' AS ISLEMDETAY,1 AS SATIRKNO, STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4, NULL, NULL, NULL, NULL,NULL, ''TL'' AS DOVIZ,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU, 2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU, 4)) USTGRUPKODU, SG2.GRUPADI USTGRUPADI,
SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU,6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI, SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI, F.CARIID AS HESAPID,
''01'' AS  KDEPOKODU,''ANADEPO'' AS KDEPOADI,NULL, STOK.TURU TURU,SAYIMBIRIMI,STOK.BIRIM FBIRIM, DFI.MIKTAR AS FADET, DFI.BFIYAT FBFIYAT, DFI.BFIYAT DFBFIYAT,
'''' TEVORAN, ''01'' AS SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,NULL OZELKOD1,NULL OZELKOD2,NULL OZELKOD3,
1 AS ISLEMKATSAYISI, ''01'' SDEPART, ''GENEL'' AS SDEPARTADI,
BFIYAT AS  BIRIMMALIYET,  DFI.BFIYAT AS BMALIYET,BFIYAT AS FBMALIYET,1 AS BKATSAYI,
DFI.MIKTAR * CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,
0 DURUM, 0 MUHFC, F.TARIH AS SKTARIHI, STOK.SFIYAT1,NULL SAAT,0 AS ISLREFID,STOK.ALISKDV ,NULL FATCOUNTER,NULL SBOLUMID,NULL SBOLUMADI ,NULL AS FATISLID,NULL ,NULL AS ALTCARIUNVANI,FORMNO AS EVRAKSIRANO
FROM STOK  WITH (NOLOCK) INNER JOIN
ARACKABULPARCA DFI WITH (NOLOCK) ON STOK.STOKID = DFI.STOKID LEFT JOIN
ARACKABUL    F  WITH (NOLOCK) ON DFI.ARACKABULID   = F.ARACKABULID LEFT JOIN
SGRUP SG  WITH (NOLOCK) ON STOK.GRUP         = SG.GRUPKODU LEFT JOIN
SGRUP SG1  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ANAGRUPUZUNLUGU, 1)) = SG1.GRUPKODU LEFT OUTER JOIN
SGRUP SG2  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALTGRUPUZUNLUGU, 2)) = SG2.GRUPKODU LEFT OUTER JOIN
SGRUP SG3  WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU, 1, ISNULL(SG.ALT2GRUPUZUNLUGU,3)) = SG3.GRUPKODU LEFT OUTER JOIN
MUH_HESAP HSP150  WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP600  WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT OUTER JOIN
MUH_HESAP HSP740  WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID
WHERE  ISNULL(F.SIL,0)=0  AND ISNULL(FATID,0)=0 AND 1=1  '    
EXEC (@SQLCUMLE1+@PARAMETRE+@SQLCUMLE2+@PARAMETRE+@SQLCUMLE3+@PARAMETRE+@SQLCUMLE4+@PARAMETRE+@SQLCUMLE5+@PARAMETRE+@SQLCUMLE6+@PARAMETRE+@SQLCUMLE7+@PARAMETRE+@SQLCUMLE8+@PARAMETRE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRLQ_TEST]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRLQ_TEST]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(50)
AS
BEGIN
DECLARE 
@SQLCUMLE NVARCHAR(MAX)
SET @SQLCUMLE='SELECT 0 as SIL, 1 AS FTIPI, F.FATID,ISNULL(F.IRSALIYETARIHI,F.TARIH) AS TARIH, YEAR(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEYIL,
 MONTH(F.TARIH+ISNULL(SG.VADEGUN,0)) AS VADEAY, F.TARIH+ISNULL(SG.VADEGUN,0) AS STOKVADE, ISNULL(F.ADD_DATE,F.TARIH) AS ISLEMTARIH,
 NULL AS ISLEMGRUBU1,1 SAYIMSIRA,''FATURA'' FISTIPI, ISNULL(FI.RGDEPOID,F.DEPOID) DEPOID, DEPO.KODU DEPOKODU, DEPO.DEPOADI, ISNULL(DEPO.ANADEPO,0) ANADEPO,
 CASE WHEN FISTURID IN (51,54,61) THEN ''ALIS'' ELSE ''SATIS'' END AS ISLEM,F.ACIKLAMA FACIKLAMA, FI.STOKID,STOK.GRUP SGRUPKODU,SG.MASRAF AS MASRAF,
 SG.GRUPADI SGRUPADI, STOK.KODU STOKKODU,STOK.ADI, FI.ACIKLAMA,(CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * ISNULL(F.TUR,-1) GCADET,
 FI.BFIYAT * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))
 / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  NFIYAT,ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 -
 FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0)) / 100 * (100 - ISNULL(F.INDORAN2,0))
 / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0)) / 100  DNFIYAT,
 BFIYAT,ISNULL(DBFIYAT,BFIYAT) AS DBFIYAT,FI.SATIRIND, FI.SATIRIND2, F.FATNO, CARI.KODU, CARI.ACIKLAMA AS CARIUNVANI,
 FI.BFIYAT * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
 / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0))
 / 100 * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END) *
 F.TUR TOPLAM,ISNULL(FI.DBFIYAT,FI.BFIYAT) * (100 - FI.SATIRIND) / 100 * (100 - FI.SATIRIND2) / 100 * (100 - ISNULL(F.INDORAN1,0)) / 100 * (100 + ISNULL(F.EKORAN1,0))
 / 100 * (100 - ISNULL(F.INDORAN2,0)) / 100 * (100 + ISNULL(F.EKORAN2,0)) / 100 * (100 - ISNULL(F.INDORAN3,0)) / 100 * (100 + ISNULL(F.EKORAN3,0))
 / 100 * (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 1 ELSE ISNULL(FI.ADET,0) END) * F.TUR DTOPLAM,
 F.INDORAN1, F.EKORAN1, F.INDORAN2, F.EKORAN2, F.INDORAN3, F.EKORAN3, F.BAYIID, F.SATISTID, STOK.SALISFIYAT, ISNULL(BAYI.BAYI,'''') BAYI,
 SATIST.SATIST, FI.BARKOD BARKOD, F.VADE, SATIST.SKOMORAN SATICIKOMORAN, STOK.SKOMORAN STKOMORAN, STOK.BKOMORAN, F.IRSALIYE,
 NULL AS FATGRUP, CAST(NULL AS INTEGER) KDEPOID, F.SUBEID SUBEID, SUBELER.SUBEKODU SUBEKODU, SUBELER.SUBEADI SUBEADI,
 CAST(TUR AS NVARCHAR(15)) ISLEMDETAY, FI.FATISLID SATIRKNO ,STOK.BIRIM SBIRIMI,BIRIM2,KATSAYI2,BIRIM3,KATSAYI3,BIRIM4,KATSAYI4,FI.KDV KDV,
 F.TOPLAM FTTOPLAM, F.KDV FTKDV, F.GTOPLAM FTGTOPLAM, ISNULL(F.DTOPLAM,F.GTOPLAM) AS FTDTOPLAM, ISNULL(F.DOVIZ,''TL'') AS DOVIZ,
 SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ANAGRUPUZUNLUGU,	2)) ANAGRUPKODU, SG1.GRUPADI ANAGRUPADI, SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALTGRUPUZUNLUGU,  4))
 USTGRUPKODU,SG2.GRUPADI USTGRUPADI,SUBSTRING(SG.GRUPKODU, 1,ISNULL(SG.ALT2GRUPUZUNLUGU, 6)) ALTGRUPKODU, SG3.GRUPADI ALTGRUPADI,
 SG.MUHALISHESAPID, HSP150.KODU NMUHKODU, HSP150.ACIKLAMA NMUHADI,SG.MUHSATISHESAPID, HSP600.KODU GMUHKODU, HSP600.ACIKLAMA GMUHADI,
 SG.MUHSARFHESAPID, HSP740.KODU SMUHKODU, HSP740.ACIKLAMA SMUHADI,CARI.HESAPID,NULL KDEPOKODU,NULL KDEPOADI,CARI.HESAPID AS CARIID ,STOK.TURU TURU,SAYIMBIRIMI,FI.FBIRIM FBIRIM, FI.FADET ,
 FI.FBFIYAT FBFIYAT, ISNULL(FI.DFBFIYAT,FI.FBFIYAT) AS DFBFIYAT,FI.TEVORAN, SUBELER.SUBEKODU SKODU, ISNULL(STOK.KKALDIR,0) KKALDIR,F.OZELKOD1,F.OZELKOD2,F.OZELKOD3,
 CASE WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(STOK.BIRIM,'''') THEN 1
  WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM2,'''') THEN ISNULL(KATSAYI2,1)
  WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM3,'''') THEN ISNULL(KATSAYI3,1)
  WHEN ISNULL(FI.FBIRIM,'''') = ISNULL(BIRIM4,'''') THEN ISNULL(KATSAYI4,1)
  ELSE 1 END ISLEMKATSAYISI, CASE WHEN FISTURID IN (52,62) THEN ''SATIS'' ELSE ''ALIS'' END SDEPART, CAST('''' AS NVARCHAR(50)) SDEPARTADI,
  CASE WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
  WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END	 BIRIMMALIYET, BMALIYET,FBMALIYET,BKATSAYI,
  (CASE WHEN ISNULL(FARKFATURASI,0)=1 THEN 0 ELSE ISNULL(FI.ADET,0) END) * F.TUR * CASE
  WHEN STOK.TURU=''Hammadde'' THEN SALISFIYAT
  WHEN ISNULL(KISISAYISI,0)>0 THEN  MALIYET/KISISAYISI ELSE 0 END TOPLAMMALIYET,F.FISDURUMID AS DURUM, F.MUHFC, FI.SKTARIHI ,STOK.SFIYAT1, CONVERT(NVARCHAR(5),F.KTARIH,108) SAAT,NULL ISLREFID,STOK.ALISKDV,F.FATID AS FATCOUNTER,NULL	SBOLUMID,NULL SBOLUMADI,FI.FATISLID
 ,ALTCARI.CARIUNVANI AS ALTCARIUNVANI ,F.ALTCARIID,F.EVRAKSIRANO
  FROM  FU_FATISL FI WITH (NOLOCK) INNER JOIN
  FATURA F WITH (NOLOCK) ON FI.FATID = F.FATID LEFT OUTER JOIN
 HESPLAN CARI	WITH (NOLOCK) ON F.FISHESAPID = CARI.HESAPID  LEFT OUTER JOIN
 HESCARI ALTCARI	 WITH (NOLOCK) ON F.ALTCARIID= ALTCARI.HESCARIID  LEFT OUTER JOIN
 STOK WITH (NOLOCK) ON FI.STOKID = STOK.STOKID	 LEFT JOIN
 DEPO WITH (NOLOCK) ON DEPO.DEPOID = ISNULL(FI.RGDEPOID,F.DEPOID)LEFT JOIN
 SGRUP SG WITH (NOLOCK) ON STOK.GRUP = SG.GRUPKODU LEFT JOIN
 SGRUP SG1 WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU,1,ISNULL(SG.ANAGRUPUZUNLUGU,1)) = SG1.GRUPKODU LEFT OUTER JOIN
 SGRUP SG2 WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU,1,ISNULL(SG.ALTGRUPUZUNLUGU,2)) = SG2.GRUPKODU LEFT OUTER JOIN
 SGRUP SG3 WITH (NOLOCK) ON SUBSTRING(SG.GRUPKODU,1,ISNULL(SG.ALT2GRUPUZUNLUGU,3)) = SG3.GRUPKODU LEFT OUTER JOIN
 HESPLAN HSP150	WITH (NOLOCK) ON SG.MUHALISHESAPID = HSP150.HESAPID LEFT JOIN
 HESPLAN HSP600	WITH (NOLOCK) ON SG.MUHSATISHESAPID = HSP600.HESAPID LEFT JOIN
 HESPLAN HSP740	WITH (NOLOCK) ON SG.MUHSARFHESAPID = HSP740.HESAPID LEFT JOIN
 BAYI WITH (NOLOCK) ON F.BAYIID = BAYI.BAYIID LEFT JOIN
 SATIST WITH (NOLOCK) ON FI.SATISTID = SATIST.SATISID LEFT JOIN
 SUBELER WITH (NOLOCK) ON F.SUBEID = SUBELER.SUBEID
 WHERE 1=1 '
EXEC (@SQLCUMLE+@PARAMETRE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_ADISYON]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRM_ADISYON]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADISYON WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_ADISYONYAZ]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRM_ADISYONYAZ] @FISCOUNTER NVARCHAR(10)
AS
UPDATE ADISYON SET ADISYON.STOPLAM=Q.STOPLAM, ADISYON.TOPLAM=Q.STOPLAM FROM ADISYON INNER JOIN (SELECT ADISYON.FISCOUNTER, 
SUM(BIRIMFIYAT*ADET)/100*(100-ISNULL(ADISYON.INDORAN,0)) AS TOPLAM, SUM(BIRIMFIYAT*ADET) AS STOPLAM
FROM ADISYON INNER JOIN ADSSATIR ON ADISYON.FISCOUNTER=ADSSATIR.FISCOUNTER WHERE ISNULL(ADSSATIR.SIL,0)=0 AND ADISYON.FISCOUNTER=@FISCOUNTER GROUP BY ADISYON.INDORAN, ADISYON.FISCOUNTER) AS Q ON ADISYON.FISCOUNTER=Q.FISCOUNTER
UPDATE ADISYON SET DIRTY=0 WHERE FISCOUNTER=@FISCOUNTER
GO
/****** Object:  StoredProcedure [dbo].[PRM_ADISYONYAZ_ISARETLE]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRM_ADISYONYAZ_ISARETLE] @FISCOUNTER NVARCHAR(10)
AS
UPDATE ADISYON SET DIRTY=1 WHERE FISCOUNTER=@FISCOUNTER
GO
/****** Object:  StoredProcedure [dbo].[PRM_ADSSATIR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRM_ADSSATIR]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' * FROM ADSSATIR WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_ANAGRUPLAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRM_ANAGRUPLAR]  @PARAMETRE NVARCHAR(150)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT DISTINCT ANAGRUPADI FROM SGRUP WITH (NOLOCK) WHERE GRUPTURU=''URUN'' AND ANAGRUPADI<>'''' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_CARIKART]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRM_CARIKART]   @PARAMETRE NVARCHAR(350)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT CARIID,UNVANI,STDIND,TIP,TEL1,CEPTEL,KARTTURU FROM CARIKART WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_EKOZELLIK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRM_EKOZELLIK] @PARAMETRE NVARCHAR(250)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT FIRMAID,SUBEID,GRUP,OZELLIK,FIYAT,IKRAM,MANUEL,SURE,TUMURUNLER FROM EKOZELLIK WITH (NOLOCK) WHERE 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_LKURUN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[PRM_LKURUN]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' STOKID,KODU,BARKOD,ADI,BIRIM,SFIYAT1,SDOVIZ1,POSYAZICIID1,POSYAZICIID2 
FROM STOK WITH (NOLOCK) WHERE TURU=''Mamul'' and ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_SGRUP]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRM_SGRUP]  @PARAMETRE NVARCHAR(150)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT SGRUPID,SUBEID,FIRMAID,GRUPKODU,GRUPADI,ANAGRUPADI,GRUPTURU FROM SGRUP WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND GRUPTURU=''URUN'' AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_TUMMASALAR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO











CREATE PROCEDURE [dbo].[PRM_TUMMASALAR]  @DEPT NVARCHAR(10), @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TARIH NVARCHAR(12)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(2000)
if @DEPT<>''
	BEGIN
		SET @SQLCUMLE='SELECT M.FIRMAID,M.SUBEID,M.DEPID,M.DEPART AS DEPKODU,M.MASAID, M.STATU, (CASE WHEN CALLSIPARISID>0 THEN M.MASANO+'' (PAKET) '' ELSE M.MASANO END) AS MASANO, ISNULL(M.KISIS,2) AS KISIS, A.ASAATI,
		DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, 
		DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE, A.GARSONKODU, A.TARIH, A.KISI,
		A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM, INDORAN,A.FISCOUNTER,
		(CASE WHEN ISNULL(M.STATU,0)=0 THEN ''BOŞ'' WHEN M.STATU=1 THEN ''DOLU'' WHEN M.STATU=2 THEN ''KİRLİ''
			 WHEN M.STATU=3 THEN ''REZERVE'' WHEN M.STATU=4 THEN ''KAPALI'' ELSE '''' END) AS MASADURUM,
			 ISNULL(A.ACIKLAMA,M.ACIKLAMA) AS ACIKLAMA
			 FROM MASALAR AS M LEFT JOIN (SELECT * FROM ADISYON
			 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND  
			 ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND DEPID='''+@DEPT+''')
			 AS A ON M.MASANO = A.MASANO AND M.DEPID=A.DEPID AND A.DEPID='''+@DEPT+'''
			 WHERE ISNULL(M.SIL,0)=0 AND M.FIRMAID='+@FIRMAID+' AND M.SUBEID='+@SUBEID+' AND M.DEPID='''+@DEPT+'''
			 UNION ALL
			 SELECT FIRMAID,SUBEID,A.DEPID,DEPKODU,9999 AS MASAID, ISNULL(MASASTATU,1) AS STATU, A.MASANO, A.KISI AS KISIS, A.ASAATI, 
			DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE,
			 A.GARSONKODU, A.TARIH,A.KISI,
			 A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM,INDORAN,A.FISCOUNTER, ''DOLU'' AS MASADURUM, A.ACIKLAMA FROM ADISYON AS A
			 WHERE ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND FIRMAID='+@FIRMAID+' AND 
			 SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+'''
			 AND (MASANO NOT LIKE''Z%'' AND MASANO NOT IN(SELECT MASANO FROM MASALAR 
			 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND DEPID='''+@DEPT+''')) ORDER BY MASANO'
	END
ELSE
	BEGIN
		SET @SQLCUMLE='SELECT M.FIRMAID,M.SUBEID,M.DEPID,M.DEPART AS DEPKODU,M.MASAID, M.STATU, (CASE WHEN CALLSIPARISID>0 THEN M.MASANO+'' (PAKET) '' ELSE M.MASANO END) AS MASANO, ISNULL(M.KISIS,2) AS KISIS, A.ASAATI,
		DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, 
		DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE, A.GARSONKODU, A.TARIH, A.KISI,
		A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM, INDORAN,A.FISCOUNTER,
		(CASE WHEN ISNULL(M.STATU,0)=0 THEN ''BOŞ'' WHEN M.STATU=1 THEN ''DOLU'' WHEN M.STATU=2 THEN ''KİRLİ''
			 WHEN M.STATU=3 THEN ''REZERVE'' WHEN M.STATU=4 THEN ''KAPALI'' ELSE '''' END) AS MASADURUM,
			 ISNULL(A.ACIKLAMA,M.ACIKLAMA) AS ACIKLAMA
			 FROM MASALAR AS M LEFT JOIN (SELECT * FROM ADISYON
			 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+' AND  
			 ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''')
			 AS A ON M.MASANO = A.MASANO AND M.DEPID=A.DEPID AND A.DEPID='''+@DEPT+'''
			 WHERE ISNULL(M.SIL,0)=0 AND M.FIRMAID='+@FIRMAID+' AND M.SUBEID='+@SUBEID+'
			 UNION ALL
			 SELECT FIRMAID,SUBEID,A.DEPID,DEPKODU,9999 AS MASAID, ISNULL(MASASTATU,1) AS STATU, A.MASANO, A.KISI AS KISIS, A.ASAATI, 
			DBO.FN_SUREBUL(ASAATI,GETDATE()) AS SURE, DBO.FN_SUREBUL(SSAATI,GETDATE()) AS SONSURE,
			 A.GARSONKODU, A.TARIH,A.KISI,
			 A.TOPLAM/100*(100-ISNULL(A.INDORAN,0))-(ISNULL(ONAKIT,0)+ISNULL(OACIK,0)+ISNULL(OKK,0)+ISNULL(OTICKET,0)+ISNULL(OTICKET2,0)+ISNULL(OTICKET3,0)+ISNULL(OTICKET4,0)+ISNULL(OTICKET5,0)) AS TOPLAM,INDORAN,A.FISCOUNTER, ''DOLU'' AS MASADURUM, A.ACIKLAMA FROM ADISYON AS A
			 WHERE ISNULL(SIL,0)=0 AND TARIH='''+@TARIH+''' AND FIRMAID='+@FIRMAID+' AND 
			 SUBEID='+@SUBEID+' 
			 AND (MASANO NOT LIKE''Z%'' AND MASANO NOT IN(SELECT MASANO FROM MASALAR 
			 WHERE FIRMAID='+@FIRMAID+' AND SUBEID='+@SUBEID+')) ORDER BY MASANO'
	END
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_URUNLER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRM_URUNLER]  @PARAMETRE NVARCHAR(150)
AS
SET NOCOUNT ON
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT STOKID,GRUPID,KODU,BARKOD,ADI,SFIYAT1,SDOVIZ1 FROM STOK WITH (NOLOCK) WHERE ISNULL(SIL,0)=0 AND TURU=''Mamul'' and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[PRM_YAZDIRILACAKADISYON]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[PRM_YAZDIRILACAKADISYON] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(11)
AS
SELECT FISCOUNTER FROM ADISYON WITH (NOLOCK) WHERE FIRMAID=@FIRMAID AND TARIH=@TARIH  AND DIRTY=0
GO
/****** Object:  StoredProcedure [dbo].[PRM_YAZDIRILACAKSIPARIS]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRM_YAZDIRILACAKSIPARIS] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10)
AS
SELECT DEPID, ADSSATIR.FISCOUNTER FROM ADISYON WITH (NOLOCK) INNER JOIN ADSSATIR WITH (NOLOCK) ON ADISYON.FISCOUNTER=ADSSATIR.FISCOUNTER 
WHERE ADISYON.FIRMAID=@FIRMAID AND TARIH=@TARIH  AND H=-1 AND ISNULL(GONDERILDI,0)=0 AND SIP=1
GROUP BY DEPID,ADSSATIR.FISCOUNTER
GO
/****** Object:  StoredProcedure [dbo].[PRM_YAZSIPARISHAZIRLA]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRM_YAZSIPARISHAZIRLA] @FIRMAID NVARCHAR(10), @TARIH NVARCHAR(10)
AS
UPDATE ADSSATIR SET SIP=1 WHERE FISCOUNTER IN(SELECT FISCOUNTER FROM ADISYON WHERE ADISYON.FIRMAID=@FIRMAID AND TARIH=@TARIH  AND H=-1 AND ISNULL(GONDERILDI,0)=0 AND SIP=0)
GO
/****** Object:  StoredProcedure [dbo].[PRMF_FATURATOPLAM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRMF_FATURATOPLAM]  
@FATID INT,
@INDORAN1 FLOAT,
@INDORAN2 FLOAT,
@INDORAN3 FLOAT,
@EKORAN1 FLOAT,
@EKORAN2 FLOAT,
@EKORAN3 FLOAT
AS
BEGIN
SELECT FI.FATID,
       SUM(FADET*FBFIYAT) AS TOPLAM,
       SUM(FADET*DFBFIYAT) AS DTOPLAM,
       SUM(FADET*FBFIYAT)-SUM(((FADET*FBFIYAT)*(100-ISNULL(SATIRIND,0))/100)
       *(100-ISNULL(SATIRIND2,0))/100) AS INDTUTAR,
       SUM(FADET*DFBFIYAT)-SUM(((FADET*DFBFIYAT)*(100-ISNULL(SATIRIND,0))/100)
       *(100-ISNULL(SATIRIND2,0))/100) AS DINDTUTAR,
       SUM((((FADET*FBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100) AS NETTOPLAM,
       SUM((((FADET*DFBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100) AS DNETTOPLAM,
       SUM((((((FADET*FBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100))*ISNULL(FI.KDV,0)/100) -  
       SUM(((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))
       / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - @INDORAN1)
       / 100 * (100 + @EKORAN1)
       / 100 * (100 - @INDORAN2)
       / 100 * (100 + @EKORAN2)
       / 100 * (100 - @INDORAN3)
       / 100 * (100 + @EKORAN3) / 100) *
       ISNULL(FI.ADET,0)) *
       CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
       /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  *(FI.KDV/100))
        AS KDVTUTAR,
       SUM(((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))
       / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - @INDORAN1)
       / 100 * (100 + @EKORAN1)
       / 100 * (100 - @INDORAN2)
       / 100 * (100 + @EKORAN2)
       / 100 * (100 - @INDORAN3)
       / 100 * (100 + @EKORAN3) / 100) *
       ISNULL(FI.ADET,0)) *
       CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
       /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  *(FI.KDV/100)) AS TEVKIFAT,
       SUM((((((FADET*DFBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100))*ISNULL(FI.KDV,0)/100) AS DKDVTUTAR,
       SUM((((((FADET*FBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100))/100*(100+ISNULL(FI.KDV,0)))-SUM(((ISNULL(FI.BFIYAT,0) * (100 - ISNULL(FI.SATIRIND,0))
       / 100 * (100 - ISNULL(FI.SATIRIND2,0)) / 100 * (100 - @INDORAN1)
       / 100 * (100 + @EKORAN1)
       / 100 * (100 - @INDORAN2)
       / 100 * (100 + @EKORAN2)
       / 100 * (100 - @INDORAN3)
       / 100 * (100 + @EKORAN3) / 100) *
       ISNULL(FI.ADET,0)) *
       CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,1,CHARINDEX('/',TEVORAN)-1)   AS FLOAT) ELSE 0 END
       /  CASE WHEN CHARINDEX('/',TEVORAN)>0 THEN CAST(SUBSTRING(TEVORAN,CHARINDEX('/',TEVORAN)+1,100) AS FLOAT) ELSE 1 END  *(FI.KDV/100)) AS GENELTOPLAM,
       SUM((((((FADET*DFBFIYAT)*(100-ISNULL(SATIRIND,0))/100)*(100-ISNULL(SATIRIND2,0))/100)*(100-@INDORAN1)/100))/100*(100+ISNULL(FI.KDV,0))) AS DGENELTOPLAM
       FROM FATISL AS FI
       WHERE FI.FATID=@FATID
       GROUP BY FI.FATID
END
GO
/****** Object:  StoredProcedure [dbo].[SITE_AIDAT_DONEM]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_AIDAT_DONEM] @FIRMAID NVARCHAR(10)
AS
SELECT GRUPID,FIRMAID,SUBEID,GRUPKODU,GRUPADI,TIPID,AKTIF FROM MUH_GRUP WHERE ISNULL(SIL,0)=0 AND TIPID=3 AND FIRMAID=@FIRMAID
/*ISLEMGRUPID1=GRUPID */
GO
/****** Object:  StoredProcedure [dbo].[SITE_HESAP_BAKIYE_ISLEMGRUPID1]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_HESAP_BAKIYE_ISLEMGRUPID1] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(20)
AS
SELECT KODU,HESAPADI,ISLEMGRUPID1, MUH_GRUP.GRUPADI AS ISLEMGRUPADI, SUM(BORC)-SUM(ALACAK) AS TLBAKIYE, SUM(DBORC)-SUM(DALACAK) AS DVZBAKIYE, DOVIZ 
FROM [FNCQ_HESAPDETAY_FATURA_HESAPID] (@TARIH, @TARIH2, @FIRMAID, @HESAPID)  AS TBL 
LEFT JOIN  MUH_GRUP WITH (NOLOCK) ON TBL.ISLEMGRUPID1=MUH_GRUP.GRUPID GROUP BY ISLEMGRUPID1,DOVIZ,MUH_GRUP.GRUPADI,KODU,HESAPADI
GO
/****** Object:  StoredProcedure [dbo].[SITE_HESAP_BAKIYE_OZET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_HESAP_BAKIYE_OZET] @TARIH NVARCHAR(10), @TARIH2 NVARCHAR(10), @FIRMAID NVARCHAR(10), @HESAPID NVARCHAR(20)
AS
SELECT KODU,HESAPADI,SUM(BORC)-SUM(ALACAK) AS TLBAKIYE, SUM(DBORC)-SUM(DALACAK) AS DVZBAKIYE, DOVIZ 
FROM [FNCQ_HESAPDETAY_FATURA_HESAPID] (@TARIH, @TARIH2, @FIRMAID, @HESAPID)  AS TBL 
GROUP BY DOVIZ,KODU,HESAPADI
GO
/****** Object:  StoredProcedure [dbo].[SITE_KULLANICI_FIRMALARI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_KULLANICI_FIRMALARI] @SITEKULLANICILARID NVARCHAR(10)
AS
SELECT SITEKULLANICIHESAP.SITEKULLANICILARID, SITEKULLANICILAR.ADSOYAD, SITEKULLANICILAR.EMAIL, 
SUBELER.SUBEID, MUHFIRMAID, FIRMALAR.FIRMAKODU, MUHHESAPID, MUH_HESAP.KODU AS HESAPKODU, MUH_HESAP.ACIKLAMA AS HESAPADI 
FROM SITEKULLANICIHESAP WITH (NOLOCK) 
INNER JOIN SITEKULLANICILAR WITH (NOLOCK) ON SITEKULLANICIHESAP.SITEKULLANICILARID=SITEKULLANICILAR.SITEKULLANICILARID
INNER JOIN FIRMALAR WITH (NOLOCK) ON SITEKULLANICIHESAP.MUHFIRMAID=FIRMALAR.FIRMAID
LEFT JOIN MUH_HESAP WITH (NOLOCK) ON SITEKULLANICIHESAP.MUHHESAPID=MUH_HESAP.HESAPID
LEFT JOIN SUBELER WITH (NOLOCK) ON SITEKULLANICIHESAP.MUHFIRMAID=SUBELER.FIRMAID
WHERE SITEKULLANICIHESAP.SITEKULLANICILARID=@SITEKULLANICILARID
GO
/****** Object:  StoredProcedure [dbo].[SITE_LOGIN]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_LOGIN] @EMAIL NVARCHAR(50), @SIFRE NVARCHAR(30)
AS
SELECT SITEKULLANICILARID, FIRMAID, SUBEID, ADSOYAD, 
YETKITIPI,AKTIF,SEHIR,ULKE,DIL FROM SITEKULLANICILAR 
WHERE AKTIF=1 AND ISNULL(SIL,0)=0 AND EMAIL=@EMAIL AND SIFRE=@SIFRE
GO
/****** Object:  StoredProcedure [dbo].[SITE_MUH_DONEMI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_MUH_DONEMI] @FIRMAID NVARCHAR(10)
AS
SELECT FIRMAID,SUBEID,KODU,DONEMBASI,DONEMSONU,KAPANDI FROM MUHDONEM WHERE ISNULL(SIL,0)=0 AND ISNULL(KAPANDI,0)=0 AND FIRMAID=@FIRMAID
GO
/****** Object:  StoredProcedure [dbo].[SITE_ODEME_GONDER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SITE_ODEME_GONDER]
 @FIRMAID NVARCHAR(10), @SUBEID NVARCHAR(10), @TARIH NVARCHAR(10), @TUTAR FLOAT, @DOVIZ NVARCHAR(5), @ISLEMGRUPID1 NVARCHAR(10), @OZELKODID NVARCHAR(10), 
 @HESAPID NVARCHAR(10),  @ACIKLAMA NVARCHAR(100), @BELGENO NVARCHAR(20)
 AS 
BEGIN 
	DECLARE 
	@FISID INT,
	@FATID INT,
	@FISUUID uniqueidentifier,
	@IYZICOHESAPID INT,
	@DTUTAR FLOAT,
	@KUR FLOAT,
	@HESAPDOVIZ NVARCHAR(5)

/*EXEC SITE_ODEME_GONDER '308','319','2023-08-31',100.00,'USD',4796,4634,159973,NULL,'5454545' */
	
	IF @DOVIZ IN('TL','TRY')	
		BEGIN
			SET @HESAPDOVIZ=ISNULL((SELECT DOVIZ FROM MUH_HESAP WHERE HESAPID=@HESAPID),'TL')
			IF @HESAPDOVIZ<>'TL'
				BEGIN
					SET @KUR=ISNULL((SELECT TOP 1  MBDOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU=@HESAPDOVIZ AND TARIH=@TARIH),(SELECT MAX(MBDOVIZALIS) FROM DOVIZISL WHERE KODU=@DOVIZ AND FIRMAID=@FIRMAID))
					SET @DTUTAR=@TUTAR
					SET @TUTAR=NULLIF(@TUTAR,0)*NULLIF(@KUR,0)
				END
		END
	ELSE
		BEGIN
				IF (SELECT count(*) FROM DOVIZ WHERE KODU=@DOVIZ AND FIRMAID=@FIRMAID)>0
					BEGIN
						SET @KUR=ISNULL((SELECT TOP 1 MBDOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU=@DOVIZ AND TARIH=@TARIH),(SELECT MAX(MBDOVIZALIS) FROM DOVIZISL WHERE KODU=@DOVIZ AND FIRMAID=@FIRMAID))
						SET @DTUTAR=@TUTAR
						SET @TUTAR=NULLIF(@TUTAR,0)*NULLIF(@KUR,0)
					END
				ELSE
					BEGIN
						IF @DOVIZ='EUR' SET @DOVIZ='EURO'
						SET @KUR=ISNULL((SELECT TOP 1 MBDOVIZALIS FROM DOVIZISL WHERE FIRMAID=@FIRMAID AND KODU=@DOVIZ AND TARIH=@TARIH),(SELECT MAX(MBDOVIZALIS) FROM DOVIZISL WHERE KODU=@DOVIZ AND FIRMAID=@FIRMAID))
						SET @DTUTAR=@TUTAR
						SET	@TUTAR=NULLIF(@TUTAR,0)*NULLIF(@KUR,0)
					END
		END
			set @FISUUID=NEWID()
			SET @IYZICOHESAPID=ISNULL((SELECT HESAPID FROM MUH_HESAP WHERE FIRMAID=@FIRMAID AND 
			KODU=(SELECT TOP 1 VALUESTR FROM CONFIG WHERE FIRMAID=@FIRMAID AND KEYNAME='iyzico Hesap Kodu')),-999)

			INSERT INTO  MUH_FIS (FISUUID,TARIH,FISNO,FISTURID,FISHESAPID, FISTURU,MODULID,MODULEKRANID,FIRMAID,SUBEID,
			ISLEMGRUPID1,OZELKODID, FISDURUMID,DETAYLIENTEGRE,ADD_DATE,ADD_USERID,
			ACIKLAMA,BELGENO,ENTKAYNAKID,ENTKAYNAK,TOPLAM,DTOPLAM,KUR,DOVIZ)
			VALUES(@FISUUID,@TARIH, dbo.FNMUH_FISNO_VER (@SUBEID,'Mahsup',@TARIH),3,@IYZICOHESAPID,'Bankaya Tahsilat',1,1,
			@FIRMAID,@SUBEID, @ISLEMGRUPID1, @OZELKODID, 1,1,GETDATE(),-1,'iyzico Online Tahsilat',@BELGENO,-9999,'IYZICO',@TUTAR,@DTUTAR,@KUR,@DOVIZ)

			SET @FISID=(SELECT FISID FROM MUH_FIS WHERE FISUUID=@FISUUID)

			INSERT INTO MUH_HESAPISL (FISID,HESAPID,ISLEMGRUPID1,OZELKODID, ACIKLAMA,BORC,ALACAK,DBORC,DALACAK,KUR,DOVIZ,TUTAR,DTUTAR)
			VALUES (@FISID, @HESAPID,@ISLEMGRUPID1, @OZELKODID, ISNULL(@ACIKLAMA,'İyzico Online Tahsilat'),0.00,@TUTAR,0.00, @DTUTAR,@KUR,@DOVIZ,@TUTAR,@DTUTAR)
	end
GO
/****** Object:  StoredProcedure [dbo].[SP_BIRIM_BIRIM2_DEGISTIR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_BIRIM_BIRIM2_DEGISTIR] (@STOKID INT) AS  
  
 IF NOT EXISTS (SELECT STOKID FROM STOK WHERE ISNULL(BIRIM,'')<>'' AND ISNULL(BIRIM2,'')<>'' AND ISNULL(BIRIM3,'')='' AND ISNULL(BIRIM4,'')='' AND ISNULL(KATSAYI2,0)<>0 AND STOKID=@STOKID)  
 BEGIN 
   RAISERROR ('Bu stok kartında işlem yapılamaz.', -- Message text. 
                16, -- Severity. 
                1 -- State. 
                ) 
   RETURN 
 END 
  
 UPDATE FATISL SET ADET = ADET * (1.00/STOK.KATSAYI2), 
                   BFIYAT = 1.00 * BFIYAT * (STOK.KATSAYI2)  
 FROM FATISL INNER JOIN STOK ON FATISL.STOKID=STOK.STOKID  
 WHERE FATISL.STOKID = @STOKID 
  
 UPDATE DEPOFISISL SET MIKTAR = MIKTAR * (1.00/STOK.KATSAYI2), 
                   BFIYAT = 1.00 * BFIYAT * (STOK.KATSAYI2)  
 FROM DEPOFISISL INNER JOIN STOK ON DEPOFISISL.STOKID=STOK.STOKID  
 WHERE DEPOFISISL.STOKID = @STOKID 
  
 UPDATE TUKETIMFISISL SET MIKTAR = MIKTAR * (1.00/STOK.KATSAYI2), 
                   BFIYAT = 1.00 * BFIYAT * (STOK.KATSAYI2)  
 FROM TUKETIMFISISL INNER JOIN STOK ON TUKETIMFISISL.STOKID=STOK.STOKID  
 WHERE TUKETIMFISISL.STOKID = @STOKID 
  
 UPDATE TALEPFISISL  
 SET TMIKTAR  = TMIKTAR  * (1.00/STOK.KATSAYI2), 
     SMIKTAR  = SMIKTAR  * (1.00/STOK.KATSAYI2), 
     ADMIKTAR = ADMIKTAR * (1.00/STOK.KATSAYI2) 
 FROM   TALEPFISISL INNER JOIN STOK ON TALEPFISISL.STOKID=STOK.STOKID  
 WHERE  TALEPFISISL.STOKID = @STOKID 
  
 UPDATE SAYIM2 
   SET DEVIRMIKTAR = DEVIRMIKTAR * (1.00/STOK.KATSAYI2), 
       ALIMMIKTAR = ALIMMIKTAR * (1.00/STOK.KATSAYI2), 
       ALIMIADEMIKTAR = ALIMIADEMIKTAR * (1.00/STOK.KATSAYI2), 
       TRANSGMIKTAR = TRANSGMIKTAR * (1.00/STOK.KATSAYI2), 
       TRANSCMIKTAR = TRANSCMIKTAR * (1.00/STOK.KATSAYI2), 
       CIKANMIKTAR = CIKANMIKTAR * (1.00/STOK.KATSAYI2), 
       SAYIM = SAYIM * (1.00/STOK.KATSAYI2), 
       SAYIM2.ORTFIYAT = 1.00 * SAYIM2.ORTFIYAT * STOK.KATSAYI2 
 FROM SAYIM2 INNER JOIN STOK ON SAYIM2.STOKID=STOK.STOKID  
 WHERE SAYIM2.STOKID = @STOKID 
                                                                                           
 UPDATE RECETE  
 SET ORAN = ORAN * (1.00/STOK.KATSAYI2), 
     BMALIYET = 1.00 * BMALIYET * STOK.KATSAYI2, 
     SONBMALIYET = 1.00 * SONBMALIYET * STOK.KATSAYI2, 
     XBIRIM = STOK.BIRIM2 
 FROM RECETE INNER JOIN STOK ON RECETE.STOKID=STOK.STOKID  
 WHERE RECETE.STOKID = @STOKID 
  
 UPDATE STOK SET BIRIM = BIRIM2, BIRIM2=BIRIM, KATSAYI2 = 1.00 / KATSAYI2 ,RECETEBIRIMI=BIRIM2 
 WHERE STOKID = @STOKID
GO
/****** Object:  StoredProcedure [dbo].[SP_DEPOID_DEGISTIR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SP_DEPOID_DEGISTIR] (@DEPOID INT,@YDEPOID INT ) AS   
   
  
  IF NOT EXISTS (SELECT TOP 1 DEPOID FROM QMUH_STOKISL WHERE DEPOID=@DEPOID)   
  BEGIN  
    RAISERROR ('işlem bulunamadı', -- Message text.  
                 16, -- Severity.  
                 1 -- State.  
                 )  
    RETURN  
  END  
  
  
  UPDATE FATURA     SET DEPOID    = @YDEPOID WHERE DEPOID=@DEPOID 
  UPDATE DEPOFIS    SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE DEPOFIS    SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID 
  UPDATE TUKETIMFIS SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE TUKETIMFIS SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID 
  UPDATE TALEPFIS   SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE TALEPFIS   SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID
GO
/****** Object:  StoredProcedure [dbo].[SP_DROPDEFAULTCONSTRAINT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SP_DROPDEFAULTCONSTRAINT] (@DEPOID INT,@YDEPOID INT ) AS   
   
  
  IF NOT EXISTS (SELECT TOP 1 DEPOID FROM QMUH_STOKISL WHERE DEPOID=@DEPOID)   
  BEGIN  
    RAISERROR ('işlem bulunamadı', -- Message text.  
                 16, -- Severity.  
                 1 -- State.  
                 )  
    RETURN  
  END  
  
  
  UPDATE FATURA     SET DEPOID    = @YDEPOID WHERE DEPOID=@DEPOID 
  UPDATE DEPOFIS    SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE DEPOFIS    SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID 
  UPDATE TUKETIMFIS SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE TUKETIMFIS SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID 
  UPDATE TALEPFIS   SET GDEPOID   = @YDEPOID WHERE GDEPOID=@DEPOID 
  UPDATE TALEPFIS   SET CDEPOID   = @YDEPOID WHERE CDEPOID=@DEPOID
GO
/****** Object:  StoredProcedure [dbo].[SP_ETSFIFOMALIYET]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_ETSFIFOMALIYET]  
       @TARIH DATETIME  
  AS  
  BEGIN  
       DECLARE @STOKID INT  
       DECLARE @TOPLAM_SAYIM FLOAT  
       DECLARE @GCADET FLOAT, @NFIYAT FLOAT  
       DECLARE @SAYIM_KALAN FLOAT, @MALIYET FLOAT  
       DECLARE SAYIM_CURSOR CURSOR FOR   
                SELECT SUM(SAYIM), STOKID FROM SAYIM2   
                WHERE TARIH=@TARIH  
                GROUP  BY  STOKID  
  
      OPEN SAYIM_CURSOR  
       FETCH NEXT FROM SAYIM_CURSOR INTO @TOPLAM_SAYIM, @STOKID    
       WHILE(@@FETCH_STATUS = 0)   
       BEGIN  
             --SAYIMI OKU  
             --ALISLARI GERIYE DOGRU LISTELE  
             DECLARE ALIS_CURSOR CURSOR FOR  
                   SELECT GCADET, NFIYAT FROM QMUH_STOKISLSAYIM   
                   WHERE STOKID = @STOKID AND FISTIPI = 'FATURA'   
                   ORDER BY TARIH DESC, FATID DESC  
  
            SET @SAYIM_KALAN = @TOPLAM_SAYIM  
             SET @MALIYET = 0  
                         
             OPEN ALIS_CURSOR  
             FETCH NEXT FROM ALIS_CURSOR INTO @GCADET, @NFIYAT    
             WHILE(@@FETCH_STATUS = 0)   
             BEGIN  
  
                  --FATURLARI GERIYE DOGRU TARA  
                   IF (@SAYIM_KALAN<@GCADET AND @GCADET >= 0)  
                   BEGIN  
                      SET @MALIYET = @MALIYET + @SAYIM_KALAN * @NFIYAT  
                      UPDATE SAYIM2 SET ORTFIYAT = CASE WHEN @TOPLAM_SAYIM=0 THEN 0 ELSE @MALIYET / @TOPLAM_SAYIM END  
                      WHERE STOKID = @STOKID AND TARIH = @TARIH   
                      BREAK  
                   END     
                   ELSE  
                   BEGIN  
                      SET @MALIYET=@MALIYET + @GCADET * @NFIYAT  
                      SET @SAYIM_KALAN=@SAYIM_KALAN - @GCADET  
                   END   
                 FETCH NEXT FROM ALIS_CURSOR INTO @GCADET, @NFIYAT  
             END  
             CLOSE ALIS_CURSOR  
             DEALLOCATE ALIS_CURSOR  
             FETCH NEXT FROM SAYIM_CURSOR INTO @TOPLAM_SAYIM, @STOKID    
             END  
       CLOSE SAYIM_CURSOR  
     DEALLOCATE SAYIM_CURSOR  
  END
GO
/****** Object:  StoredProcedure [dbo].[SP_ETSMUHFISKURUSFARKIDUZELT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 CREATE  PROCEDURE [dbo].[SP_ETSMUHFISKURUSFARKIDUZELT]  
 (@ID NVARCHAR(MAX)='0',@TARIH1 DATETIME,@TARIH2 DATETIME) AS  

  BEGIN  

  DECLARE @FISID INT  

  DECLARE @BALANCE FLOAT    

 

  DECLARE @FISIDS TABLE(FISID INT PRIMARY KEY) 

  INSERT INTO @FISIDS 

  SELECT DISTINCT CAST(splitdata AS INT) 

  FROM FN_SPLIT_STRING(@ID,',') 

  WHERE LEN(splitdata) > 0 

   

  IF ISNULL(@ID,'0')<>'0'  

  BEGIN 

  SET @ID=','+REPLACE(@ID,CHAR(39),'')+','   

   UPDATE MUH_HESAPISL SET ALACAK=0,BORC=BORC-ALACAK WHERE BORC>ALACAK AND ALACAK<>0  AND FISID IN(SELECT FISID FROM @FISIDS) 

			AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2) 

  

   UPDATE MUH_HESAPISL SET BORC=0,ALACAK=ALACAK-BORC WHERE BORC<ALACAK AND BORC<>0 AND FISID IN(SELECT FISID FROM @FISIDS) 

         AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

  DECLARE MUHFIS_CURSOR CURSOR  FOR  

                  SELECT FISID FROM MUH_HESAPISL (nolock) 

         WHERE ISNULL(SILINDI,0)=0 AND CHARINDEX(','+CAST(FISID AS NVARCHAR(20))+',',@ID)>0  

 				 AND FISID IN (SELECT FISID FROM MUH_FIS (nolock) WHERE ISNULL(YEVMNO,'0')='0' AND (MUH_FIS.TARIH BETWEEN @TARIH1 AND @TARIH2) AND ISNULL(FISDURUMID,0)>=0) 

         GROUP BY FISID  

          HAVING ABS((SUM(BORC)-SUM(ALACAK)))>0.00001 AND ABS((SUM(BORC)-SUM(ALACAK)))<0.05  

  END 

  ELSE  

  BEGIN 

   UPDATE MUH_HESAPISL SET ALACAK=0,BORC=BORC-ALACAK WHERE BORC>ALACAK AND ALACAK<>0  

			AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

     

   UPDATE MUH_HESAPISL SET BORC=0,ALACAK=ALACAK-BORC WHERE BORC<ALACAK AND BORC<>0

         AND ISNULL(SILINDI,0)=0 AND FISID IN (SELECT FISID FROM MUH_FIS (NOLOCK) WHERE ISNULL(FISDURUMID,0)>-2 AND ISNULL(YEVMNO,'0')='0' AND TARIH BETWEEN @TARIH1 AND @TARIH2)

  DECLARE MUHFIS_CURSOR CURSOR FOR  

                  SELECT FISID FROM MUH_HESAPISL (nolock)  

 				          WHERE ISNULL(SILINDI,0)=0 AND FISID  IN (SELECT FISID FROM MUH_FIS (nolock)  WHERE ISNULL(YEVMNO,'0')='0' AND (MUH_FIS.TARIH BETWEEN @TARIH1 AND @TARIH2) AND ISNULL(FISDURUMID,0)>=0) 

                  GROUP BY FISID  

          HAVING ABS((SUM(BORC)-SUM(ALACAK)))>0.00001 AND ABS((SUM(BORC)-SUM(ALACAK)))<0.05  

  

  END   OPEN MUHFIS_CURSOR 

  FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID  

  WHILE(@@FETCH_STATUS = 0)  

  BEGIN  

  	 SELECT @BALANCE=(CASE WHEN ABS(SUM(BORC)-SUM(ALACAK))>0.00001 AND ABS(SUM(BORC)-SUM(ALACAK))<0.05 THEN SUM(BORC)-SUM(ALACAK) ELSE 0 END) FROM MUH_HESAPISL (nolock)      WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID  

      IF @BALANCE<> 0  

      BEGIN  

       IF @BALANCE>0  

       BEGIN  

        UPDATE MUH_HESAPISL  

        SET BORC=BORC-@BALANCE  

        WHERE BORC>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE  ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

        UPDATE MUH_HESAPISL  

        SET ALACAK=ALACAK+@BALANCE   

        WHERE ALACAK>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

       END  

       ELSE  

       IF @BALANCE<0  

       BEGIN  

        UPDATE MUH_HESAPISL  

        SET ALACAK=ALACAK-ABS(@BALANCE)  

        WHERE ALACAK>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND  FISID=@FISID ORDER BY (BORC+ALACAK) DESC) ORDER BY (BORC+ALACAK) DESC)  

   

        UPDATE MUH_HESAPISL  

        SET BORC=BORC+ABS(@BALANCE)  

        WHERE BORC>0 AND  

        ISLEMID=(SELECT TOP 1 ISLEMID FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID AND ISLEMID NOT IN (SELECT TOP 1 ISLEMID  FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=@FISID ORDER BY (BORC+ALACAK)DESC) ORDER BY (BORC+ALACAK) DESC)  

       END  

   

       UPDATE MUH_FIS SET TOPLAM=(SELECT SUM(BORC) FROM MUH_HESAPISL (nolock) WHERE ISNULL(SILINDI,0)=0 AND FISID=MUH_FIS.FISID ) WHERE ISNULL(FISDURUMID,0)>=0 AND FISID=@FISID  

      END  

     FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID  

  END  

  CLOSE MUHFIS_CURSOR  

  DEALLOCATE MUHFIS_CURSOR  

  END
GO
/****** Object:  StoredProcedure [dbo].[SP_MUHFIS_FISNODUZELT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_MUHFIS_FISNODUZELT]  
 (@SUBEID INT,@TAR1 DATETIME,@TAR2 DATETIME,@TARIH DATETIME) AS 

  BEGIN 

  DECLARE @FISID INT  

  

 	 UPDATE MUH_FIS 

 	 SET FISNO=NULL 

   FROM MUH_FIS  

   INNER JOIN (SELECT MIN(FISID) AS FISID ,FISNO AS FNO FROM MUH_FIS  

               WHERE SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0  

               GROUP BY FISNO)  AS TBL  

    	  ON TBL.FNO=MUH_FIS.FISNO AND TBL.FISID<>MUH_FIS.FISID  

 	 WHERE SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0 

   AND (FISNO IN ( 

 	      SELECT FISNO FROM QMUH_FIS 

 	      WHERE SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH AND ISNULL(FISNO,0)>0 

 	      GROUP BY FISNO  

 	      HAVING COUNT(*)>1) OR LEN(FISNO)<7) 

   DECLARE MUHFIS_CURSOR CURSOR FOR   

 			  SELECT FISID FROM 
			  (SELECT TARIH,FISID FROM QMUH_FIS 
 			  WHERE FISTURID IN (49) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH
			  UNION ALL
			  SELECT TARIH,FISID FROM QMUH_FIS 
 			  WHERE FISTURID NOT IN (48,49) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH
			  UNION ALL
			  SELECT TARIH,FISID FROM QMUH_FIS 
 			  WHERE FISTURID IN (48) AND FISNO IS NULL AND FISDURUMID>=0  AND SUBEID=@SUBEID AND (TARIH BETWEEN @TAR1 AND @TAR2) AND TARIH>=@TARIH) AS QMUH_FIS   ORDER BY TARIH

   OPEN MUHFIS_CURSOR  

   FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID   

   WHILE(@@FETCH_STATUS = 0)   

   BEGIN   

 		    UPDATE MUH_FIS  

 		    SET FISNO=DBO.FNMUH_FISNO_VER(SUBEID,FISTURU,TARIH) 

 	    	WHERE FISID=@FISID 

        FETCH NEXT FROM MUHFIS_CURSOR INTO @FISID   

   END   

  

   CLOSE MUHFIS_CURSOR   

   DEALLOCATE MUHFIS_CURSOR   

 END
GO
/****** Object:  StoredProcedure [dbo].[SP_MUHFIS_SIRADUZELT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SP_MUHFIS_SIRADUZELT]  
 (@FISID INT) AS 

  BEGIN 

 DECLARE @EFISID INT 

 DECLARE @UPDATED_CURSOR CURSOR 

 IF ISNULL(@FISID,0)<>0  

 SET @UPDATED_CURSOR = CURSOR FAST_FORWARD FOR 

 SELECT FISID FROM MUH_FIS WHERE FISID=@FISID 

 ELSE  SET @UPDATED_CURSOR = CURSOR FAST_FORWARD FOR 

 SELECT FISID FROM MUH_FIS 

 

 OPEN @UPDATED_CURSOR 

 FETCH NEXT FROM @UPDATED_CURSOR 

 INTO @EFISID 

 

 WHILE @@FETCH_STATUS = 0 

 BEGIN 

 

   UPDATE MUH_HESAPISL 

   SET SSIRA=KSIRA 

   FROM MUH_HESAPISL HI 

   INNER JOIN (SELECT ISLEMID,ROW_NUMBER() OVER (ORDER BY ISLEMID) KSIRA FROM MUH_HESAPISL 

   WHERE ISNULL(SILINDI,0)=0 AND FISID=@EFISID) AS TBL2 ON TBL2.ISLEMID=HI.ISLEMID WHERE ISNULL(SSIRA,-1)<0 

   

   FETCH NEXT FROM @UPDATED_CURSOR 

   INTO @EFISID 

 END 

 CLOSE @UPDATED_CURSOR 

 DEALLOCATE @UPDATED_CURSOR 

  END
GO
/****** Object:  StoredProcedure [dbo].[SP_STOKMIADBAKIYE_OLUSTUR]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_STOKMIADBAKIYE_OLUSTUR] AS 
 DECLARE @SUBEID INT 
 DECLARE @DEPOID INT 
 DECLARE @STOKID INT 
 DECLARE @BAKIYE FLOAT 
 DECLARE @SKTARIHI SMALLDATETIME 
 DECLARE @GCADET FLOAT 
 DECLARE @STOKBAKIYE_CURSOR CURSOR 
 DECLARE @KALANMIKTAR FLOAT 
 DECLARE @KALANFATURAMIKTAR FLOAT 
 DECLARE @DEPOMIKTAR  FLOAT 
   SET @STOKBAKIYE_CURSOR= CURSOR FOR 
     SELECT SUBEID,STOKID,SUM(GCADET) AS BAKIYE  
     FROM (SELECT SUBEID,DEPOID,STOKID,SUM(GCADET) AS GCADET FROM QMUH_STOKISLSAYIM GROUP BY SUBEID,DEPOID,STOKID HAVING SUM(GCADET)>0) AS TBL  
     GROUP BY SUBEID,STOKID  
     ORDER BY SUBEID,STOKID 
   OPEN @STOKBAKIYE_CURSOR  
   FETCH NEXT FROM @STOKBAKIYE_CURSOR INTO @SUBEID,@STOKID,@BAKIYE 
   WHILE(@@FETCH_STATUS = 0) 
   BEGIN 
     SELECT @KALANMIKTAR=@BAKIYE 
     PRINT 'STOK BAKIYE DONUYOR :'+STR(@BAKIYE)  
     DECLARE @FATISL_CURSOR CURSOR 
     SET     @FATISL_CURSOR= CURSOR FOR 
     SELECT  GCADET,SKTARIHI FROM QMUH_STOKISL WHERE FISTIPI='FATURA' AND GCADET>0 AND STOKID=@STOKID ORDER BY ISNULL(SKTARIHI,'01.01.1900') 
     OPEN @FATISL_CURSOR  
     FETCH NEXT FROM @FATISL_CURSOR INTO @GCADET,@SKTARIHI 
     WHILE(@@FETCH_STATUS = 0) 
     BEGIN 
       SELECT @KALANFATURAMIKTAR=@GCADET 
       PRINT 'FATISL DONUYOR : '+STR(@GCADET) 
       DECLARE @DEPOBAKIYE_CURSOR CURSOR 
       SET     @DEPOBAKIYE_CURSOR=CURSOR FOR 
            SELECT DEPOID, 
            SUM(GCADET)-(SELECT ISNULL(SUM(MIKTAR),0) FROM STOKMIADBAKIYE WHERE STOKMIADBAKIYE.SUBEID=QMUH_STOKISL.SUBEID AND  
                                                                           STOKMIADBAKIYE.DEPOID=QMUH_STOKISL.DEPOID AND  
                                                                           STOKMIADBAKIYE.STOKID=QMUH_STOKISL.STOKID  ) AS MIKTAR 
            FROM QMUH_STOKISL  
            WHERE STOKID=@STOKID GROUP BY SUBEID,DEPOID,ANADEPO,STOKID HAVING SUM(GCADET)>0 ORDER BY ANADEPO,DEPOID 
       OPEN @DEPOBAKIYE_CURSOR  
       FETCH NEXT FROM @DEPOBAKIYE_CURSOR INTO @DEPOID,@DEPOMIKTAR 
       WHILE(@@FETCH_STATUS = 0) 
       BEGIN 
        PRINT 'DEPO BAKIYE DONUYOR'+STR(@DEPOID)+' '+STR(@KALANMIKTAR)+' >> '+STR(@KALANFATURAMIKTAR)+' <> '+STR(@DEPOMIKTAR)+' >>> '+CAST(@SKTARIHI AS NVARCHAR(20)) 
        IF @KALANFATURAMIKTAR > 0  
        BEGIN 
         IF @KALANFATURAMIKTAR >= @DEPOMIKTAR 
         BEGIN 
           IF EXISTS(SELECT * FROM STOKMIADBAKIYE WHERE SUBEID=@SUBEID AND DEPOID=@DEPOID AND STOKID=@STOKID AND ISNULL(SKTARIHI,'01.01.1900')=ISNULL(@SKTARIHI,'01.01.1900'))  
  		    UPDATE STOKMIADBAKIYE SET MIKTAR = MIKTAR + @DEPOMIKTAR WHERE SUBEID=@SUBEID AND DEPOID=@DEPOID AND STOKID=@STOKID AND  ISNULL(SKTARIHI,'01.01.1900')=ISNULL(@SKTARIHI,'01.01.1900')  
           ELSE  
             INSERT INTO STOKMIADBAKIYE(SUBEID,DEPOID,STOKID,MIKTAR,SKTARIHI) VALUES (@SUBEID,@DEPOID,@STOKID,@DEPOMIKTAR,@SKTARIHI)      
           SELECT @KALANFATURAMIKTAR = @KALANFATURAMIKTAR-@DEPOMIKTAR 
           SELECT @KALANMIKTAR = @KALANMIKTAR-@DEPOMIKTAR 
         END 
         ELSE 
         BEGIN 
           IF EXISTS(SELECT * FROM STOKMIADBAKIYE WHERE SUBEID=@SUBEID AND DEPOID=@DEPOID AND STOKID=@STOKID AND  ISNULL(SKTARIHI,'01.01.1900')=ISNULL(@SKTARIHI,'01.01.1900'))  
  		    UPDATE STOKMIADBAKIYE SET MIKTAR = MIKTAR + @KALANFATURAMIKTAR WHERE SUBEID=@SUBEID AND DEPOID=@DEPOID AND STOKID=@STOKID AND  ISNULL(SKTARIHI,'01.01.1900')=ISNULL(@SKTARIHI,'01.01.1900')  
           ELSE  
             INSERT INTO STOKMIADBAKIYE(SUBEID,DEPOID,STOKID,MIKTAR,SKTARIHI) VALUES (@SUBEID,@DEPOID,@STOKID,@KALANFATURAMIKTAR,@SKTARIHI)      
           SELECT @KALANMIKTAR = @KALANMIKTAR-@KALANFATURAMIKTAR 
           SELECT @KALANFATURAMIKTAR = 0 
           BREAK            END 
        END 
        FETCH NEXT FROM @DEPOBAKIYE_CURSOR INTO @DEPOID,@DEPOMIKTAR 
       END 
       CLOSE      @DEPOBAKIYE_CURSOR 
       DEALLOCATE @DEPOBAKIYE_CURSOR 
  
       FETCH NEXT FROM @FATISL_CURSOR INTO @GCADET,@SKTARIHI 
     END 
     CLOSE      @FATISL_CURSOR 
     DEALLOCATE @FATISL_CURSOR 
     FETCH NEXT FROM @STOKBAKIYE_CURSOR INTO @SUBEID,@STOKID,@BAKIYE 
   END 
 CLOSE @STOKBAKIYE_CURSOR 
 DEALLOCATE @STOKBAKIYE_CURSOR
GO
/****** Object:  StoredProcedure [dbo].[SP_Tablolar_ReIndex]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_Tablolar_ReIndex] AS  
 DECLARE @TableName varchar(255)  
 DECLARE TableCursor CURSOR FOR  
 SELECT table_name FROM INFORMATION_SCHEMA.TABLES 
 WHERE table_type = 'base table'  
 OPEN TableCursor  
 FETCH NEXT FROM TableCursor INTO @TableName  
 WHILE @@FETCH_STATUS = 0  
 BEGIN  
 DBCC DBREINDEX(@TableName,' ',70)  
 FETCH NEXT FROM TableCursor INTO @TableName  
 END  
 CLOSE TableCursor  
 DEALLOCATE TableCursor
GO
/****** Object:  StoredProcedure [dbo].[SPETS_FIYATDUZELT]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SPETS_FIYATDUZELT] ( @SUBEID INTEGER ,@TAR1 SMALLDATETIME,@TAR2 SMALLDATETIME) AS   
   /*  1.defa işlemler  */   
   UPDATE QMUH_DEPOFISISLEM   
    SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
                FROM QMUH_STOKISL   
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID   
                  AND (  (QMUH_STOKISL.TARIH<@TAR1) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND (FISTIPI='FATURA' OR ISLEM='ÜRETİM' OR (ISLEM='TRANSFER' AND GCADET>0) )  ) )   
                )      -- O FISI TOPLAMA HESABINA KATMA   
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID   
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND STOKID = 510   
     AND CDEPOID IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE QMUH_DEPOFISISLEM   
   SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
                FROM QMUH_STOKISL   
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID   
                  AND (  (QMUH_STOKISL.TARIH < @TAR1 ) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND GCADET > 0 ) )              
                )      -- O FISI TOPLAMA HESABINA KATMA   
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID    
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND StokId = 510   
     AND CDEPOID NOT IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE DEPOFIS    
   SET TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID),    
           TADET=(SELECT COUNT(*) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID)    
   WHERE TARIH BETWEEN @TAR1 AND @TAR2   
   /* 1. defa bitti*/   
  
   /* 2.defa aynı işlemler  */   
    UPDATE QMUH_DEPOFISISLEM    
    SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
               FROM QMUH_STOKISL    
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID    
                  AND (  (QMUH_STOKISL.TARIH<@TAR1) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND (FISTIPI='FATURA' OR ISLEM='ÜRETİM' OR (ISLEM='TRANSFER' AND GCADET>0) )  ) )   
                )      -- O FISI TOPLAMA HESABINA KATMA   
  
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID   
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND StokId = 510   
     AND CDEPOID IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE QMUH_DEPOFISISLEM   
    SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
                FROM QMUH_STOKISL   
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID   
                  AND (  (QMUH_STOKISL.TARIH < @TAR1 ) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND GCADET > 0 ) )   
                )      -- O FISI TOPLAMA HESABINA KATMA   
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID   
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND StokId = 510   
     AND CDEPOID NOT IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE DEPOFIS   
   SET TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID),   
           TADET=(SELECT COUNT(*) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID)   
   WHERE TARIH BETWEEN @TAR1 AND @TAR2   
   /* 2. defa bitti*/   
   /* 3.defa aynı işlemler  */   
   UPDATE QMUH_DEPOFISISLEM   
    SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
                FROM QMUH_STOKISL   
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID   
                  AND (  (QMUH_STOKISL.TARIH<@TAR1) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND (FISTIPI='FATURA' OR ISLEM='ÜRETİM' OR (ISLEM='TRANSFER' AND GCADET>0) )  ) )   
                )      -- O FISI TOPLAMA HESABINA KATMA   
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID   
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND StokId = 510   
     AND CDEPOID IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE QMUH_DEPOFISISLEM   
    SET BFIYAT=(SELECT (CASE WHEN SUM(GCADET)<=0 THEN 0 ELSE  SUM(GCADET*NFIYAT)/SUM(GCADET) END)   
                FROM QMUH_STOKISL   
                WHERE QMUH_STOKISL.SUBEID=@SUBEID AND QMUH_STOKISL.DEPOID=QMUH_DEPOFISISLEM.CDEPOID     ---AYNI STOGUN O DEPOYA AIT O ISLMEDEN ONCEKI  TUM ESKI ISLEMLERININ   
                  AND QMUH_STOKISL.STOKID=QMUH_DEPOFISISLEM.STOKID   
                  AND (  (QMUH_STOKISL.TARIH < @TAR1 ) OR (QMUH_STOKISL.TARIH BETWEEN @TAR1 AND @TAR2 AND GCADET > 0 ) )   
                )      -- O FISI TOPLAMA HESABINA KATMA   
   WHERE QMUH_DEPOFISISLEM.SUBEID=@SUBEID   
     AND QMUH_DEPOFISISLEM.TARIH BETWEEN @TAR1 AND @TAR2   
     --AND StokId = 510   
     AND CDEPOID NOT IN (SELECT DEPOID FROM DEPO WHERE ANADEPO=1)   
     AND DEPOFISID IN ( SELECT DEPOFISID FROM DEPOFIS WHERE ISLEM  IN ('TRANSFER','TÜKETİM') )   
   UPDATE DEPOFIS   
   SET TTUTAR=(SELECT SUM(MIKTAR*BFIYAT) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID),   
           TADET=(SELECT COUNT(*) FROM DEPOFISISL WHERE DEPOFISISL.DEPOFISID=DEPOFIS.DEPOFISID)   
   WHERE TARIH BETWEEN @TAR1 AND @TAR2   
   /* 3. defa bitti*/
GO
/****** Object:  StoredProcedure [dbo].[SPFO4_POS_ADISYON_FATURAKES]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SPFO4_POS_ADISYON_FATURAKES]  
    (@ADISYONID INT, @GARSON NVARCHAR(50),@FATID INT)     AS 	IF NOT EXISTS(SELECT * FROM FOLYOISL,DEPART WHERE FOLYOISL.DEPT=DEPART.KODU AND DEPART.TUR='B' AND ADISYON=@ADISYONID) 	 BEGIN
	  RAISERROR('Folyoda Islem bulunamadı',16,1)
	 END
	 ELSE
	 IF (ISNULL(@ADISYONID,0)=0)
	 BEGIN
	  RAISERROR('Fatura Parametreleri Hatalı',16,1)
	 END
	ELSE
	 BEGIN
			DECLARE @USERID INT
			SELECT @USERID = ISNULL(MAX(USERID),0) FROM [USER] WHERE KODU=@GARSON

			--DECLARATIONS
			DECLARE @TARIH DATETIME,
					  @FATNO INT,
					  @ACIKLAMA NVARCHAR(255),
					  @DOVIZKODU NVARCHAR(50),
					  @ODANO NVARCHAR(10),
					  @KNO INT


		  DECLARE @EFATTURU  INT
		  IF DBO.FN_READEXEINI('HOTEL','EFaturaEnt','Varsayılan Fatura Türü (Ticari/Temel) ') = 'Temel'
			 SET @EFATTURU = 0 ELSE SET @EFATTURU = 1

			SELECT @TARIH = DBO.TARIHAL(ISNULL(TARIH,GETDATE())) FROM PTARIH

			IF DBO.FN_READEXEINI('HOTEL','Fatura','Faturada Acenta ve Onburo Ayni No Kullan') = '1'
				EXEC SPREADID 'Genel Fatura No'  , @FATNO OUTPUT
			ELSE
				EXEC SPREADID 'Onbura Fatura No' , @FATNO OUTPUT

		  SELECT @KNO = FOLYONO FROM FOLYOISL WHERE ADISYON=@ADISYONID

		  SELECT @DOVIZKODU=DOVIZKODU,@ODANO=ODANO FROM RES WHERE KNO=@KNO

		   DECLARE @EXTKUR FLOAT
			IF (DBO.FN_READEXEINI('HOTEL','Fatura','Extra Faturasinda KUR1 Kullan') = '1')
			  SELECT TOP 1 @EXTKUR=K.KUR1 FROM QFO4_DOVIZ_KUR K WHERE K.TARIH=@TARIH AND K.DOVIZKODU = @DOVIZKODU
			ELSE
			  SELECT TOP 1 @EXTKUR=K.KUR3 FROM QFO4_DOVIZ_KUR K WHERE K.TARIH=@TARIH AND K.DOVIZKODU = @DOVIZKODU
			INSERT INTO OTEL_FATURA([FATID],[FATNO],[FISDURUMID],[FISTURID]
				,[CARIID],[UNVANI],[ADRES1],[ADRES2],[VD]
				,[VDNO],[TARIH],[VADE],[ACIKLAMA],[OZELKOD1],[OZELKOD2]
				,[DOVIZ],[KUR],[DGTOPLAM],[TOPLAM],[KDV],[GTOPLAM]
				,[ADD_DATE],[ADD_USERID],[CARITURID],[EFATTURU],TEL)
			SELECT @FATID,@FATNO,0,62,0,FA.FUNVANI,FA.FADRESI1,FA.FADRESI2,FA.FVD,FA.FVDNO,
			@TARIH,@TARIH,@ACIKLAMA,@KNO,@ODANO,@DOVIZKODU,
			@EXTKUR  ,
			0.0,0.0,0.0,0.0,GETDATE(),@USERID ,1,@EFATTURU,NULL
			FROM FISARSIV FA
			WHERE FA.FISCOUNTER=@ADISYONID 
			IF EXISTS(SELECT TOP 1 * FROM OTEL_FATURA WHERE [FATID] = @FATID)
 			   INSERT INTO OTEL_FATISL(FATID,ACIKLAMA,KNO,DEPT,GELIRGRUP,KDV,TUTAR,DOVIZ,KUR,DTUTAR)
 			   SELECT @FATID,MAX(DEPART.ADI)+' '+MAX(GELIRGRUP.ADI),@KNO,FOLYOISL.DEPT,FOLYOISL.GELIRGRUBU,
 			   MAX(ISNULL(GELIRGRUP.KDV,0)+ISNULL(GELIRGRUP.EKKDV,0)+ISNULL(GELIRGRUP.EKKDV2,0)+ISNULL(GELIRGRUP.EKKDV2,0)/100.0),     SUM(FOLYOISL.BORC*100/(100.0+ISNULL(GELIRGRUP.KDV,0)+ISNULL(GELIRGRUP.EKKDV,0)+ISNULL(GELIRGRUP.EKKDV2,0)+ISNULL(GELIRGRUP.EKKDV2,0)/100.0)),MAX(FATURA.DOVIZ),MAX(FATURA.KUR),
 			   CASE WHEN MAX(ISNULL(FATURA.KUR,0)) <> 0 THEN SUM(FOLYOISL.BORC)/MAX(FATURA.KUR) ELSE 0 END
 			   FROM QFOLYOISL AS FOLYOISL
 				INNER JOIN DEPART    ON FOLYOISL.DEPT = DEPART.KODU
 				LEFT JOIN GELIRGRUP ON FOLYOISL.GELIRGRUBU = GELIRGRUP.KODU
 				LEFT JOIN OTEL_FATURA FATURA ON FATURA.FATID = @FATID
 			   WHERE FOLYOISL.FOLYONO = @KNO AND DEPART.TUR = 'B' AND ISNULL(FOLYOISL.FATID,0)=0  AND ADISYON=@ADISYONID
 			   GROUP BY FOLYOISL.DEPT,FOLYOISL.GELIRGRUBU
			OPTION(RECOMPILE)

 			 IF EXISTS(SELECT TOP 1 * FROM OTEL_FATURA WHERE [FATID] = @FATID)
 				 UPDATE FOLYOISL SET FATID = @FATID WHERE FOLYOISL.FOLYONO = @KNO AND ISNULL(FOLYOISL.FATID,0)=0  AND    ADISYON=@ADISYONID



			--Toplanilan odeme bilgisini faturaya git yaz
			UPDATE OTEL_FATURA SET
			[DGTOPLAM] = DGT , [TOPLAM] = T.TOPLAM , [KDV] = T.KT , [GTOPLAM] = T.TOPLAM+T.KT
			FROM (
				SELECT SUM(DTUTAR) AS DGT , SUM(TUTAR) AS TOPLAM , SUM(TUTAR*ISNULL(KDV,0)/100.0) AS KT
				FROM OTEL_FATISL WHERE OTEL_FATISL.FATID = @FATID
			) AS T WHERE FATID = @FATID
  END
GO
/****** Object:  StoredProcedure [dbo].[SPFO4_POS_RECID_FATURAKES]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SPFO4_POS_RECID_FATURAKES]  
    (@RECID INT, @GARSON NVARCHAR(50),@FATID INT)
    AS
	IF (ISNULL(@RECID,0)=0)
	 BEGIN
	  RAISERROR('Fatura Parametreleri Hatalı',16,1)
	 END
	ELSE
	 BEGIN
			DECLARE @USERID INT
			SELECT @USERID = ISNULL(MAX(USERID),0) FROM [USER] WHERE KODU=@GARSON

			--DECLARATIONS
			DECLARE @TARIH DATETIME,
					  @FATNO INT,
					  @ACIKLAMA NVARCHAR(255),
					  @DOVIZKODU NVARCHAR(50),
					  @ODANO NVARCHAR(10),
					  @KNO INT


		  DECLARE @EFATTURU  INT
		  IF DBO.FN_READEXEINI('HOTEL','EFaturaEnt','Varsayılan Fatura Türü (Ticari/Temel) ') = 'Temel'
			 SET @EFATTURU = 0 ELSE SET @EFATTURU = 1

			SELECT @TARIH = DBO.TARIHAL(ISNULL(TARIH,GETDATE())) FROM PTARIH

			IF DBO.FN_READEXEINI('HOTEL','Fatura','Faturada Acenta ve Onburo Ayni No Kullan') = '1'
				EXEC SPREADID 'Genel Fatura No'  , @FATNO OUTPUT
			ELSE
				EXEC SPREADID 'Onbura Fatura No' , @FATNO OUTPUT

		  SELECT @KNO = KNO FROM REZKISI WHERE REZKISIID=@RECID

		  SELECT @DOVIZKODU=DOVIZKODU,@ODANO=ODANO FROM RES WHERE KNO=@KNO

		   DECLARE @EXTKUR FLOAT
			IF (DBO.FN_READEXEINI('HOTEL','Fatura','Extra Faturasinda KUR1 Kullan') = '1')
			  SELECT TOP 1 @EXTKUR=K.KUR1 FROM QFO4_DOVIZ_KUR K WHERE K.TARIH=@TARIH AND K.DOVIZKODU = @DOVIZKODU
			ELSE
			  SELECT TOP 1 @EXTKUR=K.KUR3 FROM QFO4_DOVIZ_KUR K WHERE K.TARIH=@TARIH AND K.DOVIZKODU = @DOVIZKODU

			INSERT INTO OTEL_FATURA([FATID],[FATNO],[FISDURUMID],[FISTURID]
				,[CARIID],[UNVANI],[ADRES1],[ADRES2],[ULKEKODU],[VD]
				,[VDNO],[TARIH],[VADE],[ACIKLAMA],[OZELKOD1],[OZELKOD2]
				,[DOVIZ],[KUR],[DGTOPLAM],[TOPLAM],[KDV],[GTOPLAM]
				,[ADD_DATE],[ADD_USERID],[CARITURID],[EFATTURU],TEL)
			SELECT @FATID,@FATNO,0,62,OC.CARIID,OC.UNVANI,OC.ADRES1,CASE WHEN TURU = 'ACENTA' THEN  OC.ADRES2 +
		 CASE WHEN (ISNULL(OC.SEHIR,'') <> '' AND CHARINDEX(OC.SEHIR,OC.ADRES2)=0) THEN  '/' + OC.SEHIR ELSE '' END ELSE OC.ADRES2 END AS ADRES2,OC.ULKE,OC.VD,OC.VDNO,
			@TARIH,DATEADD(DAY,ISNULL(OC.VADEGUN,0),@TARIH),@ACIKLAMA,@KNO,@ODANO,@DOVIZKODU,
			@EXTKUR  ,
			0.0,0.0,0.0,0.0,GETDATE(),@USERID ,1,@EFATTURU,OC.TEL1
			FROM OTEL_CARI OC
			INNER JOIN RES ON RES.KNO = @KNO
			WHERE OC.CARIID = 0  ----PEŞİN HESAPLARA KESİLİYOR


			IF EXISTS(SELECT TOP 1 * FROM OTEL_FATURA WHERE [FATID] = @FATID)
 			   INSERT INTO OTEL_FATISL(FATID,ACIKLAMA,KNO,DEPT,GELIRGRUP,KDV,TUTAR,DOVIZ,KUR,DTUTAR)
 			   SELECT @FATID,MAX(DEPART.ADI)+' '+MAX(GELIRGRUP.ADI),@KNO,FOLYOISL.DEPT,FOLYOISL.GELIRGRUBU,
 			   MAX(ISNULL(GELIRGRUP.KDV,0)+ISNULL(GELIRGRUP.EKKDV,0)+ISNULL(GELIRGRUP.EKKDV2,0)+ISNULL(GELIRGRUP.EKKDV2,0)/100.0),     SUM(FOLYOISL.BORC*100/(100.0+ISNULL(GELIRGRUP.KDV,0)+ISNULL(GELIRGRUP.EKKDV,0)+ISNULL(GELIRGRUP.EKKDV2,0)+ISNULL(GELIRGRUP.EKKDV2,0)/100.0)),MAX(FATURA.DOVIZ),MAX(FATURA.KUR),
 			   CASE WHEN MAX(ISNULL(FATURA.KUR,0)) <> 0 THEN SUM(FOLYOISL.BORC)/MAX(FATURA.KUR) ELSE 0 END
 			   FROM QFOLYOISL AS FOLYOISL
 				LEFT JOIN DEPART    ON FOLYOISL.DEPT = DEPART.KODU
 				LEFT JOIN GELIRGRUP ON FOLYOISL.GELIRGRUBU = GELIRGRUP.KODU
 				LEFT JOIN OTEL_FATURA FATURA ON FATURA.FATID = @FATID
 			   WHERE FOLYOISL.FOLYONO = @KNO AND DEPART.TUR = 'B' AND ISNULL(FOLYOISL.FATID,0)=0  AND RECID=@RECID
 			   GROUP BY FOLYOISL.DEPT,FOLYOISL.GELIRGRUBU
			OPTION(RECOMPILE)

 			 IF EXISTS(SELECT TOP 1 * FROM OTEL_FATURA WHERE [FATID] = @FATID)
 				 UPDATE FOLYOISL SET FATID = @FATID WHERE FOLYOISL.FOLYONO = @KNO AND ISNULL(FOLYOISL.FATID,0)=0  AND    RECID=@RECID
			UPDATE OTEL_FATURA SET
			[DGTOPLAM] = DGT , [TOPLAM] = T.TOPLAM , [KDV] = T.KT , [GTOPLAM] = T.TOPLAM+T.KT 			FROM (
				SELECT SUM(DTUTAR) AS DGT , SUM(TUTAR) AS TOPLAM , SUM(TUTAR*ISNULL(KDV,0)/100.0) AS KT
				FROM OTEL_FATISL WHERE OTEL_FATISL.FATID = @FATID
			) AS T WHERE FATID = @FATID
  END
GO
/****** Object:  StoredProcedure [dbo].[SPM_CARILER]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[SPM_CARILER]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' HESAPID,SUBEID,HESAPTIPID,KODU,ACIKLAMA,DOVIZ,VADEGUN,
VD,VDNO,TCKIMLIKNO,UNVANI,ADRES1,ADRES2,SEHIR,PKODU,YETKILI,
TEL1,STDIND,BORCTUTAR,ALACAKTUTAR,DBORCTUTAR,DALACAKTUTAR,
KARTKODU,AKTIF,ILCE,CINDORAN,SIL,STDIND2,ANLASMAOKU,FIYATTIPI,
TAPDK,VADEUYAR FROM MUH_HESAP WHERE ISNULL(SIL,0)=0 AND 
HESAPTIPID IN(120,320,7,740) AND UCHESAP=1 and 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[SPM_FATSTOK]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SPM_FATSTOK]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' SELECT STOKID,ADI,SFIYAT1,BIRIM,SFIYAT2,BIRIM2
 FROM STOK WHERE ISNULL(KKALDIR,0)=0 AND ISNULL(SIL,0)=0 AND 1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[SPM_KULLANICI]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SPM_KULLANICI]  @LIMIT NVARCHAR(10), @PARAMETRE NVARCHAR(350)
AS
BEGIN
DECLARE
@SQLCUMLE NVARCHAR(500)
SET @SQLCUMLE='SELECT TOP '+@LIMIT+' SELECT NOVAUSERID, KODU,ADSOYAD,SIFRESI,
SUBEID,DEPOID,MASMERID,MOBILYETKISEVIYE,FIYATDEGISTIR FROM NOVAUSER WHERE  1=1 '+@PARAMETRE
EXEC (@SQLCUMLE)
END
GO
/****** Object:  StoredProcedure [dbo].[SPREADID]    Script Date: 17.07.2026 15:19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  PROCEDURE [dbo].[SPREADID]  
 @TNAME nvarchar(255) , @NEWID int OUTPUT   
 AS  
  
 	IF NOT EXISTS (SELECT * FROM SAYACLAR WHERE TABLENAME = @TNAME)  
 	BEGIN                                                            
 	SET @NEWID = 1                                                 
 	INSERT INTO SAYACLAR (TABLENAME , SIRANO) VALUES (@TNAME , 2) 
 	END                                                            
 	ELSE                                                           
 	BEGIN                                                            
 	SELECT  @NEWID = SIRANO FROM SAYACLAR WHERE TABLENAME = @TNAME    
 	update SAYACLAR set SIRANO =SIRANO+1 where TABLENAME=@TNAME    
 END
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'NAKİT BANKA KREDİ KARTI DİĞER' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'EMLAKKIRALAMA', @level2type=N'COLUMN',@level2name=N'ODEMESEKLI'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'MESKEN TİCARİ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'EMLAKKIRALAMA', @level2type=N'COLUMN',@level2name=N'KULLANIMAMACI'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'BOŞ EŞYALI DİĞER' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'EMLAKKIRALAMA', @level2type=N'COLUMN',@level2name=N'DURUMU'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'SÜRELİ SÜRESİZ BİTTİ İPTAL' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'EMLAKKIRALAMA', @level2type=N'COLUMN',@level2name=N'SOZLESMEDURUMU'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'İÇ DIŞ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IKEGITIMPLAN_DETAY', @level2type=N'COLUMN',@level2name=N'ICDISEGITIM'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 BEKLEMEDE 1 VERILDI 2 IPTAL' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IKEGITIMPLAN_DETAY', @level2type=N'COLUMN',@level2name=N'EGITIMDURUMID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0-normal 1-onaylı' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'IKFAZLAMESAI', @level2type=N'COLUMN',@level2name=N'ONAYTIPI'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0-ÇIKIŞ 1-GİRİŞ 2-YETKİSİZ İP 3-ZORLA GİRİŞ DENEMESİ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'NOVAERISIM', @level2type=N'COLUMN',@level2name=N'DURUMID'
GO
