Created on 8.09.2025 23:32:14

-----------------Log Baslangıç
Hata Zamanı : 8.09.2025 23:32:14
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Sunucuyla bağlantı kurulurken ağ ile ilgili veya örneğe özel bir hata oluştu. Sunucu bulunamadı veya sunucuya erişilemiyor. Örnek adının doğru olduğunu ve SQL Server'ın uzak bağlantılara izin verdiğini doğrulayın. (provider: Named Pipes Provider, error: 40 - SQL Server için bağlantı açılamadı) ---> System.ComponentModel.Win32Exception (0x80004005): Sistem belirtilen dosyayı bulamıyor
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:2,State:0,Class:20
 Tarih Formatları 
InnerException: Select * From [dbo].[YetkiMenu] Where IsActive=1
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:30:56
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:d791092a-26c1-40c9-9b72-72ebace3411d
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:31:03
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:c5991cde-577c-4b52-93e8-0e195a46b930
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (N'SARAYLI' IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + N'SARAYLI' + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:31:09
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:94255cd7-e996-4719-a3d1-50e198d5ad86
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (N'ACILI' IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + N'ACILI' + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:32:32
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:da851729-f13a-48a8-8e45-84556efa6cd3
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (N'kebo' IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + N'kebo' + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:32:46
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:9258b175-f5b1-4df4-89db-ff880085bc36
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (N'KEBO Q XL.120GR' IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + N'KEBO Q XL.120GR' + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 12.09.2025 17:33:13
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:8b8caccf-ff97-4429-b293-4d6f844a8713
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.05.10 00:00:00';
declare @par2 nvarchar(20) = '2025.09.10 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (N'ACILI' IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + N'ACILI' + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 24.09.2025 12:29:34
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting date and/or time from character string.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
   konum: System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
   konum: System.Data.SqlClient.SqlDataReader.Read()
   konum: System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
   konum: System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   konum: System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:d83b0b6d-98da-4713-b402-9a287a3ea1dc
Error Number:241,State:1,Class:16
 Tarih Formatları 
InnerException: declare @par1 nvarchar(20) = '2025-05-18 00:00:00';
declare @par2 nvarchar(20) = '2025-09-18 00:00:00';

WITH
IncludedUsers AS (
SELECT 
	UserName AS UNJ 
FROM [User] 
WHERE 
	ISNULL([User].Branch,'') IN ('') AND 
	ISNULL([User].Department,'') IN ('')
    ),

PaidBillx AS (SELECT PaidBill.* FROM PaidBill LEFT JOIN IncludedUsers ON PaidBill.UserName=IncludedUsers.UNJ),
Billx AS (SELECT Bill.* FROM Bill LEFT JOIN IncludedUsers ON Bill.UserName=IncludedUsers.UNJ),
BillHeaderx AS (SELECT BillHeader.* FROM BillHeader WHERE BillHeader.Id IN (SELECT DISTINCT HeaderId FROM Billx)),
DeletedBillx AS (SELECT DeletedBill.* FROM DeletedBill LEFT JOIN IncludedUsers ON DeletedBill.UserName=IncludedUsers.UNJ),
DebitPaymentx AS (SELECT Payment.* FROM Payment LEFT JOIN IncludedUsers ON Payment.ReceivedByUserName=IncludedUsers.UNJ where Payment.TableNo='DEBIT' And  Payment.Debit=0),
Collectx AS (SELECT Payment.* FROM Payment LEFT JOIN IncludedUsers ON Payment.ReceivedByUserName=IncludedUsers.UNJ WHERE ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' ),
DirectTransactionx AS (SELECT DirectTransaction.* FROM DirectTransaction LEFT JOIN IncludedUsers ON DirectTransaction.UserName=IncludedUsers.UNJ),
PhoneOrderHeaderx AS (SELECT PhoneOrderHeader.* FROM PhoneOrderHeader LEFT JOIN IncludedUsers ON PhoneOrderHeader.CreatedByUserName=IncludedUsers.UNJ),
Paymentx AS (SELECT Payment.* FROM Payment LEFT JOIN IncludedUsers ON Payment.ReceivedByUserName=IncludedUsers.UNJ WHERE ISNULL(FastSale,0)=1 and Payment.TableNo<>'DEBIT' ),
BillWithHeaderx AS (SELECT BillWithHeader.* FROM BillWithHeader LEFT JOIN IncludedUsers ON BillWithHeader.UserName=IncludedUsers.UNJ where  BillWithHeader.ProductName NOT LIKE '%\[R]%' ESCAPE '\')

,days as (
SELECT TOP (DATEDIFF(DAY, @par1, @par2))
	ROW_NUMBER() OVER (ORDER BY A.object_id) as rowno
FROM 
	sys.objects as A,
	sys.objects AS C,
	sys.objects AS D),
shifts as (
SELECT
		DATEADD(ss,1,DATEADD(dd, days.rowno-1, @par1)) as sStart,
		DATEADD(dd, days.rowno, @par1) as sEnd
FROM
	DAYS
)
	
SELECT 	
	shifts.sStart as Date,
	p.TotalPaymentCount,
	p.CashPayment,
	p.CreditPayment,
	p.TicketPayment,
    p.OnlinePayment,
    p.Discount,
	p.Debit,
	Free.Free,
    ResReturnItems.ResReturnItems,
	Canceled.Canceled,
	DebitPayments.DebitPayment_CashPayment,
	DebitPayments.DebitPayment_CreditPayment,
	DebitPayments.DebitPayment_Discount,
	DebitPayments.DebitPayment_TicketPayment,
	Collects.Collect_CashPayment,
	Collects.Collect_CreditPayment,
	Collects.Collect_Discount,
	Collects.Collect_TicketPayment,
    Collects.Collect_OnlinePayment,
    PakReturnItems.PakReturnItems,
	DirectTransactions.DirectTransaction_CashPayment
	
FROM shifts

CROSS APPLY
(SELECT
	COUNT(*) AS TotalPaymentCount,
    SUM(CashPayment) as CashPayment,
    SUM(CreditPayment) as CreditPayment,
    SUM(TicketPayment) as TicketPayment,
    SUM(OnlinePayment) as OnlinePayment,
    SUM(Discount) as Discount,            
    SUM(Debit) as Debit
FROM Paymentx
WHERE
	Paymentx.PaymentTime>=shifts.sStart AND
	Paymentx.PaymentTime<=shifts.sEnd) as p

CROSS APPLY
(SELECT 
	SUM(OriginalPrice * Quantity) AS Free
FROM PaidBillx 
WHERE 
	PaidBillx.PaymentTime>=shifts.sStart AND
	PaidBillx.PaymentTime<=shifts.sEnd AND
	ISNULL(Price,0)=0) AS Free

CROSS APPLY
(SELECT 
	SUM(OriginalPrice * ABS(Quantity)) AS ResReturnItems
FROM PaidBillx 
WHERE 
	PaidBillx.PaymentTime>=shifts.sStart AND
	PaidBillx.PaymentTime<=shifts.sEnd AND PaidBillx.FastSale=1 AND
	ISNULL(Quantity,0)<0) AS ResReturnItems

CROSS APPLY
(SELECT 
	SUM(OriginalPrice * Quantity) as Canceled
FROM DeletedBillx 
WHERE 
     DeletedBillx.Date>=shifts.sStart AND
     DeletedBillx.Date<=shifts.sEnd) AS Canceled

CROSS APPLY
(SELECT 
	SUM(CashPayment) as DebitPayment_CashPayment,
	SUM(Discount) as DebitPayment_Discount,
	SUM(CreditPayment) as DebitPayment_CreditPayment,
	SUM(TicketPayment) as DebitPayment_TicketPayment
FROM DebitPaymentx 
WHERE 
	DebitPaymentx.PaymentTime>=shifts.sStart AND
	DebitPaymentx.PaymentTime<=shifts.sEnd
) AS DebitPayments
                    
CROSS APPLY                                        
(SELECT 
	SUM(CashPayment) as Collect_CashPayment,
	SUM(CreditPayment) as Collect_CreditPayment,
	SUM(TicketPayment) as Collect_TicketPayment,
    SUM(OnlinePayment) as Collect_OnlinePayment,
	SUM(Discount) as Collect_Discount
FROM Collectx 
WHERE
	Collectx.PaymentTime>=shifts.sStart AND
	Collectx.PaymentTime<=shifts.sEnd) AS Collects

CROSS APPLY
(SELECT 
	SUM(OriginalPrice * ABS(Quantity)) AS PakReturnItems
FROM PaidBillx 
WHERE 
	PaidBillx.PaymentTime>=shifts.sStart AND
	PaidBillx.PaymentTime<=shifts.sEnd AND PaidBillx.FastSale=0 AND
	ISNULL(Quantity,0)<0) AS PakReturnItems

CROSS APPLY
(SELECT 
	SUM(Total) AS DirectTransaction_CashPayment
FROM DirectTransactionx  
WHERE
     DirectTransactionx.[Date]>=shifts.sStart AND
     DirectTransactionx.Date<=shifts.sEnd) AS DirectTransactions 






-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:07
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:3370cd7f-8453-45a4-84d6-cb5407f20315
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:07
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:7f9d9bf3-ec24-43c4-aa80-a1409ca1c7c3
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:07
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:43024cd0-c5d1-4bb6-a5a8-f1468e563deb
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:09
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:f334d5c4-88ac-44f1-bb27-a43909ebb9b1
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:09
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:36040f42-5993-4beb-8340-50a70b538f4e
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:11
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:04dc38c8-24ee-454e-a97b-07e0a7896b88
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:18
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:3d06db53-62ef-435b-8ad6-082bc2deadfc
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:9233c39d-bf03-431f-b7ee-3e19d13f6193
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:34cbd522-eaaa-40d6-93fe-ba455956f2f6
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:1f76b4c6-52ba-42ff-b16e-2c10359bdf91
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:9b35c0b1-d468-4ffa-bbb1-15574512cb02
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:48aa5990-c989-49f4-b50e-30c1c3bc11ab
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:209b8e48-3a49-4e0e-a795-0e69bb25db70
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:60eed2ca-1b0e-4a95-89dd-50c614a57c74
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:f6fe6c79-bc40-46df-a538-d6c7de003a18
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:2fc8bde3-5947-4de9-89ac-bba78fac48a7
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:20
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:3dc819fc-cfc7-43a6-9ec5-fb082d27af23
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:20
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:80976ea5-d333-45a8-a35e-bc13c9a79915
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:20
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:9f80207b-18df-44c2-9bc0-3757f6df3c06
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:20
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:6cd0cd3f-441f-490b-8f01-554e73ed7901
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:21
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:e528e7a0-bcfe-4e16-8ed8-44d053648ebb
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:21
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:33979111-60cc-44f9-b4b6-c23840bc44b2
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:21
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:102d52e3-84d6-4181-948a-7ffe60ebf8bd
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:21
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:bf3a07db-3fff-4fa8-a7c0-db12b7b25ea2
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:22
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:0b5b0014-5d0c-4c1e-9a89-05b766334db6
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:22
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:bbe0963f-9d52-48d4-a101-c37330cb974e
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:22
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:88059ecc-18a1-4039-a768-78df8b1221d0
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:22
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:80f6ceef-fa66-4c88-8b80-ae4a25884d8b
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:28
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:c1b2b71d-a226-45c5-abe5-def31eb41234
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:28
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:98d3cf9f-ff82-4b0b-bdb7-322fab3e6d19
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:63d8986f-35ca-46f2-bea9-6890e9a12022
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:2f5cf486-19e9-4686-ab98-b53553e812f8
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:7f5813f5-778a-4c5a-abe5-82b6eadcf63d
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:88191c01-1ce2-4e98-9482-bf25b53e056f
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:bd9cbdfd-8676-458b-b070-430f729464ae
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:32
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:3dac58c5-bd54-48bf-af66-d9395596070d
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:32
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:4aca47fa-416b-4885-bb79-e073a17648a0
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:32
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:928ddc4b-f67a-4604-9ab5-e8875cb7ffec
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:38
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:5eae3a43-a8dd-4581-b416-f3de3d42a832
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.04.25 00:00:00';
declare @par2 nvarchar(20) = '2025.09.25 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:38
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:ed9010d6-2973-4322-9858-d7e88893e6f1
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.04.25 00:00:00';
declare @par2 nvarchar(20) = '2025.09.25 00:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:53
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:badc332c-92e2-4be3-97bf-d01142474a1b
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:55
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:42bd3105-ce5d-4d75-8666-7126df921fd4
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:03:56
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:d1793a11-9442-4c1a-b8b5-e8772bdb247b
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:12
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:84b31f5a-ff51-41a3-9730-36d2afe8a7c3
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:34
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:e2981f07-2fe1-47fc-bdea-4da081283c91
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:37
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:dcb6a91a-d702-4f01-8053-0c4df7780d27
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:41
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:15d8b6ab-08f4-445c-83f9-46a56eace747
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:53
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:8549797a-671e-4259-8e80-e08b4cfdf2a0
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:53
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:15884712-0012-442a-b631-6f90978e929f
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:55
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:01dc4cac-f876-41cf-85c2-d7a38e2afbb4
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:04:55
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:16097623-6529-4852-8268-b62eefcfb932
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:05:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:25057d6c-0055-4814-b003-1bda6884f479
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:05:31
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:6d98b3fc-73fb-4093-a4f6-583d948e3856
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:05:40
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:d536c557-7775-4d17-bf65-d2ea0335b997
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:05:40
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:5faddd60-0843-46e1-a403-007683ee3ca0
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:05:40
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:0a5f318e-a23c-43b8-8008-6ca4afef90b6
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:07:15
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:6c9d3e62-6b95-491a-a162-dd6f64ea65ae
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:07:43
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:129bb549-b6a9-441d-9bbd-e2137eb1b371
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 25.09.2025 17:07:43
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@par1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d2".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
Must declare the scalar variable "@d1".
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:64941e49-ce00-49ee-85a3-3b4b55e8a1f9
Error Number:137,State:2,Class:15
 Tarih Formatları 
InnerException: DECLARE @d1 nvarchar(20) = @par1, @d2 nvarchar(20) = @par2;

;WITH
-- @d1..@d2 aralığındaki tüm günler
DateSpine AS (
    SELECT CAST(@d1 AS date) AS DateValue
    UNION ALL
    SELECT DATEADD(day, 1, DateValue)
    FROM DateSpine
    WHERE DateValue < CAST(@d2 AS date)
),

-- FastSale = 1, DEBIT dışı ödemeler
PayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        COUNT(*)                 AS TotalPaymentCount,
        SUM(CashPayment)         AS CashPayment,
        SUM(CreditPayment)       AS CreditPayment,
        SUM(TicketPayment)       AS TicketPayment,
        SUM(OnlinePayment)       AS OnlinePayment,
        SUM(Discount)            AS Discount,
        SUM(Debit)               AS Debit
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 1
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- DEBIT tahsilatları (Debit=0)
DebitPayAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS DebitPayment_CashPayment,
        SUM(CreditPayment)        AS DebitPayment_CreditPayment,
        SUM(TicketPayment)        AS DebitPayment_TicketPayment,
        SUM(Discount)             AS DebitPayment_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND TableNo = 'DEBIT' AND Debit = 0
    GROUP BY CAST(PaymentTime AS date)
),

-- FastSale = 0, DEBIT dışı tahsilatlar
CollectAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CashPayment)          AS Collect_CashPayment,
        SUM(CreditPayment)        AS Collect_CreditPayment,
        SUM(TicketPayment)        AS Collect_TicketPayment,
        SUM(OnlinePayment)        AS Collect_OnlinePayment,
        SUM(Discount)             AS Collect_Discount
    FROM Payment WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
      AND ISNULL(FastSale,0) = 0
      AND TableNo <> 'DEBIT'
    GROUP BY CAST(PaymentTime AS date)
),

-- PaidBill üzerinden ücretsiz/iadeler
PaidAgg AS (
    SELECT 
        CAST(PaymentTime AS date) AS DateValue,
        SUM(CASE WHEN ISNULL(Price,0)=0 THEN OriginalPrice * Quantity ELSE 0 END)                        AS Free,
        SUM(CASE WHEN FastSale=1 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS ResReturnItems,
        SUM(CASE WHEN FastSale=0 AND ISNULL(Quantity,0)<0 THEN OriginalPrice * ABS(Quantity) ELSE 0 END) AS PakReturnItems
    FROM PaidBill WITH (NOLOCK)
    WHERE PaymentTime >= @d1 AND PaymentTime < @d2
    GROUP BY CAST(PaymentTime AS date)
),

-- Silinen kalemler
DeletedAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM(OriginalPrice * Quantity) AS Canceled
    FROM DeletedBill WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
),

-- Direkt kasa işlemleri
DirectTxnAgg AS (
    SELECT 
        CAST([Date] AS date) AS DateValue,
        SUM([Total])         AS DirectTransaction_CashPayment
    FROM DirectTransaction WITH (NOLOCK)
    WHERE [Date] >= @d1 AND [Date] < @d2
    GROUP BY CAST([Date] AS date)
)

SELECT 
    ds.DateValue                                         AS [Date],
    ISNULL(p.TotalPaymentCount,0)                        AS TotalPaymentCount,
    ISNULL(p.CashPayment,0)                              AS CashPayment,
    ISNULL(p.CreditPayment,0)                            AS CreditPayment,
    ISNULL(p.TicketPayment,0)                            AS TicketPayment,
    ISNULL(p.OnlinePayment,0)                            AS OnlinePayment,
    ISNULL(p.Discount,0)                                 AS Discount,
    ISNULL(p.Debit,0)                                    AS Debit,
    ISNULL(pb.Free,0)                                    AS Free,
    ISNULL(pb.ResReturnItems,0)                          AS ResReturnItems,
    ISNULL(dlt.Canceled,0)                               AS Cancelled,
    ISNULL(dp.DebitPayment_CashPayment,0)                AS DebitPayment_CashPayment,
    ISNULL(dp.DebitPayment_CreditPayment,0)              AS DebitPayment_CreditPayment,
    ISNULL(dp.DebitPayment_Discount,0)                   AS DebitPayment_Discount,
    ISNULL(dp.DebitPayment_TicketPayment,0)              AS DebitPayment_TicketPayment,
    ISNULL(col.Collect_CashPayment,0)                    AS Collect_CashPayment,
    ISNULL(col.Collect_CreditPayment,0)                  AS Collect_CreditPayment,
    ISNULL(col.Collect_Discount,0)                       AS Collect_Discount,
    ISNULL(col.Collect_TicketPayment,0)                  AS Collect_TicketPayment,
    ISNULL(col.Collect_OnlinePayment,0)                  AS Collect_OnlinePayment,
    ISNULL(pb.PakReturnItems,0)                          AS PakReturnItems,
    ISNULL(dt.DirectTransaction_CashPayment,0)           AS DirectTransaction_CashPayment
FROM DateSpine ds
LEFT JOIN PayAgg       p   ON p.DateValue   = ds.DateValue
LEFT JOIN DebitPayAgg  dp  ON dp.DateValue  = ds.DateValue
LEFT JOIN CollectAgg   col ON col.DateValue = ds.DateValue
LEFT JOIN PaidAgg      pb  ON pb.DateValue  = ds.DateValue
LEFT JOIN DeletedAgg   dlt ON dlt.DateValue = ds.DateValue
LEFT JOIN DirectTxnAgg dt  ON dt.DateValue  = ds.DateValue
OPTION (MAXRECURSION 366) -- en fazla 366 gün (yani bir yıl civarı);

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:26:11
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:dc46f12f-3340-40c7-9682-44a346e9b7df
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_071';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:26:12
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:d0f84e9c-f16f-49fa-848a-b8acc79de63e
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_072';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:26:22
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:58acf3c3-8bc1-4193-bab6-8a4d89a7285a
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_073';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:26:32
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:cdbe19a7-15eb-45fa-a2ee-80f1bd7d64e9
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_074';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:26:42
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:08d7a0b7-7613-4be1-8b05-02f79b7b6ec5
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_075';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:27:17
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:7f58dc32-90ad-444d-a87d-67da1633047c
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_071';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:27:18
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:3464283d-1dda-4514-957c-3c90379d0ba4
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_072';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:27:28
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:c65c089a-b50b-48c8-ba18-8b64e0d04809
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_073';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:27:38
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:4b343eed-4c15-4a31-829e-25b483bb75bb
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_074';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:27:48
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:e8cbd381-ee66-489e-a391-b48a6932074c
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_075';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:45:35
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:abeb2dad-25ff-4ce2-afe2-ddc1221aef34
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_071';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:45:35
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:5de76458-0449-4d6c-bd31-b8543f468f75
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_072';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:45:45
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:17ee8ddb-f4ef-4ee8-8374-d21de3c10cf5
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_073';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:45:55
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:235f6bec-9880-46fe-918a-7e665fa8ea16
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_074';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:46:05
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:569c801a-bc8f-4000-bad0-5e90bcd65180
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_075';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:46:48
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:98e47b97-62e5-4462-9429-aa4e7480a05b
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_071';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:46:48
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:3415863f-76b0-4c1f-99c6-c774ca32631f
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_072';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:46:58
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:99fe7665-a12b-4efd-9006-ecd1f25a1044
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_073';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:47:08
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:09c789ff-70c8-4a02-896c-59aacb1dcd6d
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_074';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 26.09.2025 11:47:18
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:3a646c7d-76be-4c39-bc93-e5b3b0b93fd7
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 
declare @Sube nvarchar(100) = 'denizli_075';
declare @Trh1 nvarchar(20) = '2025.07.26 00:00:00';
declare @Trh2 nvarchar(20) = '2025.09.26 00:00:00';

WITH Toplamsatis 
AS ( 
SELECT 
@Sube as Sube, 
0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan,
ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%' OR PaidBill.Zayi=1)  
and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
and ISNULL(Price,0) <= 0.1

UNION ALL 

SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 AS Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
from BillWithHeader WITH (NOLOCK)
where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


UNION ALL 
SELECT 
@Sube as Sube, 
ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,sum(Amount) as Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 as Bakiye,sum(Amount) as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaymentDetails  WITH (NOLOCK)
WHERE 
PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 
UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--and  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM Payment WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
--nd  ISNULL(FastSale,0)=1

UNION ALL 

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM PaidBill WITH (NOLOCK)
WHERE 
Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price<=0.1 and ProductName Not Like '$%'
and (PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%' OR PaidBill.Ikram = 1)

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 AS iade,0 AS pakettoplam
FROM DeletedBill WITH (NOLOCK)
WHERE 
DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

UNION ALL
SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) AS iade ,0 AS pakettoplam
from PaidBill WITH (NOLOCK)

WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

UNION ALL

SELECT 
@Sube as Sube, 
0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo,

((SELECT SUM(Discount)   FROM PhoneOrderHeader WITH (NOLOCK)
WHERE 
PhoneOrderHeader.CreationTime>=@Trh1 AND 
PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

0 AS iptal,0 AS Bakiye, 0 as Puan, 0 AS zayi, 0 AS iade,

((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) AS pakettoplam

FROM PhoneOrderHeader D WITH (NOLOCK)
JOIN Bill B ON B.HeaderId = D .HeaderId
WHERE  
D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

) 
SELECT Sube 
,SUM(Cash) AS Cash 
,SUM(Credit) AS Credit 
,Sum(Ticket) AS Ticket 
,Sum(OnlinePayment) AS OnlinePayment
,SUM(PaketToplam) as PaketToplam
,Sum(Debit) AS Debit 
,Sum(ikram) AS ikram 
,Sum(AcikMasalar) AS AcikMasalar 
,SUM(Bakiye) AS Bakiye
,SUM(Puan) AS PUAN
,Sum(TableNo) AS TableNo 
,Sum(Discount) AS Discount 
,Sum(iptal) AS iptal 
,Sum(iade) AS iade 
,Sum(Zayi) AS Zayi
,SUM(Cash+Credit+Ticket+Debit+Bakiye+OnlinePayment) AS ToplamCiro
,0 AS Saniye
,'' AS RowStyle
,'' AS RowError
FROM toplamsatis  
GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye,0 as Puan,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,0 as Puan,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,sum(Amount) as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='BAKIYE' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal,sum(Amount) as Puan,0 as Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaymentDetails 
--WHERE 
--PaymentDetail='PUAN' AND Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo) as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,0 as Puan,
--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal,0 AS Bakiye,0 as Puan, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Puan,

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal,0 AS Bakiye, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 



--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,SUM(Bakiye) AS Bakiye
--,SUM(Puan) AS PUAN
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+Bakiye) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube


--WITH Toplamsatis 
--AS ( 
--SELECT 
--@Sube as Sube, 
--0 AS Cash, 0 AS Credit, 0 AS Ticket,0 AS OnlinePayment, 0 AS Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal,
--ISNULL(Sum(Quantity * OriginalPrice),0) AS zayi , 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--(PaidBill.Comment  LIKE  '%zayi%' or PaidBill.Comment LIKE '%ZAYI%')   
--and PaidBill.PaymentTime >= @Trh1 and PaidBill.PaymentTime <= @Trh2
--and ISNULL(Price,0) = 0

--UNION 

--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket,ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 AS TableNo, 0 AS Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and ISNULL(FastSale,0)=0 and Payment.TableNo<>'DEBIT' 


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment,
--0 as Debit, 0 AS ikram, sum(quantity*price) AS  AcikMasalar,0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--from BillWithHeader where BillState=0 AND ISNULL(BillType,0) IN (0,1)  and  [Date]>=@Trh1 AND [Date]<=@Trh2


--UNION 
--SELECT 
--@Sube as Sube, 
--ISNULL(Sum(CashPayment),0) as Cash, ISNULL(Sum(CreditPayment),0) as Credit, ISNULL(Sum(TicketPayment),0) as Ticket, ISNULL(Sum(OnlinePayment),0) as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1  and Payment.TableNo<>'DEBIT' 
 

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 as OnlinePayment, --ISNULL(Sum(OnlinePayment),0) as OnlinePayment, 06.04.2022 yorum satırına alındı.
--0 as Debit, 0 AS ikram,0 as AcikMasalar, Count(TableNo)-(SELECT 
--Count(TableNo) as TableNo
--FROM  Payment where PaymentTime>=@Trh1 and  PaymentTime<=@Trh2
--and  (ISNULL(CashPayment,0)<0 OR ISNULL(TicketPayment,0)<0 OR ISNULL(CreditPayment,0)<0 OR ISNULL(OnlinePayment,0)<0 OR ISNULL(Debit,0)<0 OR ISNULL(Discount,0)<0)
--) as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and  ISNULL(FastSale,0)=1 AND ISNULL(TableNo,'')<>'DEBIT'


--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--ISNULL(Sum(Debit),0) as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----and  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash,0 as Credit, 0 as Ticket, 0 as OnlinePayment,
--0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, ISNULL(Sum(Discount),0) as Discount,
--0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM Payment
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 
----nd  ISNULL(FastSale,0)=1

--UNION 

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, ISNULL(Sum(Quantity*OriginalPrice),0) AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM PaidBill
--WHERE 
--Paymenttime >= @Trh1 AND Paymenttime <= @Trh2 and Price=0 and ProductName Not Like '$%'
--and PaidBill.Comment not LIKE '%ZAYi%' and PaidBill.Comment not LIKE '%ZAYI%'

--UNION

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, ISNULL(Sum(Quantity*OriginalPrice),0) AS iptal, 0 AS zayi, 0 iade,0 pakettoplam
--FROM DeletedBill
--WHERE 
--DeletingTime >= @Trh1 AND DeletingTime <= @Trh2 and ProductName Not Like '$%'

--UNION
--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 0 as Discount, 0 AS iptal, 0 AS zayi, Sum(Quantity*(-OriginalPrice)) iade ,0 pakettoplam
--from PaidBill 

--WHERE [PaymentTime]>=@Trh1 AND [PaymentTime]<=@Trh2 AND ISNULL(Quantity,0)<0

--UNION ALL

--SELECT 
--@Sube as Sube, 
--0 as Cash, 0 as Credit, 0 as Ticket,0 AS OnlinePayment, 0 as Debit, 0 AS ikram,0 as AcikMasalar, 0 as TableNo, 

--((SELECT SUM(Discount)   FROM PhoneOrderHeader 
--WHERE 
--PhoneOrderHeader.CreationTime>=@Trh1 AND 
--PhoneOrderHeader.CreationTime<=@Trh2)) as Discount, 

--0 AS iptal, 0 AS zayi, 0 iade,

--((SUM(ISNULL(B.Price,0)*ISNULL(B.Quantity,0))) ) pakettoplam

--FROM PhoneOrderHeader D
--JOIN Bill B ON B.HeaderId = D .HeaderId
--WHERE  
--D .CreationTime>=@Trh1 AND  D .CreationTime<=@Trh2 

--) 
--SELECT Sube 
--,SUM(Cash) AS Cash 
--,SUM(Credit) AS Credit 
--,Sum(Ticket) AS Ticket 
--,Sum(OnlinePayment) AS OnlinePayment
--,SUM(PaketToplam) as PaketToplam
--,Sum(Debit) AS Debit 
--,Sum(ikram) AS ikram 
--,Sum(AcikMasalar) AS AcikMasalar 
--,Sum(TableNo) AS TableNo 
--,Sum(Discount) AS Discount 
--,Sum(iptal) AS iptal 
--,Sum(iade) AS iade 
--,Sum(Zayi) AS Zayi
--,SUM(Cash+Credit+Ticket+Debit+OnlinePayment) AS ToplamCiro
--,0 AS Saniye
--,'' AS RowStyle
--,'' AS RowError
--FROM toplamsatis  
--GROUP BY Sube
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:28
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:6e69cb57-250f-4473-94fd-67de343ad9ac
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:38
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:3c141ab1-2067-4ea5-8586-bf2d0ee1796b
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: SELECT CASE 
                                                    WHEN EXISTS (
                                                        SELECT 1
                                                        FROM INFORMATION_SCHEMA.COLUMNS
                                                        WHERE TABLE_NAME = 'Product' AND COLUMN_NAME = 'StockCode'
                                                    ) THEN 1 
                                                    ELSE 0 
                                                END AS StockCodeExists
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:39
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:f8259df7-4947-4afd-af2e-131e3c7d8853
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: SELECT CASE 
                                                    WHEN EXISTS (
                                                        SELECT 1
                                                        FROM INFORMATION_SCHEMA.COLUMNS
                                                        WHERE TABLE_NAME = 'Product' AND COLUMN_NAME = 'StockCode'
                                                    ) THEN 1 
                                                    ELSE 0 
                                                END AS StockCodeExists
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:39
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:eefefb0e-a16b-4a8c-b855-5ffb7711d50d
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: SELECT CASE 
                                                    WHEN EXISTS (
                                                        SELECT 1
                                                        FROM INFORMATION_SCHEMA.COLUMNS
                                                        WHERE TABLE_NAME = 'Product' AND COLUMN_NAME = 'StockCode'
                                                    ) THEN 1 
                                                    ELSE 0 
                                                END AS StockCodeExists
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:48
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:68d45abd-dd19-4f16-a52a-726cfbfc53b8
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: DECLARE @par1 nvarchar(20) = '2025.10.21 05:00:00';
DECLARE @par2 nvarchar(20) = '2025.10.21 07:00:00';

WITH base as (
SELECT
	PaymentTime,
	Quantity,
	LTRIM(RTRIM(split.s)) AS Opt,
	ProductId
FROM
	dbo.PaidBill
CROSS APPLY
	dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) as split
WHERE
	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
	),
base_with_optqty as (
SELECT 
	base.PaymentTime,
	base.Quantity,
	ProductId,
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
	ELSE
		'1'
	END AS OptQty,
	
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
	ELSE
		base.Opt
	END AS Opt	
FROM 
	base),
	
satislar as (	
SELECT	
	PaymentTime,
	ProductId,
	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
	Opt as ProductName
from
	base_with_optqty	where Opt Not Like '$%' 
)
select 

* from (

SELECT 

sum(Quantity) as MIKTAR,
ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
NULL as ProductCode,
0 as TUTAR,
0 as INDIRIM,
0 as IKRAM
from  satislar
group by satislar.ProductName

UNION

select 
sum(t.toplam) as MIKTAR,
t.ProductName,
t.ProductCode,
sum(t.tutar) as TUTAR,
SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
SUM(IKRAM) IKRAM

from 

(
SELECT 
P.Id as ProductId,
P.ProductCode,
SUM(B.Quantity) AS Toplam,
B.ProductName,
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,
0 as INDIRIM,
0 PAKETINDIRIM,
0 IKRAM
  FROM dbo.Bill AS B
LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
p.Id,
P.ProductCode


UNION ALL

SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar, 
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
(SUM(ISNULL(Discount,0))  / 
CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,
0 PAKETINDIRIM,
Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.Quantity*B.OriginalPrice,0))) Else 0 End  IKRAM
  FROM dbo.Payment AS P
LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode


UNION ALL
SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar,
0 INDIRIM,
SUM(b.Quantity*b.Price)*
(  avg(ISNULL(ph.Discount,0))/ ( SELECT case when  SUM(Quantity*Price)=0 then 1 else SUM(Quantity*Price) end   FROM Bill where HeaderId=B.HeaderId )) PAKETINDIRIM,
0 IKRAM
  FROM  dbo.PhoneOrderHeader as PH
LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode

)   as t

group by
t.ProductName,
t.ProductCode) as a 
WHERE NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%'
order by
a.ProductName

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:49
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:0b6ac5f5-b996-45f0-b5e2-25d12b143a0d
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: DECLARE @par1 nvarchar(20) = '2025.10.21 05:00:00';
DECLARE @par2 nvarchar(20) = '2025.10.21 07:00:00';

WITH base as (
SELECT
	PaymentTime,
	Quantity,
	LTRIM(RTRIM(split.s)) AS Opt,
	ProductId
FROM
	dbo.PaidBill
CROSS APPLY
	dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) as split
WHERE
	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
	),
base_with_optqty as (
SELECT 
	base.PaymentTime,
	base.Quantity,
	ProductId,
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
	ELSE
		'1'
	END AS OptQty,
	
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
	ELSE
		base.Opt
	END AS Opt	
FROM 
	base),
	
satislar as (	
SELECT	
	PaymentTime,
	ProductId,
	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
	Opt as ProductName
from
	base_with_optqty	where Opt Not Like '$%' 
)
select 

* from (

SELECT 

sum(Quantity) as MIKTAR,
ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
NULL as ProductCode,
0 as TUTAR,
0 as INDIRIM,
0 as IKRAM
from  satislar
group by satislar.ProductName

UNION

select 
sum(t.toplam) as MIKTAR,
t.ProductName,
t.ProductCode,
sum(t.tutar) as TUTAR,
SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
SUM(IKRAM) IKRAM

from 

(
SELECT 
P.Id as ProductId,
P.ProductCode,
SUM(B.Quantity) AS Toplam,
B.ProductName,
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,
0 as INDIRIM,
0 PAKETINDIRIM,
0 IKRAM
  FROM dbo.Bill AS B
LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
p.Id,
P.ProductCode


UNION ALL

SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar, 
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
(SUM(ISNULL(Discount,0))  / 
CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,
0 PAKETINDIRIM,
Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.Quantity*B.OriginalPrice,0))) Else 0 End  IKRAM
  FROM dbo.Payment AS P
LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode


UNION ALL
SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar,
0 INDIRIM,
SUM(b.Quantity*b.Price)*
(  avg(ISNULL(ph.Discount,0))/ ( SELECT case when  SUM(Quantity*Price)=0 then 1 else SUM(Quantity*Price) end   FROM Bill where HeaderId=B.HeaderId )) PAKETINDIRIM,
0 IKRAM
  FROM  dbo.PhoneOrderHeader as PH
LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode

)   as t

group by
t.ProductName,
t.ProductCode) as a 
WHERE NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%'
order by
a.ProductName

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:58
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_072" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:35c30491-c887-480d-ad5c-dbb858a953f7
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 

declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';


--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
  newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', B.Options) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,sum(Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
	,HeaderId
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,HeaderId
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    ,optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / NULLIF(sum(Quantity * Price), 0) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 ISNULL(ph.discount, 0) / NULLIF((
  SELECT sum(Quantity * Price)
  FROM bill b2
  WHERE b2.HeaderId = ph.HeaderId
), 0) pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
	,HeaderId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) = 0 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND b.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

  ,base2 as  (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,HeaderId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup,HeaderId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,HeaderId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
	,HeaderId

  ) 


SELECT
    SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN 1 ELSE 0 END) AS YemekSepetiMiktar,
	SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [YemekSepetiTutar],

    SUM(CASE WHEN Deliverer = 'GETIR' THEN 1 ELSE 0 END) AS GetirMiktar,
	SUM(CASE WHEN Deliverer = 'GETIR' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [GetirTutar],

    SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN 1 ELSE 0 END) AS MigrosMiktar,
	SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [MigrosTutar],

    SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN 1 ELSE 0 END) AS TrendyolMiktar,
	SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TrendyolTutar],

    SUM(CASE WHEN Deliverer = 'TELEFON' THEN 1 ELSE 0 END) AS TelefonMiktar,
	 SUM(CASE WHEN Deliverer = 'TELEFON' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TelefonTutar]


	


FROM (
    SELECT
        1 AS SAY,
        TrackingNumber,
        CASE 
            WHEN TrackingNumber LIKE 'ty_%' THEN 'TRENDYOL'
            WHEN TrackingNumber LIKE 'gt_%' THEN 'GETIR'
            WHEN TrackingNumber LIKE 'my_%' THEN 'MIGROSYEMEK'
            WHEN ISNULL(TrackingNumber, '') <> '' 
                 AND TrackingNumber NOT LIKE 'ty_%' 
                 AND TrackingNumber NOT LIKE 'gt_%' 
                 AND TrackingNumber NOT LIKE 'my_%' THEN 'YEMEKSEPETI'
            ELSE 'TELEFON' 
        END AS Deliverer
		 ,Sum(TUTAR) TUTAR
		 ,SUM(INDIRIM) INDIRIM
    FROM PhoneOrderHeader po
    LEFT JOIN base2 b2 ON po.HeaderId = b2.HeaderId
    WHERE MIKTAR <> 0 
    AND ( NULL IS NULL OR b2.ProductName LIKE '%' + NULL + '%' ) --servisten setliyoruz, productname ile arama için
    GROUP BY TrackingNumber, po.Id
) T
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:59
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_073" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:e4fe35d3-ac9d-440e-8c4e-d757c0e1caad
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 

declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';


--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
  newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', B.Options) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,sum(Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
	,HeaderId
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,HeaderId
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    ,optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / NULLIF(sum(Quantity * Price), 0) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 ISNULL(ph.discount, 0) / NULLIF((
  SELECT sum(Quantity * Price)
  FROM bill b2
  WHERE b2.HeaderId = ph.HeaderId
), 0) pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
	,HeaderId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) = 0 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND b.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

  ,base2 as  (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,HeaderId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup,HeaderId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,HeaderId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
	,HeaderId

  ) 


SELECT
    SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN 1 ELSE 0 END) AS YemekSepetiMiktar,
	SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [YemekSepetiTutar],

    SUM(CASE WHEN Deliverer = 'GETIR' THEN 1 ELSE 0 END) AS GetirMiktar,
	SUM(CASE WHEN Deliverer = 'GETIR' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [GetirTutar],

    SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN 1 ELSE 0 END) AS MigrosMiktar,
	SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [MigrosTutar],

    SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN 1 ELSE 0 END) AS TrendyolMiktar,
	SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TrendyolTutar],

    SUM(CASE WHEN Deliverer = 'TELEFON' THEN 1 ELSE 0 END) AS TelefonMiktar,
	 SUM(CASE WHEN Deliverer = 'TELEFON' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TelefonTutar]


	


FROM (
    SELECT
        1 AS SAY,
        TrackingNumber,
        CASE 
            WHEN TrackingNumber LIKE 'ty_%' THEN 'TRENDYOL'
            WHEN TrackingNumber LIKE 'gt_%' THEN 'GETIR'
            WHEN TrackingNumber LIKE 'my_%' THEN 'MIGROSYEMEK'
            WHEN ISNULL(TrackingNumber, '') <> '' 
                 AND TrackingNumber NOT LIKE 'ty_%' 
                 AND TrackingNumber NOT LIKE 'gt_%' 
                 AND TrackingNumber NOT LIKE 'my_%' THEN 'YEMEKSEPETI'
            ELSE 'TELEFON' 
        END AS Deliverer
		 ,Sum(TUTAR) TUTAR
		 ,SUM(INDIRIM) INDIRIM
    FROM PhoneOrderHeader po
    LEFT JOIN base2 b2 ON po.HeaderId = b2.HeaderId
    WHERE MIKTAR <> 0 
    AND ( NULL IS NULL OR b2.ProductName LIKE '%' + NULL + '%' ) --servisten setliyoruz, productname ile arama için
    GROUP BY TrackingNumber, po.Id
) T
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:00:59
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_071" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:b714459a-a2d8-4638-83a0-712e6f7a9c6a
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 

declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';


--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
  newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', B.Options) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,sum(Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
	,HeaderId
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,HeaderId
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    ,optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / NULLIF(sum(Quantity * Price), 0) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 ISNULL(ph.discount, 0) / NULLIF((
  SELECT sum(Quantity * Price)
  FROM bill b2
  WHERE b2.HeaderId = ph.HeaderId
), 0) pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
	,HeaderId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) = 0 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND b.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

  ,base2 as  (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,HeaderId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup,HeaderId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,HeaderId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
	,HeaderId

  ) 


SELECT
    SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN 1 ELSE 0 END) AS YemekSepetiMiktar,
	SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [YemekSepetiTutar],

    SUM(CASE WHEN Deliverer = 'GETIR' THEN 1 ELSE 0 END) AS GetirMiktar,
	SUM(CASE WHEN Deliverer = 'GETIR' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [GetirTutar],

    SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN 1 ELSE 0 END) AS MigrosMiktar,
	SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [MigrosTutar],

    SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN 1 ELSE 0 END) AS TrendyolMiktar,
	SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TrendyolTutar],

    SUM(CASE WHEN Deliverer = 'TELEFON' THEN 1 ELSE 0 END) AS TelefonMiktar,
	 SUM(CASE WHEN Deliverer = 'TELEFON' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TelefonTutar]


	


FROM (
    SELECT
        1 AS SAY,
        TrackingNumber,
        CASE 
            WHEN TrackingNumber LIKE 'ty_%' THEN 'TRENDYOL'
            WHEN TrackingNumber LIKE 'gt_%' THEN 'GETIR'
            WHEN TrackingNumber LIKE 'my_%' THEN 'MIGROSYEMEK'
            WHEN ISNULL(TrackingNumber, '') <> '' 
                 AND TrackingNumber NOT LIKE 'ty_%' 
                 AND TrackingNumber NOT LIKE 'gt_%' 
                 AND TrackingNumber NOT LIKE 'my_%' THEN 'YEMEKSEPETI'
            ELSE 'TELEFON' 
        END AS Deliverer
		 ,Sum(TUTAR) TUTAR
		 ,SUM(INDIRIM) INDIRIM
    FROM PhoneOrderHeader po
    LEFT JOIN base2 b2 ON po.HeaderId = b2.HeaderId
    WHERE MIKTAR <> 0 
    AND ( NULL IS NULL OR b2.ProductName LIKE '%' + NULL + '%' ) --servisten setliyoruz, productname ile arama için
    GROUP BY TrackingNumber, po.Id
) T
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:09
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:bcd6e127-8a31-4cc8-9e6a-7f1a297aa22d
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: SELECT CASE 
                                                    WHEN EXISTS (
                                                        SELECT 1
                                                        FROM INFORMATION_SCHEMA.COLUMNS
                                                        WHERE TABLE_NAME = 'Product' AND COLUMN_NAME = 'StockCode'
                                                    ) THEN 1 
                                                    ELSE 0 
                                                END AS StockCodeExists
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:19
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:5eec4623-0c63-477e-95d1-c35e3bec3c69
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: DECLARE @par1 nvarchar(20) = '2025.10.21 05:00:00';
DECLARE @par2 nvarchar(20) = '2025.10.21 07:00:00';

WITH base as (
SELECT
	PaymentTime,
	Quantity,
	LTRIM(RTRIM(split.s)) AS Opt,
	ProductId
FROM
	dbo.PaidBill
CROSS APPLY
	dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) as split
WHERE
	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
	),
base_with_optqty as (
SELECT 
	base.PaymentTime,
	base.Quantity,
	ProductId,
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
	ELSE
		'1'
	END AS OptQty,
	
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
	ELSE
		base.Opt
	END AS Opt	
FROM 
	base),
	
satislar as (	
SELECT	
	PaymentTime,
	ProductId,
	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
	Opt as ProductName
from
	base_with_optqty	where Opt Not Like '$%' 
)
select 

* from (

SELECT 

sum(Quantity) as MIKTAR,
ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
NULL as ProductCode,
0 as TUTAR,
0 as INDIRIM,
0 as IKRAM
from  satislar
group by satislar.ProductName

UNION

select 
sum(t.toplam) as MIKTAR,
t.ProductName,
t.ProductCode,
sum(t.tutar) as TUTAR,
SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
SUM(IKRAM) IKRAM

from 

(
SELECT 
P.Id as ProductId,
P.ProductCode,
SUM(B.Quantity) AS Toplam,
B.ProductName,
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,
0 as INDIRIM,
0 PAKETINDIRIM,
0 IKRAM
  FROM dbo.Bill AS B
LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
p.Id,
P.ProductCode


UNION ALL

SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar, 
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
(SUM(ISNULL(Discount,0))  / 
CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,
0 PAKETINDIRIM,
Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.Quantity*B.OriginalPrice,0))) Else 0 End  IKRAM
  FROM dbo.Payment AS P
LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode


UNION ALL
SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar,
0 INDIRIM,
SUM(b.Quantity*b.Price)*
(  avg(ISNULL(ph.Discount,0))/ ( SELECT case when  SUM(Quantity*Price)=0 then 1 else SUM(Quantity*Price) end   FROM Bill where HeaderId=B.HeaderId )) PAKETINDIRIM,
0 IKRAM
  FROM  dbo.PhoneOrderHeader as PH
LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode

)   as t

group by
t.ProductName,
t.ProductCode) as a 
WHERE NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%'
order by
a.ProductName

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:29
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_074" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:f31e3176-1dba-4375-a027-706d5775a72e
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 

declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';


--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
  newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', B.Options) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,sum(Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
	,HeaderId
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,HeaderId
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    ,optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / NULLIF(sum(Quantity * Price), 0) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 ISNULL(ph.discount, 0) / NULLIF((
  SELECT sum(Quantity * Price)
  FROM bill b2
  WHERE b2.HeaderId = ph.HeaderId
), 0) pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
	,HeaderId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) = 0 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND b.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

  ,base2 as  (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,HeaderId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup,HeaderId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,HeaderId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
	,HeaderId

  ) 


SELECT
    SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN 1 ELSE 0 END) AS YemekSepetiMiktar,
	SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [YemekSepetiTutar],

    SUM(CASE WHEN Deliverer = 'GETIR' THEN 1 ELSE 0 END) AS GetirMiktar,
	SUM(CASE WHEN Deliverer = 'GETIR' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [GetirTutar],

    SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN 1 ELSE 0 END) AS MigrosMiktar,
	SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [MigrosTutar],

    SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN 1 ELSE 0 END) AS TrendyolMiktar,
	SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TrendyolTutar],

    SUM(CASE WHEN Deliverer = 'TELEFON' THEN 1 ELSE 0 END) AS TelefonMiktar,
	 SUM(CASE WHEN Deliverer = 'TELEFON' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TelefonTutar]


	


FROM (
    SELECT
        1 AS SAY,
        TrackingNumber,
        CASE 
            WHEN TrackingNumber LIKE 'ty_%' THEN 'TRENDYOL'
            WHEN TrackingNumber LIKE 'gt_%' THEN 'GETIR'
            WHEN TrackingNumber LIKE 'my_%' THEN 'MIGROSYEMEK'
            WHEN ISNULL(TrackingNumber, '') <> '' 
                 AND TrackingNumber NOT LIKE 'ty_%' 
                 AND TrackingNumber NOT LIKE 'gt_%' 
                 AND TrackingNumber NOT LIKE 'my_%' THEN 'YEMEKSEPETI'
            ELSE 'TELEFON' 
        END AS Deliverer
		 ,Sum(TUTAR) TUTAR
		 ,SUM(INDIRIM) INDIRIM
    FROM PhoneOrderHeader po
    LEFT JOIN base2 b2 ON po.HeaderId = b2.HeaderId
    WHERE MIKTAR <> 0 
    AND ( NULL IS NULL OR b2.ProductName LIKE '%' + NULL + '%' ) --servisten setliyoruz, productname ile arama için
    GROUP BY TrackingNumber, po.Id
) T
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:39
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:61a4794f-82ff-41f4-aec4-55ada7dcea53
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: SELECT CASE 
                                                    WHEN EXISTS (
                                                        SELECT 1
                                                        FROM INFORMATION_SCHEMA.COLUMNS
                                                        WHERE TABLE_NAME = 'Product' AND COLUMN_NAME = 'StockCode'
                                                    ) THEN 1 
                                                    ELSE 0 
                                                END AS StockCodeExists
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:49
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:a37a94d6-331a-460c-8061-37687f8410a8
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: DECLARE @par1 nvarchar(20) = '2025.10.21 05:00:00';
DECLARE @par2 nvarchar(20) = '2025.10.21 07:00:00';

WITH base as (
SELECT
	PaymentTime,
	Quantity,
	LTRIM(RTRIM(split.s)) AS Opt,
	ProductId
FROM
	dbo.PaidBill
CROSS APPLY
	dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) as split
WHERE
	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
	),
base_with_optqty as (
SELECT 
	base.PaymentTime,
	base.Quantity,
	ProductId,
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
	ELSE
		'1'
	END AS OptQty,
	
	CASE 
		WHEN CHARINDEX('x',base.Opt) > 0 THEN
		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
	ELSE
		base.Opt
	END AS Opt	
FROM 
	base),
	
satislar as (	
SELECT	
	PaymentTime,
	ProductId,
	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
	Opt as ProductName
from
	base_with_optqty	where Opt Not Like '$%' 
)
select 

* from (

SELECT 

sum(Quantity) as MIKTAR,
ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
NULL as ProductCode,
0 as TUTAR,
0 as INDIRIM,
0 as IKRAM
from  satislar
group by satislar.ProductName

UNION

select 
sum(t.toplam) as MIKTAR,
t.ProductName,
t.ProductCode,
sum(t.tutar) as TUTAR,
SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
SUM(IKRAM) IKRAM

from 

(
SELECT 
P.Id as ProductId,
P.ProductCode,
SUM(B.Quantity) AS Toplam,
B.ProductName,
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,
0 as INDIRIM,
0 PAKETINDIRIM,
0 IKRAM
  FROM dbo.Bill AS B
LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
p.Id,
P.ProductCode


UNION ALL

SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar, 
SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
(SUM(ISNULL(Discount,0))  / 
CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,
0 PAKETINDIRIM,
Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.Quantity*B.OriginalPrice,0))) Else 0 End  IKRAM
  FROM dbo.Payment AS P
LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode


UNION ALL
SELECT 
PR.Id as ProductId,
PR.ProductCode,
0 AS Toplam,
B.ProductName,
0 AS Tutar,
0 INDIRIM,
SUM(b.Quantity*b.Price)*
(  avg(ISNULL(ph.Discount,0))/ ( SELECT case when  SUM(Quantity*Price)=0 then 1 else SUM(Quantity*Price) end   FROM Bill where HeaderId=B.HeaderId )) PAKETINDIRIM,
0 IKRAM
  FROM  dbo.PhoneOrderHeader as PH
LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
WHERE
[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
GROUP BY B.ProductName,
B.HeaderId,
PR.Id,
PR.ProductCode

)   as t

group by
t.ProductName,
t.ProductCode) as a 
WHERE NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%'
order by
a.ProductName

-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:01:59
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): Cannot open database "denizlipdb_075" requested by the login. The login failed.
Login failed for user 'sa'.
   konum: System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   konum: System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   konum: System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   konum: System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   konum: System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   konum: System.Data.SqlClient.SqlConnection.Open()
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 32
ClientConnectionId:f3228de4-54f1-43c0-9635-706f05414957
Error Number:4060,State:1,Class:11
 Tarih Formatları 
InnerException: 

declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';


--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
  newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', B.Options) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,sum(Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
	,HeaderId
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,HeaderId
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    ,optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / NULLIF(sum(Quantity * Price), 0) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 ISNULL(ph.discount, 0) / NULLIF((
  SELECT sum(Quantity * Price)
  FROM bill b2
  WHERE b2.HeaderId = ph.HeaderId
), 0) pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
	,HeaderId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) = 0 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND b.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

  ,base2 as  (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,HeaderId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup,HeaderId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,HeaderId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
	,HeaderId

  ) 


SELECT
    SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN 1 ELSE 0 END) AS YemekSepetiMiktar,
	SUM(CASE WHEN Deliverer = 'YEMEKSEPETI' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [YemekSepetiTutar],

    SUM(CASE WHEN Deliverer = 'GETIR' THEN 1 ELSE 0 END) AS GetirMiktar,
	SUM(CASE WHEN Deliverer = 'GETIR' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [GetirTutar],

    SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN 1 ELSE 0 END) AS MigrosMiktar,
	SUM(CASE WHEN Deliverer = 'MIGROSYEMEK' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [MigrosTutar],

    SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN 1 ELSE 0 END) AS TrendyolMiktar,
	SUM(CASE WHEN Deliverer = 'TRENDYOL' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TrendyolTutar],

    SUM(CASE WHEN Deliverer = 'TELEFON' THEN 1 ELSE 0 END) AS TelefonMiktar,
	 SUM(CASE WHEN Deliverer = 'TELEFON' THEN ISNULL(TUTAR,0)-ISNULL(INDIRIM,0) ELSE 0 END) AS [TelefonTutar]


	


FROM (
    SELECT
        1 AS SAY,
        TrackingNumber,
        CASE 
            WHEN TrackingNumber LIKE 'ty_%' THEN 'TRENDYOL'
            WHEN TrackingNumber LIKE 'gt_%' THEN 'GETIR'
            WHEN TrackingNumber LIKE 'my_%' THEN 'MIGROSYEMEK'
            WHEN ISNULL(TrackingNumber, '') <> '' 
                 AND TrackingNumber NOT LIKE 'ty_%' 
                 AND TrackingNumber NOT LIKE 'gt_%' 
                 AND TrackingNumber NOT LIKE 'my_%' THEN 'YEMEKSEPETI'
            ELSE 'TELEFON' 
        END AS Deliverer
		 ,Sum(TUTAR) TUTAR
		 ,SUM(INDIRIM) INDIRIM
    FROM PhoneOrderHeader po
    LEFT JOIN base2 b2 ON po.HeaderId = b2.HeaderId
    WHERE MIKTAR <> 0 
    AND ( NULL IS NULL OR b2.ProductName LIKE '%' + NULL + '%' ) --servisten setliyoruz, productname ile arama için
    GROUP BY TrackingNumber, po.Id
) T
-----------------Log Bıtıs
-----------------Log Baslangıç
Hata Zamanı : 21.10.2025 09:03:05
Hata Mesajı : MdlFunctionsGetSubeDataWithQuery Hata Oluştu
Hata Açıklaması : System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "PaidBill.Options" could not be bound.
   konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   konum: System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   konum: System.Data.SqlClient.SqlDataReader.get_MetaData()
   konum: System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   konum: System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   konum: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   konum: System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   konum: System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   konum: SefimV2.ModelFunctions.GetSubeDataWithQuery(String conStr, String sqlText) C:\Users\eko\Desktop\Vega\VegaMasterPanelApp\SefimV2\Models\ModelFunctions\ModelFunctions.cs içinde: satır 39
ClientConnectionId:63ac9171-bcb1-4a9d-856f-4fcb7c66ee77
Error Number:4104,State:1,Class:16
 Tarih Formatları 
InnerException: 
declare @par1 nvarchar(20) = '2025.10.21 05:00:00';
declare @par2 nvarchar(20) = '2025.10.21 07:00:00';

--04.23
;WITH
ProEqu AS 
(
SELECT ISNULL(pq.ProductName, '') + ISNULL('.' + (
      SELECT name
      FROM Choice1 ch1
      WHERE ch1.Id = pq.choice1Id
      ), '') + ISNULL('.' + (
      SELECT name
      FROM Choice2 ch2
      WHERE ch2.Id = pq.choice2Id
      ), '') ProductName
  ,Multiplier
  ,EquProductName
FROM ProductEqu Pq
)
,optequ AS 
(
SELECT oq.ProductName
  ,(oq.ProductName + oq.Options) oqproname
  ,EquProduct
  ,miktar
  ,AnaUrun
FROM OptionsEqu oq
),
Base AS 
(
SELECT 
   newid() nid
  ,B.ProductId
  ,B.ProductName
  ,P.ProductName PName
  ,B.Date PaymentTime
  ,B.Quantity
    ,b.Options
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), CHARINDEX('x', LTRIM(RTRIM(O.s))) + 1, 100) ELSE LTRIM(RTRIM(O.s)) END AS Opt
  ,CASE WHEN CHARINDEX('x', LTRIM(RTRIM(O.s))) > 0 THEN SUBSTRING(LTRIM(RTRIM(O.s)), 1, CHARINDEX('x', LTRIM(RTRIM(O.s))) - 1) ELSE '1' END AS OptQty
  ,B.HeaderId
FROM Bill B
    LEFT JOIN Product P ON B.ProductId = P.Id
    CROSS APPLY dbo.SplitString(',', REPLACE(PaidBill.Options,'|',',')) AS O
WHERE ISNULL(B.Options, '') <> '' 
  AND B.Date BETWEEN @par1 AND @par2
  --and B.HeaderId=181336
),
BillPrice AS
(
SELECT
   Bp.ProductName
  ,Bp.Price
  ,Bp.MinDate
  ,Bp.Options
  ,CASE WHEN Bp.MaxDate=MAX(Bp.MaxDate) OVER(PARTITION BY Bp.ProductName) THEN GETDATE() ELSE Bp.MaxDate END MaxDate 
FROM
     (
      SELECT 
         ProductName
        ,Price
		,Options
        ,MIN(Date) MinDate
        ,MAX(Date) MaxDate 
      FROM Bill B 
	  	  where UserName='PAKET'
      GROUP BY ProductName,Price,Options
     ) Bp
),
OptSatislar AS
(
SELECT 
   Oe.EquProduct
  ,Oe.Miktar
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END) AS Quantity
  ,Opt AS OptionsName
  ,B.ProductName aaa
  ,ISNULL(Oe.EquProduct, opt) ProductName2
  ,case when ISNULL(Oe.MenuFiyat,0)=0 THEN  CASE WHEN oe.AnaUrun=1 THEN MAX(Bp.Price) ELSE ISNULL(Oe.MenuFiyat,0) END ELSE ISNULL(Oe.MenuFiyat,0) END  MenuFiyat
FROM Base B
     LEFT JOIN OptionsEqu Oe On Oe.ProductName+Oe.Options=B.PName+ISNULL(B.Opt, '')
     LEFT JOIN BillPrice Bp On B.ProductName+ISNULL(b.Options,'')=Bp.ProductName +ISNULL(bp.Options,'')
	  AND B.PaymentTime BETWEEN Bp.MinDate and Bp.MaxDate
	 	 	  where (select top 1 Category from Options where [name]=b.Opt) <>'RAPORDISI' OR  (opt not like '%istemiyorum%' and opt not like '%istiyorum%')
GROUP BY 
   Oe.EquProduct
  ,Oe.Miktar
  ,oe.AnaUrun
  ,B.ProductName
  ,B.HeaderId
  ,B.nid
  ,B.PaymentTime
  ,B.ProductId
  ,Oe.MenuFiyat
  ,Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END)
  ,Opt
)
  ,opttotal
AS (
  SELECT optsatislar.ProductId
    ,ISNULL(EquProduct, optsatislar.ProductName) BillProductName
    ,ISNULL(EquProduct, optsatislar.OptionsName ) ProductName
    ,'' ProductGroup
    ,'' InvoiceName
    ,sum(Quantity) OrjToplam
    ,sum(Quantity * ISNULL(Miktar, 1)) Toplam
    ,(sum(MenuFiyat)) * sum(Quantity) OrjTutar
    ,CASE WHEN sum(MenuFiyat) = 0 AND SUM(ISNULL(Miktar, 0)) > 0 THEN 0 ELSE sum(optsatislar.MenuFiyat*Quantity) END Tutar
  FROM optsatislar
  GROUP BY EquProduct
    ,optsatislar.ProductName
    ,optsatislar.OptionsName
    ,
    --  pr.InvoiceName,
    --	pr.ProductGroup,
    optsatislar.ProductId
  )
  ,indirim
AS (
  SELECT TOP 9999999999 ISNULL(avg(ISNULL(b2.discount, 1)), 1) / (CASE WHEN sum(Quantity * Price) = 0 THEN 1 ELSE sum(Quantity * Price) END) indirimtutar
    ,HeaderId indHeaderId
  FROM PaidBill b2
  WHERE PaymentTime >= @par1
  GROUP BY HeaderId
  )
  ,paketindirim
AS (
  SELECT TOP 9999999 CASE 
    WHEN (
      SELECT sum(Quantity * Price)
      FROM bill b2
      WHERE b2.HeaderId = ph.HeaderId
    ) = 0 THEN 0
    ELSE ISNULL(ph.discount, 0) / 
      (
        SELECT sum(Quantity * Price)
        FROM bill b2
        WHERE b2.HeaderId = ph.HeaderId
      )
  END AS pktindirim
    ,HeaderId pktheaderId
  FROM PhoneOrderHeader ph
  )
  ,satislar2
AS (
  SELECT pq.EquProductName
    ,P.Id AS ProductId
    ,SUM(Quantity * ISNULL(pq.Multiplier, 1)) AS Toplam
	,SUM(Quantity ) AS Toplam2
    ,ISNULL(pq.EquProductName, B.ProductName) ProductName
    ,P.ProductGroup
    ,SUM((ISNULL(Quantity, 0) * CASE WHEN ISNULL(pq.Multiplier, 1)=0 THEN 1 ELSE ISNULL(pq.Multiplier, 1) END  ) * ISNULL(B.Price, 0)) AS Tutar
    ,(
      SELECT SUM(Bill.Price * Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLE
    ,(
      SELECT SUM(Bill.Quantity)
      FROM dbo.BillWithHeader AS Bill
      WHERE BillState = 0 AND HeaderId = b.HeaderId AND ProductId = b.ProductId
      ) AS OPENTABLEQuantity
    ,0 AS Discount
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * (avg(ind.indirimtutar)) INDIRIM
    ,SUM((ISNULL(Quantity, 0) * ISNULL(pq.Multiplier, 1)) * ISNULL(B.Price, 0)) * avg(pkt.pktindirim) PAKETINDIRIM
    ,CASE WHEN sum(ISNULL(B.Price, 0)) <= 0.1 THEN sum((ISNULL(B.OriginalPrice, 0))) ELSE 0 END IKRAM
  FROM dbo.Bill AS b WITH (NOLOCK)
  LEFT JOIN proequ pq ON pq.ProductName = B.ProductName
  LEFT JOIN dbo.Product AS P ON P.Id = B.ProductId
  LEFT JOIN indirim AS ind ON ind.indHeaderId = b.HeaderId
  LEFT JOIN paketindirim AS pkt ON pkt.pktheaderId = b.HeaderId
  WHERE [Date] >= @par1 AND [Date] <= @par2 AND P.ProductName NOT LIKE '$%'
  and p.ProductName not in  (select ProductName from OptionsEqu)
  GROUP BY pq.EquProductName
    ,B.ProductName
    ,b.ProductId
    ,P.ProductGroup
    ,B.HeaderId
    ,p.Id
  )

SELECT sum(MIKTAR) MIKTAR
  ,a.ProductName
  ,Sum(TUTAR) TUTAR
  ,SUM(INDIRIM) INDIRIM
  ,SUM(IKRAM) IKRAM
  ,P.ProductCode
FROM (
  SELECT CASE WHEN sum(opttotal.Toplam) = 0 THEN sum(opttotal.OrjToplam) ELSE sum(opttotal.Toplam) END AS MIKTAR
    ,ProductName
    ,ProductGroup AS ProductGroup
    ,sum(ISNULL(opttotal.Tutar, 0)) AS TUTAR
    ,0 INDIRIM
    ,0 IKRAM
	,ProductId
  FROM opttotal
  GROUP BY opttotal.ProductName
    ,opttotal.ProductGroup
	,opttotal.ProductId
  
  UNION
  
  SELECT sum(toplam) AS MIKTAR
    ,ProductName
    ,ProductGroup
    ,sum(tutar) AS TUTAR
    ,SUM(ISNULL(INDIRIM, 0)) + SUM(ISNULL(PAKETINDIRIM, 0)) INDIRIM
    ,SUM(IKRAM) IKRAM
	,ProductId
  FROM satislar2
  GROUP BY ProductName
    ,ProductGroup
    ,ProductId
  ) AS a
    LEFT JOIN Product P ON P.Id = a.ProductId
WHERE MIKTAR<>0 AND (NULL IS NULL --servisten setliyoruz, productname ile arama için.
   OR a.ProductName LIKE '%' + NULL + '%')
GROUP BY a.ProductName, P.ProductCode
ORDER BY a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select 

--* from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR,
--0 as INDIRIM,
--0 as IKRAM
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR,
--SUM(INDIRIM)+SUM(PAKETINDIRIM) INDIRIM,
--SUM(IKRAM) IKRAM

--from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar,0 as INDIRIM,0 PAKETINDIRIM,0 IKRAM
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 


--UNION ALL

--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 
--SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0))*
--(SUM(ISNULL(Discount,0))  / 
--CASE WHEN (SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0)))=0 THEN 1 ELSE 
--(SUM(ISNULL(CashPayment,0))+SUM(ISNULL(CreditPayment,0))+SUM(ISNULL(TicketPayment,0))+SUM(ISNULL(OnlinePayment,0))+SUM(ISNULL(Debit,0))+SUM(ISNULL(Discount,0))) END) INDIRIM,0 PAKETINDIRIM,
----Case When sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) < 0   Then 0 Else  sum((ISNULL(B.OriginalPrice,0)-ISNULL(B.Price,0))) End  IKRAM
--Case When sum(ISNULL(B.Price,0)) = 0   Then sum((ISNULL(B.OriginalPrice,0))) Else 0 End  IKRAM
--  FROM dbo.Payment AS P
--LEFT JOIN dbo.Bill as B ON P.HeaderId=B.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id 

----UNION ALL
----SELECT 
----PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
----SUM(b.Quantity*b.Price)*
----(  SUM(ISNULL(ph.Discount,0))/ (SUM(b.Quantity*b.Price)+SUM(ISNULL(ph.Discount,0)))  ) PAKETINDIRIM,
----0 IKRAM
----  FROM  dbo.PhoneOrderHeader as PH
----LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
----LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
----WHERE
----[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
----GROUP BY B.ProductName,
----B.HeaderId,
----PR.Id 

--UNION ALL
--SELECT 
--PR.Id as ProductId,0 AS Toplam,B.ProductName,0 AS Tutar, 0 INDIRIM,
--SUM(b.Quantity*b.Price)*
--(  avg(ISNULL(ph.Discount,0))/ (  SELECT SUM(Quantity*Price) FROM Bill where HeaderId=B.HeaderId  )  ) PAKETINDIRIM,
--0 IKRAM
--  FROM  dbo.PhoneOrderHeader as PH
--LEFT JOIN dbo.Bill as B ON B.HeaderId=PH.HeaderId
--LEFT JOIN dbo.Product as PR ON PR.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--PR.Id

--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName

--WITH base as (
--SELECT
--	PaymentTime,
--	Quantity,
--	LTRIM(RTRIM(split.s)) AS Opt,
--	ProductId
--FROM
--	dbo.PaidBill
--CROSS APPLY
--	dbo.SplitString(',',PaidBill.Options)  as split
--WHERE
--	ISNULL(Options,'')<>'' AND PaymentTime>=@par1 AND PaymentTime <= @par2
--	),
--base_with_optqty as (
--SELECT 
--	base.PaymentTime,
--	base.Quantity,
--	ProductId,
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,1,CHARINDEX('x',base.Opt)-1)
--	ELSE
--		'1'
--	END AS OptQty,
	
--	CASE 
--		WHEN CHARINDEX('x',base.Opt) > 0 THEN
--		SUBSTRING(base.Opt,CHARINDEX('x',base.Opt)+1,100)
--	ELSE
--		base.Opt
--	END AS Opt	
--FROM 
--	base),
	
--satislar as (	
--SELECT	
--	PaymentTime,
--	ProductId,
--	Quantity * (CASE WHEN ISNUMERIC(OptQty) = 1 THEN CAST(OptQty AS INT) ELSE 1 END ) AS Quantity,	
--	Opt as ProductName
--from
--	base_with_optqty	where Opt Not Like '$%' 
--)
--select * from (

--SELECT 

--sum(Quantity) as MIKTAR,
--ProductName + ' ' + '(Menü İçi Satış)' as ProductName,
--0 as TUTAR
--from  satislar
--group by satislar.ProductName

--UNION


--select 
--sum(t.toplam) as MIKTAR,
--t.ProductName,
--sum(t.tutar) as TUTAR from 

--(
--SELECT 
--P.Id as ProductId,SUM(B.Quantity) AS Toplam,B.ProductName,SUM(ISNULL(B.Quantity,0) * ISNULL(B.Price,0)) AS Tutar
--  FROM dbo.Bill AS B
--LEFT JOIN dbo.Product as P ON P.Id=B.ProductId
--WHERE
--[Date]>=@par1 AND [Date]<=@par2 and  B.ProductName Not Like '$%' 
--GROUP BY B.ProductName,
--B.HeaderId,
--p.Id 
--)   as t

--group by
--t.ProductName ) as a 
--order by
--a.ProductName 
-----------------Log Bıtıs
