CREATE FUNCTION [dbo].[Func_GetSellPaymentsTitles](	@SellNo BIGINT)
RETURNS NVARCHAR(200) 
AS
BEGIN 
	DEclare @Names nvarchar(200);
	SET @Names=''
SELECT @Names = COALESCE(@Names + ', ', '') + 
CASE WHEN IsCash=1 THEN N'نقدی' 
ELSE CASE WHEN IsCustomerClub=1 THEN N'باشگاه' 
ELSE CASE WHEN IsBayeane=1 THEN N'بیعانه' 
ELSE tTypePay.Title 
END END END
FROM tSellPayments
LEFT JOIN tTypePay ON tTypePay.Code=tSellPayments.TypePayNo

WHERE SellNo=@SellNo
RETURN @Names;
END
GO
Create FUNCTION [dbo].[CalcRemind]
(
	@StartDate AS NVARCHAR(10),
	@EndDate AS NVARCHAR(10),
	@CheckBigThan AS INT
)
RETURNS INT
AS
BEGIN
    DECLARE @Value INT 
	SET @Value=(CAST(SUBSTRING(@EndDate,1,4) as int)-CAST(SUBSTRING(@StartDate,1,4) as int))*365+
(CAST(SUBSTRING(@EndDate,6,2) as int)-CAST(SUBSTRING(@StartDate,6,2) as int))*30+
(CAST(SUBSTRING(@EndDate,9,2) as int)-CAST(SUBSTRING(@StartDate,9,2) as int));
   
   RETURN CASE WHEN @CheckBigThan=1 AND @Value<0 THEN 0 ELSE ABS(@Value) END; 
END

GO

CREATE FUNCTION FormatMoney
(
	@Val AS MONEY
)
RETURNS NVARCHAR(10)
AS
BEGIN
	RETURN REPLACE(convert(varchar, @Val, 1),'.00','')
END

GO

CREATE FUNCTION [dbo].[UDF_Julian_To_Gregorian] (@jdn bigint)
Returns nvarchar(11)
as
Begin
    Declare @Jofst  as Numeric(18,2)
    Set @Jofst=2415020.5
    Return Convert(nvarchar(11),Convert(datetime,(@jdn- @Jofst),113),110)
End
GO

CREATE FUNCTION [dbo].[UDF_Persian_To_Julian](@date as nvarchar(20))
RETURNS bigint
AS
Begin
 Declare @iYear AS int=CAST(SUBSTRING(@date,1,4) AS INT)
 Declare @iMonth as int=CAST(SUBSTRING(@date,6,2) AS INT)
 Declare @iDay as int=CAST(SUBSTRING(@date,9,2) AS INT)
 
Declare @PERSIAN_EPOCH  as int
Declare @epbase as bigint
Declare @epyear as bigint
Declare @mdays as bigint
Declare @Jofst  as Numeric(18,2)
Declare @jdn bigint
 
Set @PERSIAN_EPOCH=1948321
Set @Jofst=2415020.5
 
If @iYear>=0 
    Begin
        Set @epbase=@iyear-474 
    End
Else
    Begin
        Set @epbase = @iYear - 473 
    End
    set @epyear=474 + (@epbase%2820) 
If @iMonth<=7
    Begin
        Set @mdays=(Convert(bigint,(@iMonth) - 1) * 31)
    End
Else
    Begin
        Set @mdays=(Convert(bigint,(@iMonth) - 1) * 30+6)
    End
    Set @jdn =Convert(int,@iday) + @mdays+ Cast(((@epyear * 682) - 110) / 2816 as int)  + (@epyear - 1) * 365 + Cast(@epbase / 2820 as int) * 1029983 + (@PERSIAN_EPOCH - 1) 
    RETURN @jdn
End
GO
		CREATE FUNCTION [dbo].[SplitInts]
		(
		@List      nVARCHAR(MAX),
		@Delimiter nVARCHAR(255)
		)
		RETURNS TABLE
		AS
		RETURN ( SELECT Item = CONVERT(nvarchar(100), Item) FROM
		( SELECT Item = x.i.value('(./text())[1]', 'nvarchar(max)')
		FROM ( SELECT [XML] = CONVERT(XML, '<i>
			'
			+ REPLACE(@List, @Delimiter, '
		</i><i>') + '</i>').query('.')
		) AS a CROSS APPLY [XML].nodes('i') AS x(i) ) AS y
		WHERE Item IS NOT NULL
		);
	
	
GO
CREATE TABLE [dbo].[Appontments](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Type] [int] NULL,
	[StartDate] [smalldatetime] NULL,
	[EndDate] [smalldatetime] NULL,
	[AllDay] [bit] NULL,
	[Subject] [nvarchar](max) NULL,
	[Location] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
	[Status] [int] NULL,
	[Label] [int] NULL,
	[ResourceID] [int] NULL,
	[ResourceIDS] [nvarchar](max) NULL,
	[ReminderInfo] [nvarchar](max) NULL,
	[RecurrenceInfo] [nvarchar](max) NULL,
	[CustomeField1] [nvarchar](max) NULL,
 CONSTRAINT [PK_Appointments] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[Resources]    Script Date: 4/4/2024 7:04:33 PM ******/
CREATE TABLE [dbo].[tInvoiceEmployeeTalar](
	[EmployeeId] [BIGINT] NOT NULL,
	[InvoiceId] [BIGINT] NOT NULL,
	[Wage] [money] NULL,
	ListMojavez NVARCHAR(200) NULL,
 CONSTRAINT [PK_tInvoiceEmployeeTalar] PRIMARY KEY CLUSTERED 
(
	[EmployeeId] ASC,
	[InvoiceId] ASC
)
) 
GO
CREATE TABLE [dbo].[Resources](
	[ResourceID] [int] IDENTITY(1,1) NOT NULL,
	[ResourceName] [nvarchar](max) NULL,
	[Color] [nvarchar](500) NULL,
	[Image] [image] NULL,
PRIMARY KEY CLUSTERED 
(
	[ResourceID] ASC
)
) 
GO
/****** Object:  Table [dbo].[t1]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[t1](
	[img] [image] NULL
) 
GO
/****** Object:  Table [dbo].[tAmval]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tAmval](
	[Code] [bigint] NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Model] [nvarchar](200) NULL,
	[Num] [int] NULL,
	[Unit] [nvarchar](50) NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[Des] [nvarchar](max) NULL,
	[Delivery] [nvarchar](150) NULL,
	[Part] [nvarchar](100) NULL,
	[isActive] [bit] NULL,
 CONSTRAINT [PK_tAmval] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tAshnayee]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tAshnayee](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
 CONSTRAINT [PK_tAshnayee] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tAttendance]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tAttendance](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[EmNo] [bigint] NOT NULL,
	[typeno] [int] NULL,
	[typedes] [nvarchar](100) NULL,
	[Date] [nvarchar](10) NULL,
	[timein] [nvarchar](10) NULL,
	[timeout] [nvarchar](10) NULL,
	[totaldes] [nvarchar](20) NULL,
	[total] [int] NULL,
	[des] [nvarchar](max) NULL,
	[Extra] [float] NULL,
	[ExtraDes] [nvarchar](100) NULL,
 CONSTRAINT [PK_tAttendance] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[EmNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBalloted]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBalloted](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [bigint] NULL,
	[CustName] [nvarchar](150) NULL,
	[Mobile1] [nvarchar](15) NULL,
	[Mobile2] [nvarchar](15) NULL,
	[isDelivery] [bit] NULL,
	[Date] [nvarchar](50) NULL,
 CONSTRAINT [PK_tBalloted] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBank]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBank](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Date] [nvarchar](30) NULL,
	[AccNo] [nvarchar](100) NULL,
	[Name] [nvarchar](150) NULL,
	[Branch] [nvarchar](100) NULL,
	[FirstCash] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[State] [nvarchar](15) NULL,
	[Logo] [image] NULL,
	[CardNo] [nvarchar](50) NULL,
	[Shaba] [nvarchar](50) NULL,
 CONSTRAINT [PK_tBank] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBankAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBankAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[AccNo] [nvarchar](100) NOT NULL,
	[Date] [nvarchar](20) NULL,
	[Des] [nvarchar](300) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[BuySell] [bigint] NULL,
 CONSTRAINT [PK_tBankAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[AccNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBaseFood]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBaseFood](
	[Code] [bigint] NOT NULL,
	[gCode] [bigint] NOT NULL,
	[gName] [nvarchar](150) NULL,
	[Name] [nvarchar](150) NULL,
	[OnlineName] [nvarchar](150) NULL,
	[BaseAmount] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[ShowInAccounting] [bit] NULL,
	[ShowInKitchen] [bit] NULL,
	[ShowPrice] [bit] NULL,
	[pic] [image] NULL,
	[Price1] [money] NULL,
	[Price2] [money] NULL,
	[Price3] [money] NULL,
	[Price4] [money] NULL,
	[Price5] [money] NULL,
	[Num] [int] NULL,
	[Unit] [nvarchar](50) NULL,
	[isInc] [bit] NULL,
	[NumInc] [float] NULL,
	[goodsNO] [bigint] NULL,
	[Rating] [int] NULL,
	[TimeToReady] [int] NULL,
	[ShortcutKey] [nvarchar](50) NULL,
	[printerName] [nvarchar](max) NULL,
	[isActive] [bit] NULL,
	[ShowInCust] [bit] NULL,
	[ShowInFish] [bit] NULL,
	[PrinterCode] [bigint] NULL,
	[BarCode] [nvarchar](150) NULL,
	[Ashpaz] [nvarchar](150) NULL,
	[AshpazNo] [int] NULL,
	[AshpazHundred] [float] NULL,
	[OrderRow] [nvarchar](5) NULL,
	[Discount] [float] NULL,
	[DiscountAmount] [money] NULL,
	[picForLCD2] [image] NULL,
	[IsCheckNum] [bit] NULL,
	[IsCheckNumFix] [bit] NULL,
	[numFix] [int] NULL,
	[numFix2] [int] NULL,
	[numFix3] [int] NULL,
	[numFix4] [int] NULL,
	[numFix5] [int] NULL,
	[Price1Title] [nvarchar](50) NULL,
	[Price2Title] [nvarchar](50) NULL,
	[Price3Title] [nvarchar](50) NULL,
	[Price4Title] [nvarchar](50) NULL,
	[Price5Title] [nvarchar](50) NULL,
	[OwnerNo] [bigint] NULL,
	[OwnerHundred] [int] NULL,
	[OwnerAmount] [money] NULL,
	[ShowInPayk] [bit] NULL,
	[isLevelFor1] [int] NULL,
	[isLevelFor2] [int] NULL,
	[isLevelFor3] [int] NULL,
	[isLevelFor4] [int] NULL,
	[isLevelFor5] [int] NULL,
	[ParentNo] [bigint] NULL,
	[LevelFood] [int] NULL,
	[hasServingFood] [bit] NULL,
	[isBatchFood] [bit] NULL,
	[ParentBatchNo] [bigint] NULL,
	[DefaultNumBatchFood] [int] NULL,
	[isForWebSite] [bit] NULL,
	[IsOut] [bit] NULL,
	[IsSalon] [bit] NULL,
	[isShowOnWebSite] [bit] NULL,
	[isMonitor] [bit] NULL,
	[numStaticInInvoice] [int] NULL,
	[isStaticInInvoice] [bit] NULL,
	[IsShowInFavoriteProduct] [bit] NULL,
 CONSTRAINT [PK_tBaseFood] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[gCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBirthdaySended]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBirthdaySended](
	[CustNO] [bigint] NOT NULL,
	[Birthday] [nvarchar](10) NOT NULL,
	[Married] [nvarchar](10) NOT NULL,
	[TimeSend] [nvarchar](20) NULL,
 CONSTRAINT [PK_tBirthdaySended] PRIMARY KEY CLUSTERED 
(
	[CustNO] ASC,
	[Birthday] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBooth]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBooth](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](100) NULL,
	[Manager] [nvarchar](200) NULL,
	[Mobile] [nvarchar](50) NULL,
	[Tel] [nvarchar](50) NULL,
	[NumPers] [int] NULL,
	[isActive] [bit] NULL,
	[isOnline] [bit] NULL,
	[LastTimeOfOnline] [nvarchar](50) NULL,
 CONSTRAINT [PK_tBooth] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBox]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBox](
	[Row] [bigint] NOT NULL,
	[gCode] [nvarchar](30) NOT NULL,
	[Date] [nvarchar](20) NULL,
	[Des] [nvarchar](300) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[SellBuy] [bigint] NULL,
	[isSellBuy] [bit] NULL,
 CONSTRAINT [PK_tBox] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[gCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBoxing]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBoxing](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
 CONSTRAINT [PK_tBoxing] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBranches]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBranches](
	[Code] [int] NOT NULL,
	[Name] [nvarchar](350) NULL,
	[Location] [nvarchar](max) NULL,
 CONSTRAINT [PK_tBranches] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBudgeting]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBudgeting](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NULL,
	[ByfgCode] [bigint] NULL,
	[ByfCode] [bigint] NULL,
	[ToAcc] [nvarchar](25) NULL,
	[isSendSMSSellCustomer] [bit] NULL,
	[isSendSMSCust] [bit] NULL,
	[Hundred] [float] NULL,
	[Amount] [money] NULL,
	[DateSave] [nvarchar](50) NULL,
	[DateExpire] [nvarchar](50) NULL,
	[isExpense] [bit] NULL,
	[isBank] [bit] NULL,
	[isCustomer] [bit] NULL,
	[isOnProfitInvoice] [bit] NULL,
 CONSTRAINT [PK_tBudgeting] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBudgetingAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBudgetingAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[BudgetingCode] [int] NOT NULL,
	[Date] [nvarchar](50) NULL,
	[Des] [nvarchar](max) NULL,
	[Amount] [money] NULL,
	[InvoicAmount] [money] NULL,
	[Exp] [nvarchar](max) NULL,
	[UserName] [nvarchar](50) NULL,
	[SellNo] [bigint] NULL,
 CONSTRAINT [PK_tBudgetingAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[BudgetingCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBuy]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBuy](
	[Code] [bigint] NOT NULL,
	[InvNo] [nvarchar](50) NULL,
	[CustNo] [nvarchar](15) NULL,
	[Date] [nvarchar](30) NULL,
	[Name] [nvarchar](200) NULL,
	[Total] [money] NULL,
	[Cash] [money] NULL,
	[Cheque] [money] NULL,
	[Bank] [money] NULL,
	[BankAcc] [nvarchar](30) NULL,
	[Discount] [money] NULL,
	[Portage] [money] NULL,
	[Balance] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[CashBoxNo] [bigint] NULL,
	[DiscountNo] [bigint] NULL,
	[IsSettlement] [bit] NULL,
	[DateSettle] [nvarchar](30) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[ScotNum] [float] NULL,
	[Storage] [nvarchar](100) NULL,
	[StorageNo] [nvarchar](10) NULL,
	[GoodsCardexDocNo] [bigint] NULL,
	[isProvider] [smallint] NULL,
 CONSTRAINT [PK_tBuy] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tBuyItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tBuyItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[BuyNo] [bigint] NOT NULL,
	[BuyInvNo] [nvarchar](50) NOT NULL,
	[GoodsNo] [bigint] NOT NULL,
	[Des] [nvarchar](300) NULL,
	[Num] [float] NULL,
	[Unit] [nvarchar](20) NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[type] [nvarchar](100) NULL,
	[SellAmount] [money] NULL,
	[Discount] [money] NULL,
 CONSTRAINT [PK_tBuyItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[BuyNo] ASC,
	[BuyInvNo] ASC,
	[GoodsNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCallLogs]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCallLogs](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Number] [nvarchar](20) NULL,
	[CustCode] [bigint] NULL,
	[Name] [nvarchar](150) NULL,
	[Line] [int] NULL,
	[Date] [nvarchar](10) NULL,
	[Time] [nvarchar](10) NULL,
	[isNew] [bit] NULL,
	[NumRings] [int] NULL,
	[TimeHookOn] [nvarchar](10) NULL,
	[TimeHookOff] [nvarchar](10) NULL,
	[OrderNo] [nvarchar](50) NULL,
 CONSTRAINT [PK_tCallLogs] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCashDasti]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCashDasti](
	[row] [bigint] IDENTITY(1,1) NOT NULL,
	[Date] [nvarchar](50) NULL,
	[Amount] [money] NULL,
	[BankAccNo] [nvarchar](50) NULL,
PRIMARY KEY CLUSTERED 
(
	[row] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCategory]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCategory](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Row] [nvarchar](5) NOT NULL,
	[Color] [nchar](6) NULL,
	[icon] [image] NULL,
	[Discount] [float] NULL,
	[PrinterTitle] [nvarchar](100) NULL,
	[PrinterCode] [int] NULL,
	[isHiddenOnKiosk] [bit] NULL,
	[isShowOnWebSite] [bit] NULL,
	[isService] [bit] NULL,
	[NameEN] [nvarchar](100) NULL,
	[NameWeb] [image] NULL,
	[BoothNo] [int] NULL,
	[PrinterNo] [int] NULL,
 CONSTRAINT [PK_tCategory] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCategoryCust]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCategoryCust](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_tCategoryCust] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCategoryGoods]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCategoryGoods](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Row] [nvarchar](5) NOT NULL,
	[Color] [nchar](6) NULL,
	[icon] [nvarchar](max) NULL,
	[Discount] [float] NULL,
	[PrinterTitle] [nvarchar](100) NULL,
	[PrinterCode] [int] NULL,
	[isHiddenOnKiosk] [bit] NULL,
	[isShowOnWebSite] [bit] NULL,
	[isService] [bit] NULL,
	[NameEN] [nvarchar](100) NULL,
	[NameWeb] [nvarchar](100) NULL,
	[OwnerNo] [nvarchar](50) NULL,
	[isMergeInSell] [bit] NULL,
 CONSTRAINT [PK_tCategoryGoods] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCatExpense]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCatExpense](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](80) NULL,
 CONSTRAINT [PK_tCatExpense] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCeremony]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCeremony](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [bigint] NOT NULL,
	[Date] [nvarchar](50) NULL,
	[CustName] [nvarchar](200) NULL,
	[Tel1] [nvarchar](50) NULL,
	[Tel2] [nvarchar](50) NULL,
	[Mobile1] [nvarchar](50) NULL,
	[Mobile2] [nvarchar](50) NULL,
	[NumPerson] [int] NULL,
	[NumPors] [int] NULL,
	[Total] [money] NULL,
	[Cash] [money] NULL,
	[isReset] [bit] NULL,
	[DayName] [nvarchar](50) NULL,
	[Vaede] [nvarchar](50) NULL,
	[Des] [nvarchar](max) NULL,
	[InvoiceId] [bigint] NULL,
	[DueDate] [nvarchar](10) NULL,
 CONSTRAINT [PK_tCeremony] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[CustNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCeremonyList]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCeremonyList](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CerNo] [bigint] NOT NULL,
	[fCode] [bigint] NOT NULL,
	[Name] [nvarchar](220) NULL,
	[Num] [int] NULL,
	[unit] [nvarchar](30) NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[Des] [nvarchar](max) NULL,
 CONSTRAINT [PK_tCeremonyList] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CerNo] ASC,
	[fCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tChargeRefrigerator]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tChargeRefrigerator](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Code] [int] NULL,
	[Date1] [nvarchar](50) NULL,
	[Name] [nvarchar](500) NULL,
	[Num] [float] NULL,
	[UserName] [nvarchar](50) NULL,
 CONSTRAINT [PK_tChargeRefrigerator] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCheque]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCheque](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[ChequeNo] [nvarchar](50) NOT NULL,
	[DateRec] [nvarchar](30) NULL,
	[TypeNO] [int] NULL,
	[TypeName] [nvarchar](50) NULL,
	[Bank] [nvarchar](50) NULL,
	[Branch] [nvarchar](50) NULL,
	[AccNo] [nvarchar](50) NULL,
	[Amount] [money] NULL,
	[Owner] [nvarchar](200) NULL,
	[OwnerNo] [bigint] NULL,
	[Exp] [nvarchar](500) NULL,
	[State] [int] NULL,
	[StateDes] [nvarchar](50) NULL,
	[SellNo] [bigint] NULL,
	[BuyNo] [bigint] NULL,
	[IsSurrender] [bit] NULL,
	[DocNoSurrender] [bigint] NULL,
	[DateSurrender] [nvarchar](30) NULL,
	[IsDraft] [bit] NULL,
	[DateDraft] [nvarchar](30) NULL,
	[DateRevert] [nvarchar](30) NULL,
	[DateVosol] [nvarchar](30) NULL,
	[Maturity] [nchar](10) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[DateVagozar] [nvarchar](50) NULL,
	[isVagozar] [bit] NULL,
 CONSTRAINT [PK_tCheque] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[ChequeNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tChequeSleepAccount]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tChequeSleepAccount](
	[ChequeNo] [nvarchar](100) NOT NULL,
	[DestBankAcc] [nvarchar](150) NOT NULL,
	[DateSave] [nvarchar](50) NULL,
	[Username] [nvarchar](50) NULL,
 CONSTRAINT [PK_tChequeSleepAccount] PRIMARY KEY CLUSTERED 
(
	[ChequeNo] ASC,
	[DestBankAcc] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCustAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNO] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Des] [nvarchar](500) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](300) NULL,
	[SellBuy] [bigint] NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[BoxRowNo] [bigint] NULL,
 CONSTRAINT [PK_tCustAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CustNO] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCustomer]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustomer](
	[Code] [nvarchar](50) NOT NULL,
	[Category] [nvarchar](50) NULL,
	[CategoryNo] [int] NULL,
	[TypeDelivery] [nvarchar](50) NULL,
	[Name] [nvarchar](200) NULL,
	[Tel1] [nvarchar](15) NULL,
	[Tel2] [nvarchar](15) NULL,
	[Mobile1] [nvarchar](15) NULL,
	[Mobile2] [nvarchar](15) NULL,
	[Address] [nvarchar](max) NULL,
	[Birthday] [nvarchar](10) NULL,
	[pLevel] [int] NULL,
	[isCash] [bit] NULL,
	[Cash] [money] NULL,
	[United] [nvarchar](50) NULL,
	[UnitedNo] [int] NULL,
	[Rent] [money] NULL,
	[Des] [nvarchar](max) NULL,
	[WorkAddress] [nvarchar](max) NULL,
	[isSeller] [bit] NULL,
	[Prefix] [nvarchar](50) NULL,
	[Tel3] [nvarchar](15) NULL,
	[Tel4] [nvarchar](15) NULL,
	[Tel5] [nvarchar](15) NULL,
	[Tel6] [nvarchar](15) NULL,
	[Birthday2] [nvarchar](10) NULL,
	[DateSave] [nvarchar](10) NULL,
	[DateMarried] [nvarchar](10) NULL,
	[isBlackList] [bit] NULL,
	[Area] [nvarchar](100) NULL,
	[Street] [nvarchar](100) NULL,
	[Koche] [nvarchar](100) NULL,
	[Mojtamae] [nvarchar](100) NULL,
	[Plaq] [nvarchar](50) NULL,
	[Ashenayi] [nvarchar](100) NULL,
	[Email] [nvarchar](500) NULL,
	[Discount] [float] NULL,
	[TitleNo] [int] NULL,
	[AshanyeeNo] [int] NULL,
	[AreaNo] [nvarchar](50) NULL,
	[MoearefNo] [nvarchar](50) NULL,
	[MaxMoearef] [int] NULL,
	[City] [nvarchar](150) NULL,
	[CityNo] [int] NULL,
	[DeliveryMinute] [int] NULL,
	[AutoDebit] [bit] NULL,
	[DiscountSubscript] [bit] NULL,
	[CategoryFoodNo] [int] NULL,
	[LimitInvoic] [money] NULL,
	[isMenu] [bit] NULL,
	[isSendSMSLinkPay] [bit] NULL,
 CONSTRAINT [PK_t] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCustomerAddress]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustomerAddress](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](70) NULL,
	[Tel] [nvarchar](11) NULL,
	[Mobile1] [nvarchar](11) NULL,
	[Mobile2] [nvarchar](11) NULL,
	[CustNo] [nvarchar](50) NOT NULL,
	[AreaNo] [nvarchar](50) NULL,
	[Area] [nvarchar](100) NULL,
	[Street] [nvarchar](100) NULL,
	[Koche] [nvarchar](100) NULL,
	[Mojtamae] [nvarchar](100) NULL,
	[Plaq] [nvarchar](50) NULL,
	[Rent] [money] NULL,
	[Address] [nvarchar](250) NULL,
	[OrderRow] [nvarchar](2) NULL,
 CONSTRAINT [PK_tCustomerAddress] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CustNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCustomerClubRule]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustomerClubRule](
	[CustomerClubURL] [nvarchar](1000) NULL,
	[GoldLevelPeriodBuy] [int] NULL,
	[GoldLevelNumBuy] [int] NULL,
	[GoldLevelSumBuy] [money] NULL,
	[SilverLevelPeriodBuy] [int] NULL,
	[SilverLevelNumBuy] [int] NULL,
	[SilverLevelSumBuy] [money] NULL,
	[BronzeLevelPeriodBuy] [int] NULL,
	[BronzeLevelNumBuy] [int] NULL,
	[BronzeLevelSumBuy] [money] NULL,
	[GetCustomerMobileForCustomerClub] [bit] NULL
) 
GO
/****** Object:  Table [dbo].[tCustomerOtherInf]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustomerOtherInf](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Enter] [nvarchar](50) NULL,
	[Floor] [nvarchar](50) NULL,
	[Part] [nvarchar](50) NULL,
 CONSTRAINT [PK_tCustomerOtherInf] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[CustNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tCustomerScheduleMenu]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tCustomerScheduleMenu](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[DayNo] [int] NOT NULL,
	[Vaede] [nvarchar](50) NOT NULL,
	[FoodNo] [bigint] NOT NULL,
	[gCode] [int] NULL,
	[CustNo] [nvarchar](50) NULL,
	[DayName] [nvarchar](50) NULL,
	[Num] [int] NULL,
 CONSTRAINT [PK_tCustomerScheduleMenu] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[DayNo] ASC,
	[Vaede] ASC,
	[FoodNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDeal]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDeal](
	[Code] [bigint] NOT NULL,
	[CustNo] [nvarchar](15) NULL,
	[Name] [nvarchar](200) NULL,
	[Date] [nvarchar](30) NULL,
	[Total] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[username] [nvarchar](50) NULL,
	[JetonNo] [nvarchar](1000) NULL,
 CONSTRAINT [PK_tDeal] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDealItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDealItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[DealNo] [bigint] NOT NULL,
	[FoodNo] [bigint] NOT NULL,
	[FoodName] [nvarchar](200) NULL,
	[Day] [nvarchar](50) NULL,
	[DayNo] [smallint] NULL,
	[Vaede] [nvarchar](10) NULL,
	[Num] [smallint] NULL,
	[Price] [money] NULL,
	[Des] [nvarchar](500) NULL,
 CONSTRAINT [PK_tDealItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[DealNo] ASC,
	[FoodNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDefaultTerm]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDefaultTerm](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Des] [nvarchar](150) NULL,
	[Date] [nvarchar](10) NULL,
	[isShowAlways] [bit] NULL,
	[Owner] [nvarchar](100) NULL,
 CONSTRAINT [PK_tDefaultTerm] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDeliveryMan]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDeliveryMan](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Birthday] [nchar](10) NULL,
	[Father] [nvarchar](50) NULL,
	[Sh_sh] [nvarchar](12) NULL,
	[Melli] [nvarchar](12) NULL,
	[Mobile1] [nvarchar](15) NULL,
	[Mobile2] [nvarchar](15) NULL,
	[Tel1] [nvarchar](15) NULL,
	[Tel2] [nvarchar](15) NULL,
	[StartDate] [nvarchar](50) NULL,
	[Address] [nvarchar](max) NULL,
	[Des] [nvarchar](max) NULL,
	[State] [nchar](10) NULL,
	[TypeCar] [nvarchar](50) NULL,
	[PlaqNo] [nvarchar](50) NULL,
	[CertificateNo] [nvarchar](50) NULL,
	[img] [image] NULL,
 CONSTRAINT [PK_tDeliveryMan] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDeliveryManAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDeliveryManAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CNo] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Des] [nvarchar](300) NULL,
	[Type] [smallint] NULL,
	[TypeDes] [nvarchar](50) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[BoxRowNo] [bigint] NULL,
	[UserName] [nvarchar](100) NULL,
	[Year] [int] NULL,
 CONSTRAINT [PK_tDeliveryManAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDessert]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDessert](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Expense] [money] NULL,
	[SellAmount] [money] NULL,
	[Des] [nvarchar](500) NULL,
 CONSTRAINT [PK_tDessert] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDevice]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDevice](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[IP] [nvarchar](100) NULL,
	[State] [bit] NULL,
	[MAC] [nvarchar](100) NULL,
	[UID] [nvarchar](50) NULL,
	[PWD] [nvarchar](50) NULL,
	[isOnline] [bit] NULL,
	[isDigitalMenuMode] [bit] NULL,
	[isJustDigitalMenu] [bit] NULL,
	[isKiosk] [bit] NULL,
	[IsAdminPanel] [bit] NULL,
	[Shoear] [nvarchar](500) NULL,
	[DefaultLang] [nvarchar](3) NULL,
	[TypeOrder] [int] NULL,
 CONSTRAINT [PK_tDevice] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDiscountRoles]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDiscountRoles](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](150) NULL,
	[Type] [int] NULL,
	[Score] [float] NULL,
	[Amount] [money] NULL,
	[Hundred] [float] NULL,
	[GoodsNo] [bigint] NULL,
	[NumGoods] [int] NULL,
	[ByGoodsNo] [bigint] NULL,
	[ByNumGoods] [int] NULL,
	[AmountOf] [money] NULL,
	[AmountThan] [money] NULL,
	[isCard] [bit] NULL,
	[CustNo] [bigint] NULL,
	[CardNoOf] [nvarchar](50) NULL,
	[CardNoThen] [nvarchar](50) NULL,
	[ExpireOf] [nvarchar](50) NULL,
	[ExpireThen] [nvarchar](50) NULL,
	[NumExpire] [int] NULL,
	[NumExpireBalance] [int] NULL,
	[CardAmount] [money] NULL,
	[CardAmountBalance] [money] NULL,
	[CardAmountMinusBySell] [money] NULL,
	[Barcode] [nvarchar](100) NULL,
 CONSTRAINT [PK_tDiscountRoles] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tDiscountSell]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tDiscountSell](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[Date] [nvarchar](50) NULL,
	[Des] [nvarchar](max) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](max) NULL,
	[Year] [int] NULL,
	[Username] [nvarchar](50) NULL,
 CONSTRAINT [PK_tDiscountSell] PRIMARY KEY CLUSTERED 
(
	[Row] ASC
)
) 
GO
/****** Object:  Table [dbo].[tEmployee]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tEmployee](
	[Code] [bigint] NOT NULL,
	[Date] [nvarchar](25) NULL,
	[Name] [nvarchar](200) NULL,
	[Tel] [nvarchar](50) NULL,
	[Mobile] [nvarchar](50) NULL,
	[Address] [nvarchar](300) NULL,
	[Email] [nvarchar](max) NULL,
	[MelliCode] [nvarchar](20) NULL,
	[Sh_Sh] [nvarchar](20) NULL,
	[Father] [nvarchar](50) NULL,
	[Birthday] [nvarchar](10) NULL,
	[BirthdayLocation] [nvarchar](50) NULL,
	[Sarbazi] [nvarchar](50) NULL,
	[Degree] [nvarchar](50) NULL,
	[Reshte] [nvarchar](90) NULL,
	[Gender] [nvarchar](10) NULL,
	[isMarried] [nvarchar](10) NULL,
	[NumChild] [int] NULL,
	[Sabeghe] [int] NULL,
	[TypeEstekhdam] [nvarchar](50) NULL,
	[Position] [nvarchar](150) NULL,
	[Part] [nvarchar](150) NULL,
	[StartDate] [nvarchar](10) NULL,
	[EndDate] [nvarchar](10) NULL,
	[TotalMonth] [int] NULL,
	[StartTime] [nvarchar](10) NULL,
	[EndTime] [nvarchar](10) NULL,
	[Des] [nvarchar](max) NULL,
	[img] [image] NULL,
	[Finger] [image] NULL,
	[VacationWithSalaryByHour] [money] NULL,
	[VacationWithOutSalaryByHour] [money] NULL,
	[TafsiliNp] [nvarchar](10) NULL,
	[ExpenseNo] [nvarchar](10) NULL,
	[isBime] [bit] NULL,
	[TypeBime] [nvarchar](50) NULL,
	[BimeNo] [nvarchar](90) NULL,
	[BimeTakmili] [nvarchar](50) NULL,
	[Maliyat] [nvarchar](50) NULL,
	[StartMaliyat] [nvarchar](10) NULL,
	[EndMaliyat] [nvarchar](10) NULL,
	[BaseDailySalary] [money] NULL,
	[BaseSanavat] [money] NULL,
	[BaseHourSalary] [money] NULL,
	[TypeHokm] [nvarchar](50) NULL,
	[DateSaveHokm] [nvarchar](50) NULL,
	[DateOfHokm] [nvarchar](50) NULL,
	[DateThanHokm] [nvarchar](50) NULL,
	[DesWork] [nvarchar](max) NULL,
	[WorkAddress] [nvarchar](max) NULL,
	[Managment] [nvarchar](50) NULL,
	[BeforeDayCancel] [int] NULL,
	[DesCancel] [nvarchar](max) NULL,
	[NormalDayTimeof] [nchar](10) NULL,
	[NormalDayTimeThan] [nchar](10) NULL,
	[THlDayTimeof] [nchar](10) NULL,
	[THlDayTimeThan] [nchar](10) NULL,
	[TotalTime] [int] NULL,
	[Holiday] [nvarchar](20) NULL,
	[SahmeBime] [int] NULL,
	[ExtraAmount] [money] NULL,
	[MobileFinger] [nvarchar](11) NULL,
	[isSendSMSFinger] [bit] NULL,
 CONSTRAINT [PK_tEmployeee] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tEmployeeAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tEmployeeAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[EmNo] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Des] [nvarchar](300) NULL,
	[TypeNo] [smallint] NULL,
	[TypeDes] [nvarchar](50) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](500) NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[BoxRowNo] [bigint] NULL,
	[UserName] [nvarchar](100) NULL,
	[Year] [int] NULL,
	[MonthNo] [int] NULL,
 CONSTRAINT [PK_tEmployeeAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[EmNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tEmployeeVacation]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tEmployeeVacation](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[EmNo] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[TypeVacation] [int] NULL,
	[TypeVacationDes] [nvarchar](50) NULL,
	[DateOf] [nvarchar](30) NULL,
	[DateThan] [nvarchar](30) NULL,
	[TimeOf] [nvarchar](10) NULL,
	[TimeThan] [nvarchar](10) NULL,
	[Total] [bigint] NULL,
	[Exp] [nvarchar](500) NULL,
 CONSTRAINT [PK_tEmployeeVacation] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[EmNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tExpenses]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tExpenses](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[Date] [nvarchar](30) NULL,
	[TypeNo] [int] NULL,
	[TypeName] [nvarchar](200) NULL,
	[Amount] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[CashBoxNo] [bigint] NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](150) NULL,
	[BankRowNO] [bigint] NULL,
	[BankAccNo] [nvarchar](100) NULL,
	[BankAmount] [bigint] NULL,
	[BoxAmount] [bigint] NULL,
	[ChequeAmount] [bigint] NULL,
	[SellBuyNo] [bigint] NULL,
 CONSTRAINT [PK_tExpenses] PRIMARY KEY CLUSTERED 
(
	[Row] ASC
)
) 
GO
/****** Object:  Table [dbo].[tExplication]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tExplication](
	[code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[OrderRow] [nvarchar](4) NULL,
	[ProductNo] [bigint] NULL,
 CONSTRAINT [PK_tExplication] PRIMARY KEY CLUSTERED 
(
	[code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tFoodsSchedule]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tFoodsSchedule](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[fCode] [bigint] NOT NULL,
	[Vaede] [nvarchar](50) NULL,
	[DayName] [nvarchar](50) NULL,
	[isShowByAlert] [bit] NULL,
	[DayNo] [int] NULL,
	[DateOf] [nvarchar](50) NULL,
	[DateThan] [nvarchar](50) NULL,
 CONSTRAINT [PK_tFoodsSchedule] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[fCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tGhanoneKar]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tGhanoneKar](
	[Year] [int] NOT NULL,
	[TotalDayWorkInMonthVezaratKar] [int] NULL,
	[DarsadBime] [float] NULL,
	[SahmeKarfarma] [int] NULL,
	[SahmeEmployee] [int] NULL,
	[SahmeDowlat] [int] NULL,
 CONSTRAINT [PK_tGhanoneKar] PRIMARY KEY CLUSTERED 
(
	[Year] ASC
)
) 
GO
/****** Object:  Table [dbo].[tGoods]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tGoods](
	[Code] [bigint] NOT NULL,
	[gCode] [bigint] NOT NULL,
	[gName] [nvarchar](150) NULL,
	[Name] [nvarchar](150) NULL,
	[Amount] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[Price1] [money] NULL,
	[Price2] [money] NULL,
	[Price3] [money] NULL,
	[Price4] [money] NULL,
	[Price5] [money] NULL,
	[Num] [float] NULL,
	[Unit] [nvarchar](50) NOT NULL,
	[UnitSell] [nvarchar](50) NULL,
	[ShortcutKey] [nvarchar](50) NULL,
	[isActive] [bit] NULL,
	[BarCode] [nvarchar](150) NULL,
	[OrderRow] [nvarchar](5) NULL,
	[Discount] [float] NULL,
	[DiscountAmount] [money] NULL,
	[picForLCD2] [image] NULL,
	[pic] [image] NULL,
	[isNumEnd] [bit] NULL,
	[NumEnd] [float] NULL,
	[BarCode2] [nvarchar](150) NULL,
	[Size] [nvarchar](150) NULL,
	[Color] [nvarchar](100) NULL,
	[FirstNum] [float] NULL,
	[MinNum] [float] NULL,
	[MaxNum] [float] NULL,
	[PointOrder] [float] NULL,
	[NumOrder] [float] NULL,
	[isBarCodeWeight] [bit] NULL,
	[PriceHundred1] [money] NULL,
	[PriceHundred2] [money] NULL,
	[PriceHundred3] [money] NULL,
	[PriceHundred4] [money] NULL,
	[PriceHundred5] [money] NULL,
	[Salon] [nvarchar](50) NULL,
	[Shelf] [nvarchar](50) NULL,
	[Floor] [nvarchar](50) NULL,
	[IsNegativeCash] [bit] NULL,
 CONSTRAINT [PK_tGoods] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[gCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tGoodsCardex]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tGoodsCardex](
	[DocNo] [bigint] IDENTITY(1,1) NOT NULL,
	[GoodsNo] [bigint] NOT NULL,
	[CatNo] [int] NULL,
	[StorageNo] [nvarchar](10) NULL,
	[Date] [nvarchar](50) NULL,
	[TypeDoc] [nvarchar](200) NULL,
	[TypeNo] [int] NULL,
	[DebitNum] [float] NULL,
	[CreditNum] [float] NULL,
	[Balance] [float] NULL,
	[Exp] [nchar](10) NULL,
	[Price] [money] NULL,
 CONSTRAINT [PK_tGoodsCardex] PRIMARY KEY CLUSTERED 
(
	[DocNo] ASC,
	[GoodsNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tGoodsOut]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tGoodsOut](
	[Code] [bigint] NOT NULL,
	[Date] [nvarchar](50) NULL,
	[gby] [nvarchar](100) NULL,
	[Storage] [nvarchar](100) NULL,
	[Des] [nvarchar](250) NULL,
	[UserName] [nvarchar](80) NULL,
	[StorageNo] [nvarchar](10) NULL,
 CONSTRAINT [PK_tGoodsOut] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tGoodsOutItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tGoodsOutItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[GoodsOutNo] [bigint] NOT NULL,
	[GoodsNo] [bigint] NOT NULL,
	[Des] [nvarchar](300) NULL,
	[Num] [float] NULL,
	[Unit] [nvarchar](20) NULL,
 CONSTRAINT [PK_tGoodsOutItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[GoodsOutNo] ASC,
	[GoodsNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tHoliday]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tHoliday](
	[Year] [int] NULL,
	[Month] [int] NULL,
	[Day] [int] NULL,
	[Title] [nvarchar](100) NULL,
	[isHoliday] [bit] NULL
) 
GO
/****** Object:  Table [dbo].[tJeton]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tJeton](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[CodeOF] [nvarchar](50) NULL,
	[CodeThan] [nvarchar](50) NULL,
	[DateExpire] [nvarchar](30) NULL,
	[Organ] [nvarchar](100) NULL,
	[Amount] [money] NULL,
	[Percents] [int] NULL,
	[isPercent] [bit] NULL,
 CONSTRAINT [PK_tJeton] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tKhedmat]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tKhedmat](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NULL,
 CONSTRAINT [PK_tKhedmat] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tKoche]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tKoche](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[UnitedNo] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](100) NULL,
	[StreetNo] [bigint] NULL,
 CONSTRAINT [PK_tKoche] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[UnitedNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tLimitation]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tLimitation](
	[FormName] [nvarchar](250) NOT NULL,
	[isDelete] [bit] NULL,
	[isAdd] [bit] NULL,
	[isEdit] [bit] NULL,
	[isView] [bit] NULL,
	[isSummary] [bit] NULL,
	[UserNo] [bigint] NOT NULL,
 CONSTRAINT [PK_tLimitation] PRIMARY KEY CLUSTERED 
(
	[FormName] ASC,
	[UserNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tLimitFoods]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tLimitFoods](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[gCode] [bigint] NOT NULL,
	[fCode] [bigint] NOT NULL,
	[LimitNum] [int] NULL,
	[Vaede] [nvarchar](50) NULL,
	[Date1] [nvarchar](50) NULL,
	[Date2] [nvarchar](50) NULL,
 CONSTRAINT [PK_tLimitFoods] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[gCode] ASC,
	[fCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tListExpense]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tListExpense](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](300) NULL,
	[gCode] [int] NULL,
 CONSTRAINT [PK_tListExpense] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tLogs]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tLogs](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Form] [nvarchar](100) NULL,
	[TypeOp] [nvarchar](50) NULL,
	[Des] [nvarchar](max) NULL,
	[Date] [nvarchar](15) NULL,
	[Time] [nvarchar](15) NULL,
	[UserName] [nvarchar](50) NULL,
	[PCName] [nvarchar](max) NULL,
	[IP] [nvarchar](50) NULL,
	[Year] [int] NULL,
 CONSTRAINT [PK_tLogs] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tMavadeMasrafi]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tMavadeMasrafi](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[fg_Code] [bigint] NOT NULL,
	[fCode] [bigint] NOT NULL,
	[Num] [float] NULL,
	[Price] [money] NULL,
	[Title] [nvarchar](100) NULL,
 CONSTRAINT [PK_tMavadeMasrafi] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[fg_Code] ASC,
	[fCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tMojtamae]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tMojtamae](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[UnitedNo] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](100) NULL,
	[KocheNo] [bigint] NULL,
 CONSTRAINT [PK_tMojtamae] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[UnitedNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tNazar]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tNazar](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Dates] [nvarchar](50) NULL,
	[Times] [nvarchar](50) NULL,
	[PhoneNumber] [nvarchar](50) NULL,
	[MSG] [nvarchar](500) NULL,
	[State] [bit] NULL,
 CONSTRAINT [PK_tNazar] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tNotes]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tNotes](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](150) NULL,
	[Des] [nvarchar](max) NULL,
	[Date] [nvarchar](10) NULL,
	[Time] [nvarchar](8) NULL,
	[Count] [int] NULL,
 CONSTRAINT [PK_tNotes] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tOrderEdited]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tOrderEdited](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[SellNo] [bigint] NOT NULL,
	[TotalOld] [money] NULL,
	[TotalNew] [money] NULL,
	[DateTime] [nvarchar](50) NULL,
	[isJustSave] [bit] NULL,
	[isPrintKitchen] [bit] NULL,
	[isPrintBox] [bit] NULL,
	[isTasviye] [bit] NULL,
	[isDiscountChange] [bit] NULL,
	[isServiceChange] [bit] NULL,
	[isFoodChange] [bit] NULL,
	[isScotChange] [bit] NULL,
	[UserName] [nvarchar](50) NULL,
	[CustomerClubCreditCardId] [nvarchar](30) NULL,
	[CustomerClubCreditCardHundred] [smallint] NULL,
	[CustomerClubCreditCardAmount] [money] NULL,
 CONSTRAINT [PK_tOrderEdited_1] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[SellNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tOrderPrintingError]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tOrderPrintingError](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[DateTime] [nvarchar](20) NULL,
	[OrderNo] [nvarchar](20) NULL,
	[Location] [nvarchar](35) NULL,
	[UserName] [nvarchar](30) NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tOrderRow]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tOrderRow](
	[Code] [bigint] NOT NULL,
	[CodeOut] [bigint] NOT NULL,
	[Date] [nvarchar](10) NOT NULL,
	[Vaede] [nvarchar](20) NOT NULL
) 
GO
/****** Object:  Table [dbo].[tOrderRowEmployee]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tOrderRowEmployee](
	[Code] [bigint] NOT NULL,
	[CodeOut] [bigint] NOT NULL,
	[Date] [nvarchar](10) NOT NULL,
	[Vaede] [nvarchar](20) NOT NULL
) 
GO
/****** Object:  Table [dbo].[tOrdersState]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tOrdersState](
	[OrderNo] [bigint] NOT NULL,
	[isDeleted] [bit] NULL,
	[isReseted] [bit] NULL,
 CONSTRAINT [PK_tOrdersState] PRIMARY KEY CLUSTERED 
(
	[OrderNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tPotable]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tPotable](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Expense] [money] NULL,
	[SellAmount] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[type] [int] NULL,
 CONSTRAINT [PK_tPotable] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tPrinters]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tPrinters](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](400) NULL,
	[PrinterName] [nvarchar](700) NULL,
	[Size] [nvarchar](50) NULL,
	[TypeNo] [int] NULL,
	[TypeName] [nvarchar](200) NULL,
	[FontTitle] [nvarchar](300) NULL,
	[FontContent] [nvarchar](300) NULL,
	[FontSize] [nvarchar](20) NULL,
	[RightMargin] [float] NULL,
	[LeftMargin] [float] NULL,
	[TopMargin] [float] NULL,
	[BottomMargin] [float] NULL,
	[isShowPriceColumn] [bit] NULL,
	[isShowFooter] [bit] NULL,
	[NumCopy] [int] NULL,
	[NumReprint] [int] NULL,
	[NumCopyOut] [int] NULL,
	[NumReprintOut] [int] NULL,
	[isShowLogo] [bit] NULL,
	[TypeFish] [int] NULL,
	[isShowBarcode] [bit] NULL,
	[PCID] [nvarchar](200) NULL,
	[isShowFamuseTerm] [bit] NULL,
	[isShowTotal1] [bit] NULL,
	[isShowTotal2] [bit] NULL,
	[isShowTypeDelivery] [bit] NULL,
	[isShowDes] [bit] NULL,
	[isJustInfCustomer] [bit] NULL,
	[NumCopyOutOnly] [int] NULL,
	[NumReprintOutOnly] [int] NULL,
	[isShowContactInf] [bit] NULL,
	[isShowSummaryFoods] [bit] NULL,
	[isShowQRPayInPrint] [bit] NULL,
	[IP] [nvarchar](30) NULL,
	[isActive] [bit] NULL,
	[isShowTimeReadyFood] [bit] NULL,
	[isShowFamusTerm] [bit] NULL,
	[isShowScot] [bit] NULL,
	[isShowDiscount] [bit] NULL,
	[isShowRent] [bit] NULL,
	[isShowService] [bit] NULL,
	[OtherDes] [nvarchar](500) NULL,
	[isShowBirthdayOnFish] [bit] NULL,
	[isShowFooterMSG_Order] [bit] NULL,
	[LanguagePrint] [int] NULL,
	[isShowReprintAlert] [bit] NULL,
	[IsPrintFishBoxInSalon] [bit] NULL,
	[IsPrintFishAfterTasviye] [bit] NULL,
	[isReprintFishInChangeTablet] [bit] NULL,
	[isPrintFishPayk] [bit] NULL,
	[isShowOtherFishInformatio] [bit] NULL,
	[isShowDiffrenceTotal] [bit] NULL,
	[PrintCompleteInvoiceOnRePring] [bit] NULL,
 CONSTRAINT [PK_tPrinters] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tProvider]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tProvider](
	[Code] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Tel1] [nvarchar](15) NULL,
	[Tel2] [nvarchar](15) NULL,
	[Mobile1] [nvarchar](15) NULL,
	[Mobile2] [nvarchar](15) NULL,
	[Address] [nvarchar](max) NULL,
	[Des] [nvarchar](max) NULL,
	[WorkAddress] [nvarchar](max) NULL,
 CONSTRAINT [PK_tProvider] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tProviderAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tProviderAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNO] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Des] [nvarchar](500) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](300) NULL,
	[SellBuy] [bigint] NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[BoxRowNo] [bigint] NULL,
 CONSTRAINT [PK_tProviderAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CustNO] ASC
)
) 
GO
/****** Object:  Table [dbo].[tRecCust]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tRecCust](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Amount] [money] NULL,
	[SellNo] [bigint] NULL,
	[BuyNo] [bigint] NULL,
	[Des] [nvarchar](500) NULL,
	[Cash] [money] NULL,
	[Cheque] [money] NULL,
	[CashBoxNo] [bigint] NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
 CONSTRAINT [PK_tRecCust] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[CustNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tRecPayCustomer]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tRecPayCustomer](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [bigint] NULL,
	[Type] [bit] NULL,
	[Date] [nvarchar](50) NULL,
	[Amount] [money] NULL,
	[Cash] [money] NULL,
	[Card] [money] NULL,
	[Online] [money] NULL,
	[AccNo] [nvarchar](50) NULL,
	[Cheque] [money] NULL,
	[Exp] [nvarchar](max) NULL,
	[Username] [nvarchar](50) NULL,
 CONSTRAINT [PK_tRecPayCustomer] PRIMARY KEY CLUSTERED 
(
	[Row] ASC
)
) 
GO
/****** Object:  Table [dbo].[tReserveSalonSeat]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tReserveSalonSeat](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[DateSave] [nvarchar](50) NULL,
	[DateMaturity] [nvarchar](10) NULL,
	[Vaede] [nvarchar](50) NULL,
	[TimeOf] [nvarchar](5) NULL,
	[timeThan] [nvarchar](5) NULL,
	[CustNo] [nvarchar](10) NULL,
	[CustName] [nvarchar](150) NULL,
	[CustMobile1] [nvarchar](50) NULL,
	[CustMobile2] [nvarchar](50) NULL,
	[Des] [nvarchar](150) NULL,
	[SeatgCode] [int] NULL,
	[SeatNos] [nvarchar](150) NULL,
	[NumPerson] [int] NULL,
	[UserName] [nvarchar](100) NULL,
	[TypeReserve] [nvarchar](200) NULL,
	[SellNo] [bigint] NULL,
PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSchedule]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSchedule](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[CustNo] [bigint] NOT NULL,
	[DayName] [nvarchar](50) NULL,
	[Day] [int] NULL,
	[Vaede] [nvarchar](50) NULL,
 CONSTRAINT [PK_tSchedule] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[CustNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSeatGroup]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSeatGroup](
	[Code] [int] NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Num] [int] NULL,
	[NumThan] [int] NULL,
 CONSTRAINT [PK_tSeatGroup] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO

/****** Object:  Table [dbo].[tSeatReserved4]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSeatReserved4](
	[TableNo] [int] NOT NULL,
	[OrderNo] [bigint] NOT NULL,
	[gCode] [int] NOT NULL,
	[State] [int] NULL,
	[isTablet] [bit] NULL,
	[TabletNo] [int] NULL,
 CONSTRAINT [PK_tSeatReserved4] PRIMARY KEY CLUSTERED 
(
	[TableNo] ASC,
	[OrderNo] ASC,
	[gCode] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSell]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSell](
	[Code] [bigint] NOT NULL,
	[CustNo] [nvarchar](15) NULL,
	[Date] [nvarchar](50) NULL,
	[Name] [nvarchar](200) NULL,
	[Tel] [nvarchar](50) NULL,
	[Mobile1] [nvarchar](50) NULL,
	[Mobile2] [nvarchar](50) NULL,
	[Address] [nvarchar](max) NULL,
	[Total] [money] NULL,
	[Vaede] [nvarchar](20) NULL,
	[isCash] [bit] NULL,
	[isOut] [bit] NULL,
	[isCourier] [bit] NULL,
	[Discount] [money] NULL,
	[Service] [money] NULL,
	[Rent] [money] NULL,
	[ScotNum] [int] NULL,
	[Scot] [money] NULL,
	[CourierName] [nvarchar](100) NULL,
	[CourieNo] [bigint] NULL,
	[seat] [int] NULL,
	[JetonNo] [nvarchar](max) NULL,
	[username] [nvarchar](50) NULL,
	[CashBoxingNo] [bigint] NULL,
	[CashBoxNo] [bigint] NULL,
	[CustRowNo] [bigint] NULL,
	[year] [nvarchar](4) NULL,
	[JetonAmount] [money] NULL,
	[isSMS] [bit] NULL,
	[isMobile] [bit] NULL,
	[isTel] [bit] NULL,
	[Tel2] [nvarchar](50) NULL,
	[isReseted] [bit] NULL,
	[isDeleted] [bit] NULL,
	[TableNo] [int] NULL,
	[SeatgCode] [int] NULL,
	[State] [int] NULL,
	[isTablet] [bit] NULL,
	[TabletNo] [int] NULL,
	[OrderRow] [int] NULL,
	[GroupName] [nvarchar](100) NULL,
	[Time] [nvarchar](10) NULL,
	[isCard] [bit] NULL,
	[BankNo] [bigint] NULL,
	[BankRowNo] [bigint] NULL,
	[CashAmount] [money] NULL,
	[CardAmount] [money] NULL,
	[RoundAmount] [money] NULL,
	[Aneam] [money] NULL,
	[ReprintKitchen] [int] NULL,
	[ReprintCash] [int] NULL,
	[isPaykTasviye] [smallint] NULL,
	[Barcode] [nvarchar](50) NULL,
	[Garson] [nvarchar](50) NULL,
	[NumPerson] [int] NULL,
	[TimeTasviye] [nvarchar](10) NULL,
	[ChequeAmount] [money] NULL,
	[DateReserve] [nvarchar](30) NULL,
	[isSended] [bit] NULL,
	[TimeSend] [nvarchar](10) NULL,
	[isJustSave] [bit] NULL,
	[DiscountNum] [int] NULL,
	[ServiceNum] [int] NULL,
	[SequenceNumber] [int] NULL,
	[LinkPayState] [int] NULL,
	[LinkPayID] [bigint] NULL,
	[OnlinePayRefID] [nvarchar](100) NULL,
	[isOnlinePayed] [bit] NULL,
	[Online] [money] NULL,
	[CustomerClubCreditCardId] [nvarchar](30) NULL,
	[CustomerClubCreditCardHundred] [smallint] NULL,
	[CustomerClubCreditCardAmount] [money] NULL,
	[CustomerClubCreditAffectedAmount] [money] NULL,
	[IsCeremony] BIT NULL,
	ReasonCanceled NVARCHAR(200) NULL,
 CONSTRAINT [PK_tSell] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellEmploye]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellEmploye](
	[Code] [bigint] NOT NULL,
	[CustNo] [nvarchar](15) NULL,
	[Date] [nvarchar](50) NULL,
	[Name] [nvarchar](200) NULL,
	[Tel] [nvarchar](50) NULL,
	[Mobile1] [nvarchar](50) NULL,
	[Mobile2] [nvarchar](50) NULL,
	[Address] [nvarchar](max) NULL,
	[Total] [money] NULL,
	[Vaede] [nvarchar](20) NULL,
	[isCash] [bit] NULL,
	[isOut] [bit] NULL,
	[isCourier] [bit] NULL,
	[Discount] [money] NULL,
	[Service] [money] NULL,
	[Rent] [money] NULL,
	[ScotNum] [int] NULL,
	[Scot] [money] NULL,
	[CourierName] [nvarchar](100) NULL,
	[CourieNo] [bigint] NULL,
	[seat] [int] NULL,
	[JetonNo] [nvarchar](max) NULL,
	[username] [nvarchar](50) NULL,
	[CashBoxNo] [bigint] NULL,
	[CustRowNo] [bigint] NULL,
	[year] [nvarchar](4) NULL,
	[JetonAmount] [money] NULL,
	[isSMS] [bit] NULL,
	[isMobile] [bit] NULL,
	[isTel] [bit] NULL,
	[Tel2] [nvarchar](50) NULL,
	[isReseted] [bit] NULL,
	[isDeleted] [bit] NULL,
	[TableNo] [int] NULL,
	[SeatgCode] [int] NULL,
	[State] [int] NULL,
	[isTablet] [bit] NULL,
	[TabletNo] [int] NULL,
	[OrderRow] [int] NULL,
	[GroupName] [nvarchar](100) NULL,
	[Time] [nvarchar](10) NULL,
	[isCard] [bit] NULL,
	[BankNo] [bigint] NULL,
	[BankRowNo] [bigint] NULL,
	[CashAmount] [money] NULL,
	[CardAmount] [money] NULL,
	[RoundAmount] [money] NULL,
	[Aneam] [money] NULL,
	[ReprintKitchen] [int] NULL,
	[ReprintCash] [int] NULL,
	[isPaykTasviye] [smallint] NULL,
 CONSTRAINT [PK_tSellEmploye] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellEmployeeItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellEmployeeItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[f_gcode] [bigint] NOT NULL,
	[fCode] [bigint] NOT NULL,
	[SellNo] [bigint] NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Num] [int] NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[ShowKitchen] [bit] NULL,
	[ShowAccounting] [bit] NULL,
	[State] [int] NULL,
	[HDiscount] [float] NULL,
	[HDiscountAmount] [money] NULL,
	[HDisAmount] [money] NULL,
	[BaseAmount] [money] NULL,
 CONSTRAINT [PK_tSellEmployeeItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[f_gcode] ASC,
	[fCode] ASC,
	[SellNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellEmployeeNo]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellEmployeeNo](
	[Code] [nvarchar](50) NULL
) 
GO
/****** Object:  Table [dbo].[tSellEmployeeOrderRow]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellEmployeeOrderRow](
	[SellNo] [bigint] NOT NULL,
	[Code] [bigint] NOT NULL,
 CONSTRAINT [PK_tSellEmployeeOrderRow] PRIMARY KEY CLUSTERED 
(
	[SellNo] ASC,
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[f_gcode] [bigint] NOT NULL,
	[fCode] [bigint] NOT NULL,
	[SellNo] [bigint] NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Num] [float] NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[Des] [nvarchar](500) NULL,
	[ShowKitchen] [bit] NULL,
	[ShowAccounting] [bit] NULL,
	[State] [int] NULL,
	[HDiscount] [float] NULL,
	[HDiscountAmount] [money] NULL,
	[HDisAmount] [money] NULL,
	[isOut] [bit] NULL,
	[OldNum] [float] NULL,
	[PriceLevel] [int] NULL,
	[BaseAmount] [money] NULL,
	[OwnerNo] [bigint] NULL,
	[OwnerHundred] [int] NULL,
	[OwnerAmount] [money] NULL,
	[ParentBatchName] [nvarchar](70) NULL,
	[ParentBatchNum] [float] NULL,
	[isBatchTemplate] [bit] NULL,
	[ParentBatchNo] [bigint] NULL,
	[isBatchFood] [bit] NULL,
	[BatchNo] [nvarchar](10) NULL,
	[NumInWeight] [int] NULL,
 CONSTRAINT [PK_tSellItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[f_gcode] ASC,
	[fCode] ASC,
	[SellNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellItems2]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellItems2](
	[Name] [nvarchar](150) NULL,
	[Num] [float] NULL
) 
GO
/****** Object:  Table [dbo].[tSellItems3]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellItems3](
	[Name] [nvarchar](200) NULL,
	[Num] [float] NULL,
	[Price] [money] NULL,
	[Total] [money] NULL,
	[des] [nvarchar](max) NULL,
	[State] [int] NULL,
	[fcode] [bigint] NULL,
	[SellNo] [nvarchar](50) NULL
) 
GO
/****** Object:  Table [dbo].[tSellItemsTimeLog]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellItemsTimeLog](
	[SellNo] [bigint] NULL,
	[Time] [nvarchar](5) NULL,
	[Operation] [nvarchar](10) NULL,
	[Num] [float] NULL,
	[ProductId] [int] NULL
) 
GO
/****** Object:  Table [dbo].[tSellNo]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellNo](
	[ID] [bigint] IDENTITY(1000001,1) NOT NULL
) 
GO
/****** Object:  Table [dbo].[tSellPayments]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellPayments](
	[SellNo] [bigint] NOT NULL,
	[TypePayNo] [int] NOT NULL,
	[BankId] [int] NULL,
	[ChequeSerialId] [nvarchar](50) NULL,
	[Amount] [money] NULL,
	[TrancNo] [nvarchar](100) NULL,
	[Date] [nvarchar](20) NULL,
	[CustomerCardNo] [nvarchar](50) NULL,
	[ReferenceNumber] [nvarchar](50) NULL,
	[TraceNumber] [nvarchar](50) NULL,
	[DocNo] [bigint] NULL,
	[IsDongi] [bit] NOT NULL,
	[DongNum] [float] NULL,
	[IsCash] [bit] NOT NULL,
	[IsCard] [bit] NOT NULL,
	[IsCheque] [bit] NOT NULL,
	[IsCustomerClub] [bit] NULL,
	IsBayeane BIT NULL
) 
GO
/****** Object:  Table [dbo].[tSellSubscriptionCard]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellSubscriptionCard](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[DateSave] [nvarchar](50) NULL,
	[CustNo] [bigint] NULL,
	[TypeSubscriptionCardNo] [int] NULL,
	[NumCard] [int] NULL,
 CONSTRAINT [PK_tSellSubscriptionCard] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSellSubscriptionCardItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSellSubscriptionCardItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[SubscriptCardNo] [bigint] NOT NULL,
	[Vaede] [nvarchar](50) NULL,
	[DayName] [nvarchar](50) NULL,
	[fCode] [bigint] NULL,
	[fgCode] [bigint] NULL,
	[Num] [int] NULL,
 CONSTRAINT [PK_tSellSubscriptionCardItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[SubscriptCardNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSettBackup]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSettBackup](
	[BkPath] [nvarchar](max) NULL,
	[FileBackName] [nvarchar](max) NULL,
	[isBackupAutomat] [bit] NULL,
	[isAlterBKOnExit] [bit] NULL,
	[PeriodBackup] [int] NULL,
	[ServerURL] [nvarchar](max) NULL,
	[ServerUID] [nvarchar](50) NULL,
	[ServerPWD] [nvarchar](50) NULL,
	[BackupEmail] [nvarchar](max) NULL,
	[EmailPort] [int] NULL,
	[EmailHostServer] [nvarchar](500) NULL,
	[EmailEnableSSL] [bit] NULL
) 
GO
/****** Object:  Table [dbo].[tSettBallot]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSettBallot](
	[isBallotWithJeton] [bit] NULL,
	[isBallotWithMoney] [bit] NULL,
	[BallotJetonAmount] [money] NULL,
	[BallotMoneyAmount] [money] NULL,
	[BallotSelectFromListSell] [bit] NULL,
	[BallotSelectFromtCust] [bit] NULL,
	[isSendSMSBallot] [bit] NULL,
	[NumPersonToBallot] [int] NULL
) 
GO
/****** Object:  Table [dbo].[tSettPrint]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSettPrint](
	[isPrintFishBox] [bit] NULL,
	[isPrintFishKitchen] [bit] NULL,
	[isPrintFishFish] [bit] NULL,
	[isPrintFishCust] [bit] NULL,
	[NumFishBox] [int] NULL,
	[NumFishKitchen] [int] NULL,
	[NumFishFish] [int] NULL,
	[NumFishCust] [int] NULL,
	[isShowTimeReadyFood] [bit] NULL,
	[isShowFamusTerm] [bit] NULL,
	[isPrintSplitFish] [bit] NULL,
	[isShowAddressTel] [bit] NULL,
	[isShowScot] [bit] NULL,
	[isShowDiscount] [bit] NULL,
	[isShowRent] [bit] NULL,
	[isShowService] [bit] NULL,
	[isShowPriceColumn] [bit] NULL,
	[isShowBirthdayOnFish] [bit] NULL,
	[isFishKitchen_Smimilar_Box] [bit] NULL,
	[isReprintFishInChangeTablet] [bit] NULL,
	[isShowFooterMSG_Order] [bit] NULL,
	[DefaultPrinterKitchen] [nvarchar](750) NULL,
	[DefaultPrinterCashier] [nvarchar](750) NULL,
	[DefaultPrinterFishFish] [nvarchar](750) NULL,
	[DefaultPrinterCustomer] [nvarchar](750) NULL,
	[DefaultPrinterReport] [nvarchar](750) NULL,
	[DefaultPrinterKitchenName] [nvarchar](750) NULL,
	[DefaultPrinterCashierName] [nvarchar](750) NULL,
	[DefaultPrinterFishFishName] [nvarchar](750) NULL,
	[DefaultPrinterCustomerName] [nvarchar](750) NULL,
	[DefaultPrinterReportName] [nvarchar](750) NULL,
	[LanguagePrint] [nvarchar](10) NULL,
	[LanguageDate] [nvarchar](10) NULL,
	[isShowReprintAlert] [bit] NULL,
	[isShowLogoOnFish] [bit] NULL,
	[IsPrintFishBoxInSalon] [bit] NULL,
	[IsPrintFishAfterTasviye] [bit] NULL,
	[IsPrintFishSeatNo] [bit] NULL,
	[isPrintFishPayk] [bit] NULL,
	[isShowOtherFishInformation] [bit] NULL,
	[DefaultPrinterPayk] [nvarchar](750) NULL,
	[BarcodeType] [int] NULL,
	[BarcodeWidth] [int] NULL,
	[BarcodeHeight] [int] NULL,
	[TypeFish] [int] NULL,
	[isShowDiffrenceTotal] [bit] NULL,
	[isShowBarcode] [bit] NULL,
	[OtherDes] [nvarchar](max) NULL,
	[isPrintFishInSaveTablet] [bit] NULL,
	[DefaultLabelPrinterName] [int] NULL,
	[isPreviewInvoicInSell] [bit] NULL,
	[DefaultTypeFish] [nvarchar](300) NULL,
	[DefaultPrintSize] [nvarchar](300) NULL,
	[PrintCompleteInvoiceOnRePring] [bit] NULL
) 
GO
/****** Object:  Table [dbo].[tSettPublic]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSettPublic](
	[Title] [nvarchar](500) NULL,
	[ShortTitle] [nvarchar](120) NULL,
	[StartCustNo] [nvarchar](max) NULL,
	[Tels] [nvarchar](max) NULL,
	[Address] [nvarchar](max) NULL,
	[Unit] [nvarchar](50) NULL,
	[ScotNum] [int] NULL,
	[Rent] [money] NULL,
	[LevelTitle1] [nvarchar](50) NULL,
	[LevelTitle2] [nvarchar](50) NULL,
	[LevelTitle3] [nvarchar](50) NULL,
	[LevelTitle4] [nvarchar](50) NULL,
	[LevelTitle5] [nvarchar](50) NULL,
	[Logo] [image] NULL,
	[isShowLogoOnPrint] [bit] NULL,
	[AreaCode] [nvarchar](4) NULL,
	[CallLogWait] [int] NULL,
	[NumLines] [int] NULL,
	[isAlertEndNumFoods] [bit] NULL,
	[isAlertEndNumGoods] [bit] NULL,
	[isSendSMSAfterOrder] [bit] NULL,
	[LimitNum] [bit] NULL,
	[isSendSMSAfterSaveCust] [bit] NULL,
	[isResetOrderRow] [bit] NULL,
	[DefaultTypeDelivery] [int] NULL,
	[isShowFavFoods] [bit] NULL,
	[FavFoodsNum] [int] NULL,
	[isSendSMSBirthday] [bit] NULL,
	[isRoundAmount] [bit] NULL,
	[isShowBalanceInInvoic] [bit] NULL,
	[isTimeExpireForEditInvoic] [bit] NULL,
	[TimeExpireForEditInvoic] [int] NULL,
	[CornoTabletOrder] [int] NULL,
	[isReminderCeremony] [bit] NULL,
	[isReminderBirthday] [bit] NULL,
	[isReminderCheque] [bit] NULL,
	[isShowCallLogInMainForm] [bit] NULL,
	[SkinName] [nvarchar](200) NULL,
	[CurrLanguage] [nvarchar](5) NULL,
	[DefaultService] [int] NULL,
	[isShowDailySummary] [bit] NULL,
	[isTasviyeAfterSaveSalon] [bit] NULL,
	[IsReceiveOnlineOrder] [bit] NULL,
	[isAlertTypePay] [bit] NULL,
	[isAutoSizeProdButton] [bit] NULL,
	[isShowSelectCourier] [bit] NULL,
	[StartOfNoInv] [int] NULL,
	[HourChangeVaede] [int] NULL,
	[EghtesadNo] [nvarchar](50) NULL,
	[DefaultDiscountOut] [float] NULL,
	[StartOfNoInvOut] [int] NULL,
	[RoundType] [bit] NULL,
	[RoundAmount] [int] NULL,
	[DefaultDiscountSalon] [float] NULL,
	[PortNumberCallerID] [int] NULL,
	[BoudRateCallerID] [int] NULL,
	[ParityCallerID] [int] NULL,
	[dataBitsCallerID] [int] NULL,
	[StopBitsCallerID] [float] NULL,
	[IsActiveCallerID] [bit] NULL,
	[isSaveCallLog] [bit] NULL,
	[isSaveCallVoices] [bit] NULL,
	[isShowFoodByList] [bit] NULL,
	[TopToBottomAddToListOrder] [bit] NULL,
	[IsMergeSalonAndOutNo] [bit] NULL,
	[isCloseFirstAccount] [bit] NULL,
	[OverToRent] [money] NULL,
	[StartDateProgram] [nvarchar](20) NULL,
	[isFilterByVaede] [bit] NULL,
	[isTasviyeAfterSendinTablet] [bit] NULL,
	[isLockOtherUsers] [bit] NULL,
	[IsShowSeatNoOnTop] [bit] NULL,
	[isDefaultInCallerID] [int] NULL,
	[Rents] [nvarchar](300) NULL,
	[UpdateProductsAllClient] [int] NULL,
	[DefaultDecimalPlace] [int] NULL,
	[DefaultDecimalSeprator] [nvarchar](2) NULL,
	[isOutWithDelivery] [bit] NULL,
	[isOutWithDeliveryTxt] [nvarchar](50) NULL,
	[isOutOnly] [bit] NULL,
	[isOutOnlyTxt] [nvarchar](50) NULL,
	[isSalon] [bit] NULL,
	[isSalonTxt] [nvarchar](50) NULL,
	[isOutWithDeliveryIcon] [image] NULL,
	[isOutOnlyIcon] [image] NULL,
	[isSalonIcon] [image] NULL,
	[isCalcServiceByMinute] [bit] NULL,
	[ServiceCeilingofTime] [int] NULL,
	[ServiceByMinute] [money] NULL,
	[isOnline] [bit] NULL,
	[Options] [nvarchar](500) NULL,
	[Polysm] [nvarchar](500) NULL,
	[isShowOrderNumPayk] [bit] NULL,
	[PersonelFoodExpenseCode] [int] NULL,
	[MehmanExpenseCode] [int] NULL,
	[ZayeatExpenseCode] [int] NULL,
	[DefaultBuyExpenseNo] [int] NULL,
	[DefaultBuyExpenseName] [nvarchar](100) NULL,
	[CallerIDPortServer] [int] NULL,
	[CallerIDServerIP] [nvarchar](15) NULL,
	[CallerIDServerLineNumber] [int] NULL,
	[CallerIDThisClientLineNumber] [int] NULL,
	[isActiveSecondMonitor] [bit] NULL,
	[isDigitalMenu] [bit] NULL,
	[Poster] [image] NULL,
	[CallerIdByNetwork] [bit] NULL,
	[SendSMSSalon] [bit] NULL,
	[SendSMSOutPayk] [bit] NULL,
	[SendSMSOutOnly] [bit] NULL,
	[isLinkPayActive] [bit] NULL,
	[LinkPayCompanyNo] [bigint] NULL,
	[LinkPaySendResultPaySMSAdmin] [bit] NULL,
	[LinkPaySendResultPaySMSPayk] [bit] NULL,
	[LinkPayExpireMinuteDefault] [int] NULL,
	[ExpenseNoForLinkPayWage] [bigint] NULL,
	[DecreaseFormulaFromGoods] [bit] NULL,
	[NumLimited] [int] NULL,
	[DefaultPaymentType] [int] NULL
) 
GO
/****** Object:  Table [dbo].[tSettSMSPanel]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSettSMSPanel](
	[SMSAPI] [nvarchar](max) NULL,
	[SMSNumber] [nvarchar](50) NULL,
	[SMSUID] [nvarchar](max) NULL,
	[SMSPWD] [nvarchar](max) NULL,
	[SMSReceiveNazar] [bit] NULL,
	[SMSReceiveOrder] [bit] NULL,
	[PrefixMobile] [nchar](2) NULL,
	[endSMS] [nvarchar](300) NULL,
	[BithdaySMSTemp] [nvarchar](250) NULL,
	[MarriedSMSTemp] [nvarchar](250) NULL,
	[SMSSite] [nvarchar](max) NULL,
	[SMSInstagram] [nvarchar](max) NULL,
	[SMSTelegram] [nvarchar](max) NULL,
	[SMSAddress] [nvarchar](max) NULL,
	[SMSTel] [nvarchar](max) NULL,
	[PreCodeCountry] [nvarchar](6) NULL,
	[isSMSEnglish] [bit] NULL,
	[isSMSReceiveAlert] [bit] NULL,
	[isSMSDeviceMode] [bit] NULL,
	[IsServicedSMS] [bit] NULL,
	[SendSMSRemanderCustAccPeriod] [int] NULL,
	[isSendSMSRemanderCustAcc] [bit] NULL,
	[IsSendSMSRemindeMaturityInvoices] [bit] NULL,
	[SendSMSRemanderMaturityInvoicesPeriod] [int] NULL,
	[IsSendSMSRemindeAmani] [bit] NULL,
	[IsSendSMSRemindeMaturityInvoice] [bit] NULL
) 
GO
/****** Object:  Table [dbo].[tShareholder]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tShareholder](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](150) NULL,
	[Tel] [nvarchar](50) NULL,
	[Mobile] [nvarchar](100) NULL,
	[Address] [nvarchar](max) NULL,
	[Hundred] [float] NULL,
	[Cash] [money] NULL,
	[Des] [nvarchar](max) NULL,
	[DateSave] [nvarchar](50) NULL,
 CONSTRAINT [PK_tShareholder] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tShareholderAcc]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tShareholderAcc](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[ShareNO] [bigint] NOT NULL,
	[Date] [nvarchar](30) NULL,
	[Des] [nvarchar](500) NULL,
	[Debit] [money] NULL,
	[Credit] [money] NULL,
	[Exp] [nvarchar](300) NULL,
	[BoxingNo] [int] NULL,
	[BoxingName] [nvarchar](100) NULL,
	[UserName] [nvarchar](50) NULL,
	[Year] [int] NULL,
	[BoxRowNo] [bigint] NULL,
 CONSTRAINT [PK_tShareholderAcc] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[ShareNO] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSMSLog]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSMSLog](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Number] [nvarchar](50) NULL,
	[isBirthday] [bit] NULL,
	[Date] [nvarchar](10) NULL,
	[Time] [nvarchar](15) NULL,
	[Year] [int] NULL,
	[RecID] [bigint] NULL,
	[isDelivered] [bit] NULL,
 CONSTRAINT [PK_tSMSLog] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tStorage]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tStorage](
	[Code] [nvarchar](10) NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Anbardar] [nvarchar](100) NULL,
	[Negahban] [nvarchar](100) NULL,
	[AnbardarNo] [bigint] NULL,
	[NegahbanNo] [bigint] NULL,
	[Address] [nvarchar](max) NULL,
 CONSTRAINT [PK_tStorage] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tStreet]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tStreet](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[UnitedNo] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](100) NULL,
 CONSTRAINT [PK_tStreet] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[UnitedNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tSubscriptionCard]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tSubscriptionCard](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](100) NULL,
	[Discount] [float] NULL,
	[Num] [int] NULL,
 CONSTRAINT [PK_tSubscriptionCard] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTelBook]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTelBook](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Tel1] [nvarchar](20) NULL,
	[Tel2] [nvarchar](20) NULL,
	[Mobile1] [nvarchar](20) NULL,
	[Mobile2] [nvarchar](20) NULL,
	[Address] [nvarchar](max) NULL,
	[PartNo] [int] NULL,
	[Email] [nvarchar](max) NULL,
 CONSTRAINT [PK_tTelBook] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTelBookItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTelBookItems](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[Code] [bigint] NOT NULL,
	[Pos] [nvarchar](100) NULL,
	[Name] [nvarchar](250) NULL,
	[Phone] [nvarchar](20) NULL,
 CONSTRAINT [PK_tTelBookItems] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTempTextMessage]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTempTextMessage](
	[code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[OrderRow] [nvarchar](4) NULL,
	[isGarson] [bit] NULL,
 CONSTRAINT [PK_tTempTextMessage] PRIMARY KEY CLUSTERED 
(
	[code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTitleCustomer]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTitleCustomer](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](70) NULL,
 CONSTRAINT [PK_tTitleCustomer] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTitleShogl]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTitleShogl](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NULL,
 CONSTRAINT [PK_tTitleShogl] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTypePay]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTypePay](
	[Code] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](100) NULL,
	[isHundredCard] [bit] NULL,
	[isAmountCard] [bit] NULL,
	[isConnectPOS] [bit] NULL,
	[isTCP_USB] [bit] NULL,
	[IP] [nvarchar](50) NULL,
	[IP2] [nvarchar](50) NULL,
	[Port] [int] NULL,
	[ComPortNumber] [nvarchar](10) NULL,
	[isSubscriptionHundredCard] [bit] NULL,
	[TerminalNo] [nvarchar](50) NULL,
	[BankAccNo] [nvarchar](50) NULL,
	[SerialNo] [nvarchar](50) NULL,
	[AccpetorNo] [nvarchar](50) NULL,
	[Comm1] [nvarchar](300) NULL,
	[Comm2] [nvarchar](300) NULL,
	[Comm3] [nvarchar](300) NULL,
	[Comm4] [nvarchar](300) NULL,
	[PrintFlag] [int] NULL,
	[ConfirmFlag] [bit] NULL,
	[isMulti] [bit] NULL,
	[PCID] [nvarchar](100) NULL,
	[ProviderId] [int] NULL,
	[MinimumAmount] [bigint] NULL,
 CONSTRAINT [PK_tTypePay] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tTypePayMultiplePay]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tTypePayMultiplePay](
	[Code] [bigint] IDENTITY(1,1) NOT NULL,
	[TypePayNo] [int] NOT NULL,
	[BankAccNo] [nvarchar](100) NULL,
	[Hundred] [int] NULL,
 CONSTRAINT [PK_tTypePayMultiplePay] PRIMARY KEY CLUSTERED 
(
	[Code] ASC,
	[TypePayNo] ASC
)
) 
GO
/****** Object:  Table [dbo].[tUnited]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tUnited](
	[Code] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Rent] [money] NULL,
	[Time] [int] NULL,
	[Discount] [float] NULL,
 CONSTRAINT [PK_tUnited] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)
) 
GO
/****** Object:  Table [dbo].[tUnits]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tUnits](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_tUnits] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) 
GO
/****** Object:  Table [dbo].[tUserLevel]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tUserLevel](
	[ID] [int] NOT NULL,
	[Name] [nvarchar](max) NULL,
	[isDelete] [bit] NULL,
	[isInsert] [bit] NULL,
	[isUpdate] [bit] NULL,
	[isSelect] [bit] NULL,
 CONSTRAINT [PK_tUserLevel] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)
) 
GO
/****** Object:  Table [dbo].[tUsers]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tUsers](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[UserName] [nvarchar](50) NULL,
	[Password] [nvarchar](700) NULL,
	[BoxingNo] [bigint] NULL,
	[isKeepScreenOn] [bit] NULL,
	[screenLightValue] [int] NULL,
	[isShowMessageSendToKitchen] [bit] NULL,
	[img] [image] NULL,
	[isOnline] [bit] NULL,
	[isTablet] [bit] NULL,
	[themeNo] [int] NULL,
	[numItemInRow] [int] NULL,
	[DiscountLimitOf] [float] NULL,
	[DiscountLimitThan] [float] NULL,
	[DiscountLimitAmountOf] [float] NULL,
	[DiscountLimitAmountThan] [float] NULL,
	[IsNoTypePaySelect] [bit] NULL,
	[IsNoPaykSelect] [bit] NULL,
	[IsNoChangePriceSelect] [bit] NULL,
	[EditInvoicLimit] [int] NULL,
	[IsShowLastVisitInSell] [bit] NULL,
	[IsShowScoreInSell] [bit] NULL,
	[IsShowSumBuyInSell] [bit] NULL,
	[IsOnlySell] [bit] NULL,
	[Finger] [image] NULL,
	[isFinger] [bit] NULL,
	[hasSaveWhileZero] [bit] NULL,
 CONSTRAINT [PK_tVorod] PRIMARY KEY CLUSTERED 
(
	[Row] ASC
)
) 
GO
/****** Object:  Table [dbo].[tVacation]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

CREATE TABLE [dbo].[tVacation](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[EmNo] [int] NOT NULL,
	[Date] [nvarchar](10) NULL,
	[StartTime] [nvarchar](10) NULL,
	[EndTime] [nvarchar](10) NULL,
	[TotalDes] [nvarchar](100) NULL,
	[Total] [int] NULL,
	[Des] [nvarchar](max) NULL,
	[PersonType] [smallint] NULL,
	[DayName] [nvarchar](15) NULL,
	[SessionId] [bigint] NULL,
 CONSTRAINT [PK_tVacation] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[EmNo] ASC
))
GO
/****** Object:  Table [dbo].[tVaede]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tVaede](
	[Code] [int] NOT NULL,
	[Title] [nvarchar](50) NULL,
 CONSTRAINT [PK_tVaede] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)) ;

GO
GO


CREATE TABLE [dbo].[tVaedeSchedules](
	[DayNo] [int] NOT NULL,
	[TimeOf] [nvarchar](10) NULL,
	[TimeThan] [nvarchar](10) NULL,
	[VaedeCode] [int] NOT NULL,
 CONSTRAINT [PK_tVaedeSchedules] PRIMARY KEY CLUSTERED 
(
	[DayNo] ASC,
	[VaedeCode] ASC
)) ;

GO
/****** Object:  Table [dbo].[tYear]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE TABLE [dbo].[tYear](
	[Year] [int] NOT NULL,
	[isCurrent] [bit] NULL,
	[isBlocked] [bit] NULL,
 CONSTRAINT [PK_tYear] PRIMARY KEY CLUSTERED 
(
	[Year] ASC
)
) 
GO
ALTER TABLE [dbo].[tOrderRow] ADD  CONSTRAINT [DF_tOrderRow_Code]  DEFAULT ((0)) FOR [Code]
GO
ALTER TABLE [dbo].[tOrderRow] ADD  CONSTRAINT [DF_tOrderRow_CodeOut]  DEFAULT ((0)) FOR [CodeOut]
GO
ALTER TABLE [dbo].[tSell] ADD  CONSTRAINT [DF_tSell_ReprintKitchen]  DEFAULT ((0)) FOR [ReprintKitchen]
GO
ALTER TABLE [dbo].[tSell] ADD  CONSTRAINT [DF_tSell_ReprintCash]  DEFAULT ((0)) FOR [ReprintCash]
GO
ALTER TABLE [dbo].[tSell] ADD  DEFAULT ((1)) FOR [SequenceNumber]
GO
ALTER TABLE [dbo].[tSettPublic] ADD  DEFAULT ((0)) FOR [isLinkPayActive]
GO
ALTER TABLE [dbo].[tSettPublic] ADD  DEFAULT ((0)) FOR [LinkPayCompanyNo]
GO
ALTER TABLE [dbo].[tSettPublic] ADD  DEFAULT ((0)) FOR [LinkPaySendResultPaySMSAdmin]
GO
ALTER TABLE [dbo].[tSettPublic] ADD  DEFAULT ((0)) FOR [LinkPaySendResultPaySMSPayk]
GO
ALTER TABLE [dbo].[tSettPublic] ADD  DEFAULT ((0)) FOR [LinkPayExpireMinuteDefault]
GO
/****** Object:  StoredProcedure [dbo].[dailyReportSell]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
		CREATE  PROCEDURE [dbo].[dailyReportSell] @dateof as nvarchar(10),@datethan as nvarchar(10),@username as nvarchar(50),@timeof as nvarchar(10),@timethan as nvarchar(10)
		AS
		BEGIN
		SELECT Code,CardAmount,CashAmount,
		ISNULL(Online,0) AS Online,Rent,Discount,Scot,Service,RoundAmount,Aneam,
		isOut as isOUTInvoice,
		case when isOut=0 THEN 'Salon'
		else case when isOut=1 AND isCourier=0 THEN 'InPerson'
		Else CASE WHEN isOut=1 AND isCourier=1 THEN 'Delivery'
		ELSE 'Others'
		END END END AS OrderType,
		isCourier,isMobile,Items.Total,CustomerClubCreditAffectedAmount,
		((Items.Total+ISNULL(tSell.Rent,0)+isnull(tSell.Scot,0)-isnull(tSell.Discount,0)+ISNULL(tSell.Service,0))-(tSell.CardAmount+CashAmount+ISNULL(tSell.Online,0)+ISNULL(ChequeAmount,0)+ISNULL(CustomerClubCreditAffectedAmount,0))) as Balance
		INTO #Sells FROM tSell
		INNER JOIN (SELECT SellNo,SUM(Num*Price) AS Total FROM tSellItems GROUP BY SellNo) Items ON Items.SellNo=tSell.Code
		WHERE  SUBSTRING([Date],1,10)>=@dateof and SUBSTRING([Date],1,10)<=@datethan and tSell.State not in(3,4,13) AND
		(len(@timeof)=0 OR (len(@timeof)>0 AND (SUBSTRING([Time],1,5)>=@timeof AND SUBSTRING([Time],1,5)<=@timethan))) AND
		(len(@username)=0 OR (len(@username)>0 AND username=@username));
		
		DECLARE @tSumCustomerClub MONEY=0;
		DECLARE @tSumSalon MONEY=0;
		DECLARE @tSumOutHozori MONEY=0;
		DECLARE @tSumOutPayk MONEY=0;
		DECLARE @tSumRent MONEY=0;
		DECLARE @tSumService MONEY=0;
		DECLARE @tSumScot MONEY=0;
		DECLARE @tSumNoneCash MONEY=0;
		DECLARE @tSumRoundAmount MONEY=0;
		DECLARE @tSumDiscount MONEY=0;
		DECLARE @tSumOnline MONEY=0;
		DECLARE @tSumAneam MONEY=0;
		SELECT @tSumSalon=SUM(Total) FROM #Sells WHERE OrderType='Salon' 
		SELECT @tSumCustomerClub=SUM(ISNULL(CustomerClubCreditAffectedAmount,0)) FROM #Sells WHERE OrderType='Salon' 
		SELECT @tSumOutHozori=SUM(Total) FROM #Sells WHERE OrderType='InPerson' 
		SELECT @tSumOutPayk=SUM(Total) FROM #Sells WHERE OrderType='Delivery' 
		SELECT @tSumOnline=SUM(Total) FROM #Sells WHERE isMobile=1 

		SELECT @tSumRent=SUM(Rent) FROM #Sells WHERE OrderType='Delivery' 
		SELECT @tSumService=SUM(Service) FROM #Sells  
		SELECT @tSumRoundAmount=SUM(RoundAmount) FROM #Sells  
		SELECT @tSumScot=SUM(Scot) FROM #Sells  
		SELECT @tSumAneam=SUM(Aneam) FROM #Sells  
		SELECT @tSumDiscount=SUM(Discount) FROM #Sells  
		SELECT @tSumAneam=SUM(Aneam) FROM #Sells  

		SELECT @tSumNoneCash=SUM(Balance) FROM #Sells  

		SELECT    @tSumSalon AS tSumSalon,
		@tSumOutHozori AS tSumOutHozori,
		@tSumOutPayk AS tSumOutPayk,
		@tSumRent AS tSumRent,
		@tSumService AS tSumService,
		@tSumScot AS tSumScot,
		@tSumNoneCash AS tSumNoneCash,
		@tSumRoundAmount AS tSumRoundAmount,
		@tSumDiscount AS tSumDiscount,
		@tSumOnline AS tSumOnline,
		@tSumAneam   AS tSumAneam,
		@tSumCustomerClub AS tSumCustomerClub
		DROP TABLE #Sells;

		END


	
GO
/****** Object:  StoredProcedure [dbo].[filterCustInf]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		
	
		CREATE PROCEDURE [dbo].[filterCustInf] @filter AS NVARCHAR(50)
		AS
		BEGIN
		DECLARE @mobileFilter NVARCHAR(50)=(N'%'+@filter+'%');
		DECLARE @nameFilter NVARCHAR(50)=(N'%'+@filter+'%');
		SELECT CustNo,Name,Tel,Tel2,Mobile1,Mobile2,Address,CODE AS ORDERNO,
		ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Name) AS RowID
		INTO #dt FROM tsell
		WHERE ( mobile1 LIKE  @mobileFilter OR mobile2 LIKE @mobileFilter OR tel LIKE @mobileFilter OR tel2 LIKE @mobileFilter OR
		name LIKE @nameFilter OR Address LIKE @nameFilter) AND
		LEN(ISNULL(custno,''))=0 AND
		(LEN(ISNULL(Name,''))>0 OR len(isnull(Mobile1,''))>0 OR len(isnull(Mobile2,''))>0 OR len(isnull(Tel,''))>0 OR
		LEN(ISNULL(Tel2,''))>0 OR len(isnull(Address,''))>0) AND State<>4
		ORDER BY CODE DESC;
		SELECT * INTO #TEMP FROM (SELECT Code,(isnull(Prefix,'')+' '+Name) as Name,Tel1,Tel2,Mobile1,Mobile2,Address,WorkAddress,Area,Street,Koche,Mojtamae,Plaq,0 AS Rent,Discount,isSendSMSLinkPay,'' as ORDERNO FROM tCustomer
		WHERE mobile1 LIKE  @mobileFilter OR mobile2 LIKE @mobileFilter OR tel1 LIKE @mobileFilter OR tel2 LIKE @mobileFilter   OR
		(ISNULL(Prefix,'')+' '+Name) LIKE @nameFilter OR Address LIKE @nameFilter
		UNION
		SELECT DISTINCT CustNo,Name,Tel,Tel2,Mobile1,Mobile2,Address,'','','','' ,'','',0,0,0,ORDERNO
		FROM #dt
		WHERE #dt.rowid=1
		) result

		SELECT Code,Name,Tel1,Tel2,Mobile1,Mobile2,Address,WorkAddress,Area,Street,Koche,Mojtamae,Plaq,Rent,Discount,isSendSMSLinkPay FROM #temp
		WHERE LEN(ISNULL(Mobile1,''))>0 OR LEN(ISNULL(Mobile2,''))>0 OR LEN(ISNULL(Tel1,''))>0 OR
		LEN(ISNULL(Tel2,''))>0 OR LEN(ISNULL(Address,''))>0
		order by ORDERNO desc
		DROP TABLE #temp;
		DROP TABLE #dt;
		END
	
GO
/****** Object:  StoredProcedure [dbo].[getCustNameForCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
	
		CREATE  PROCEDURE [dbo].[getCustNameForCallerID] @filter as nvarchar(50)
		AS
		BEGIN
		declare @mobileFilter nvarchar(50)=(@filter+'%');
		select Name,Tel as tel1,tel2,Mobile1,Mobile2,address,date into #temp from tSell
		where
		Tel Like @mobileFilter or
		Tel2 Like @mobileFilter or
		Mobile1 Like @mobileFilter or
		Mobile2 Like @mobileFilter;
		select Name,tel1,tel2,Mobile1,Mobile2,address from #temp
		order by Code desc
		drop table #temp ;
		END
	
GO
/****** Object:  StoredProcedure [dbo].[getCustomerInfForCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
		CREATE PROCEDURE [dbo].[getCustomerInfForCallerID] @filter as nvarchar(50)
		AS
		BEGIN
		declare @mobileFilter nvarchar(50)=(@filter+'%');
		select Code,Name,Tel1,tel2,Tel3,Tel4,Tel5,Tel6,Mobile1,Mobile2,address into #temp from tCustomer ;
		select Code,Name,Tel1,tel2,Tel3,Tel4,Tel5,Tel6,Mobile1,Mobile2,address from #temp  
		WHERE
		Tel1 Like @mobileFilter or
		Tel2 Like @mobileFilter or
		Tel3 Like @mobileFilter or
		Tel4 Like @mobileFilter or
		Tel5 Like @mobileFilter or
		Tel6 Like @mobileFilter or
		Mobile1 Like @mobileFilter or
		Mobile2 Like @mobileFilter
		drop table #temp ;
		END
GO
/****** Object:  StoredProcedure [dbo].[getLastOrderForCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
	
		CREATE PROCEDURE [dbo].[getLastOrderForCallerID] @filter as nvarchar(50)
		AS
		BEGIN
		declare @mobileFilter nvarchar(50)=(@filter+'%');
		select Code,Tel,tel2,Mobile1,Mobile2,State,Date,Time into #temp from tSell;
		select SellNo,Num,Price into #items from tSellItems;
		select  top 1 Date,Time,Code into #sell from #temp
		where Tel Like @mobileFilter or Tel2 Like @mobileFilter or Mobile1 Like @mobileFilter or Mobile2 Like @mobileFilter
		order by Code desc;

		select cast(t.Total as money) as Total,[Date],[Time] from #sell
		inner join (SELECT SUM(Num*Price) as Total,SellNo from #items Group by sellno) t on t.SellNo=#sell.code
		drop table #temp ;
		drop table #items ;
		drop table #sell ;
		END
	
GO
/****** Object:  StoredProcedure [dbo].[getListCategoryFoodsForTablet]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE procedure [dbo].[getListCategoryFoodsForTablet] @seatNo as int,@orderno as nvarchar(15) ,@today as nvarchar(15),@seatGCode AS INT as begin select num,f_gcode,NumInWeight into #sells from tSellItems  inner join tSell on tSell.Code=tSellItems.SellNo where tSell.State in (-2,-1,-3,-21,6) and  SUBSTRING(Date,1,10)=@today AND  ((seat=@seatNo AND SeatgCode=@seatGCode AND SellNo=@orderno AND tSell.isOut=0) OR  (tSell.isOut=1 AND SellNo=@orderno)); select tCategory.Code,tCategory.Row,tCategory.Name,tCategory.Color,tCategory.Discount, tCategory.icon,CASE WHEN ISNULL(NumInWeight,0)>0 THEN NumInWeight ELSE isnull(titems.cc,0) END as NumItemInThisOrder into #cats from tCategory left join (select sum(num) as cc,SUM(ISNULL(NumInWeight,0)) AS NumInWeight,f_gcode FROM #sells  group by f_gcode) titems on titems.f_gcode=tCategory.Code; select * from #cats order by Row ASC; drop table #sells drop table #cats; END;
GO
/****** Object:  StoredProcedure [dbo].[getListCustomer]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		create PROCEDURE [dbo].[getListCustomer]
		AS
		BEGIN
		select Code,Name,Tel1,tel2,Tel3,Tel4,Tel5,Tel6,Mobile1,Mobile2,Address into #temp from tCustomer ;
		select Name from #temp
		drop table #temp ;
		END
	
GO
/****** Object:  StoredProcedure [dbo].[getListFoods]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[getListFoods] @today as nvarchar(10) AS  BEGIN  SELECT fcode into #tSells from tSellItems where Sellno
in(Select Code from tSell where [Date]=@today);  
Select Code,Name,gName,Num,Price1,ShowInAccounting, isActive, Pic,  ParentNo, hasServingFood,Discount,isLevelFor1,OrderRow, ShowInKitchen,isInc,GoodsNo,PrinterName,gCode,IsCheckNum,isCheckNumFix,	   LevelFood, ShortcutKey, Discount as DiscountGoods,
DiscountAmount,[OwnerNo],[OwnerHundred], [OwnerAmount],cast(isnull(isbatchfood,0) as bit) as isbatchfood, 
isnull(ParentBatchNo,0) as ParentBatchNo, ISNULL(DefaultNumBatchFood,0) AS DefaultNumBatchFood,IsOut,IsSalon,Unit ,Barcode
INTO #tFoods  
FROM tBaseFood; 
Select #tFoods.Code,#tFoods.Name,#tFoods.gName,#tFoods.Num, 
CASE WHEN ISNULL(SubProductBatch,0)=0 THEN #tFoods.Price1 ELSE PriceBatch END AS Price1, 
#tFoods.ShowInAccounting,	ShortcutKey,OrderRow,	Pic,  #tfoods.ParentNo, 
CASE WHEN LevelFood=0 THEN N'معمولی' ELSE CASE WHEN LevelFood=1 THEN N'مخصوص' ELSE N'VIP' END END AS LevelFoodTxt,
#tFoods.ShowInKitchen,#tFoods.isInc,#tFoods.GoodsNo,#tFoods.PrinterName,#tFoods.gCode,
tCategory.Discount,IsCheckNum,isCheckNumFix,#tFoods.Discount as DiscountGoods,#tFoods.DiscountAmount,#tFoods.[OwnerNo],#tFoods.[OwnerHundred],
#tFoods.[OwnerAmount],isLevelFor1, ProductFormula,SubProduct,hasServingFood,NumSchedule, NumLimit,LevelFood,NumSell,#tFoods.ParentBatchNo, 
isbatchfood,ISNULL(SubProductBatch,0) AS SubProductBatch,DefaultNumBatchFood,#tFoods.IsOut, #tFoods.IsSalon,
Unit,ISNULL(CountGoodsCashIsZero ,-1) CountGoodsCashIsZero,#tFoods.Barcode  FROM #tFoods
INNER JOIN tCategory ON tCategory.Code=#tFoods.gCode  
LEFT JOIN (SELECT COUNT(*) AS NumSell,fCode FROM #tSells GROUP BY fCode) tSells ON tSells.fCode=#tFoods.Code
LEFT JOIN (SELECT COUNT(*) AS NumSchedule,fCode FROM tFoodsSchedule GROUP By fCode) tSchedule ON tSchedule.fCode=#tFoods.Code  
LEFT JOIN (SELECT COUNT(*) AS NumLimit ,fCode FROM tLimitFoods GROUP By fCode) tLimit ON tLimit.fCode=#tFoods.Code  
LEFT JOIN (SELECT COUNT(*) AS ProductFormula,SUM(ISNULL(goods.CountGoodsCashIsZero ,-1)) AS CountGoodsCashIsZero ,fCode FROM tMavadeMasrafi  
LEFT JOIN (SELECT COUNT(*) AS CountGoodsCashIsZero,Code FROM tGoods
LEFT JOIN (SELECT SUM(DebitNum-CreditNum) AS CashGoods,goodsNo FROM tGoodsCardex GROUP BY GoodsNo) tCardex ON tCardex.GoodsNo=tGoods.Code WHERE ISNULL(tCardex.CashGoods,0)<=0 AND ISNULL(IsNegativeCash,0)=0 GROUP BY Code) goods ON goods.Code=tMavadeMasrafi.fg_Code GROUP BY fCode) tFormula ON tFormula.fCode=#tFoods.Code
LEFT JOIN (SELECT COUNT(*) AS SubProduct,ParentNo FROM #tFoods GROUP BY ParentNo) tSubProduct ON tSubProduct.ParentNo=#tFoods.Code
LEFT JOIN (SELECT COUNT(*) AS SubProductBatch,Sum(DefaultNumBatchFood*Price1) AS PriceBatch,ParentBatchNo FROM #tFoods GROUP BY ParentBatchNo) tSubProductBatch ON tSubProductBatch.ParentBatchNo=#tFoods.Code
WHERE  isActive=1 
ORDER BY OrderRow ASC; 

DROP TABLE #tFoods; 
DROP TABLE #tSells;
END; 
GO
/****** Object:  StoredProcedure [dbo].[getListGroupedFoodsInOrder]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE PROCEDURE [dbo].[getListGroupedFoodsInOrder] @sellno as bigint
		AS
		BEGIN
		select (tBaseFood.Name+' ('+ cast(t.Num as nvarchar(10))+')') as item into #temp From (select Sum(tSellItems.num) as num,fCode from tSellItems
		where sellno=@sellno
		group by  fcode) t
		inner join tBaseFood on tBaseFood.Code=t.fCode


		DECLARE @Names NVARCHAR(MAX)
		SELECT @Names = COALESCE(@Names + ', ', '') + item
		FROM #temp
		select @Names+N'ء '
		drop table #temp
		END
	
GO


		CREATE PROCEDURE [dbo].[getListSellFoodDifference]
		@foodcode AS INT,
		@foodname AS NVARCHAR(100),
		@username AS NVARCHAR(100),
		@gcode AS NVARCHAR(100),
		@custno AS NVARCHAR(10),
		@custname AS NVARCHAR(50),
		@vaede AS NVARCHAR(100),
		@ownerNo AS INT,
		@dateof AS NVARCHAR(10),
		@datethan AS NVARCHAR(10)
		AS
		BEGIN

		SELECT tbasefood.Code,tCategory.Name AS gName,tbasefood.Name,gcode,
		CASE WHEN ISNULL(TotalBaseAmountFormula,0)=0 THEN BaseAmount 
		ELSE TotalBaseAmountFormula 
		END BaseAmount
		INTO #foods FROM tbasefood
		LEFT JOIN tCategory on tCategory.Code=tBaseFood.gCode
		LEFT JOIN (SELECT SUM(Num*ISNULL(Price,0)) AS TotalBaseAmountFormula, fCode FROM tMavadeMasrafi GROUP BY fCode) tFormula ON tFormula.fCode=tBaseFood.Code
		WHERE
		(LEN(@gcode)=0 OR (LEN(@gcode)>0 AND 
							@gcode=CAST(tCategory.Code AS NVARCHAR(10)) OR
							@gcode LIKE '%'+CAST(tCategory.Code AS NVARCHAR(10))+',%' OR
							@gcode LIKE '%,'+CAST(tCategory.Code AS NVARCHAR(10))+',%' OR
							@gcode LIKE '%,'+CAST(tCategory.Code AS NVARCHAR(10))+'%'
						   )
        ) AND
		(@foodcode=0 OR (@foodcode>0 AND tBaseFood.Code=@foodcode)) AND
		(@ownerNo=0 OR (@ownerNo>0 AND tBaseFood.OwnerNo=@ownerNo)) AND
		(LEN(@foodname)=0 OR (LEN(@foodname)>0 AND tBaseFood.name LIKE '%'+@foodname+'%'))


		SELECT #foods.gcode,#foods.gName,#foods.Name,fCode,fCode Code,num, 
		(Num*Price) AS TotalItemSell,
		(Num*ISNULL(#foods.BaseAmount,0)) AS TotalItemBaseAmount,
		ISNULL(#foods.BaseAmount,0) AS BaseAmount,
		Price,
		(CASE WHEN ISNULL(OwnerHundred,0)>0 THEN ((OwnerHundred*Price*Num)/100) ELSE (ISNULL(OwnerAmount,0)*NUM*Price) END) AS OwnerAmount
		INTO #sells 
		FROM tSellItems
		INNER JOIN tSell ON tSell.Code=tSellItems.SellNo
		LEFT JOIN #foods ON #foods.Code=tSellItems.fCode
		WHERE
		(LEN(@custname)=0 OR (LEN(@custname)>0 AND tSell.Name LIKE '%'+@custname+'%')) AND
		(LEN(@custno)=0 OR (LEN(@custno)>0 AND tSell.CustNo=@custno))	   AND
		(LEN(@username)=0 OR (LEN(@username)>0 AND tSell.username=@username)) AND
		(LEN(@vaede)=0 OR (LEN(@vaede)>0 AND Vaede IN (SELECT Item FROM SplitInts(@vaede,',')))) AND
		[Date]>=@dateof AND [Date]<=@datethan AND tSell.State NOT IN(3,4,13);



		SELECT #foods.Code,gName,Name, 
		ISNULL(t.TotalCount,0) AS TotalCount,
		ISNULL(t.TotalItemSell,0) AS TotalItemSell,
		ISNULL(t.TotalItemBaseAmount,0) TotalItemBaseAmount,
		(ISNULL(t.TotalItemSell,0)-ISNULL((t.TotalItemBaseAmount),0)) AS ProfitNot,
		#foods.gcode,#foods.Code AS fCode,
		ISNULL(t.AvgSell,0) AS AvgSell,
		ISNULL(t.minPrice,0) AS minPrice,
		ISNULL(t.maxPrice,0) AS maxPrice,
		[OWNER] 
		INTO #sssdata 
		FROM #foods
		INNER JOIN (SELECT fCode,sum(num) AS TotalCount , SUM(TotalItemSell) AS TotalItemSell,
						SUM(TotalItemBaseAmount) AS TotalItemBaseAmount,
						AVG(BaseAmount) AS BaseAmount,
						AVG(Price) AS AvgSell,
						MIN(Price) AS minPrice,
						MAX(Price) AS maxPrice,
						SUM(OwnerAmount) AS [OWNER]
						FROM #sells
						GROUP BY fCode 
						HAVING SUM(NUM)>0
					) t ON t.fCode=#foods.Code

		SELECT * FROM #sssdata
		ORDER BY TotalCount DESC;
		
		DROP TABLE #foods;
		DROP TABLE #sells;
		DROP TABLE #sssdata;
		end
	

	
GO
/****** Object:  StoredProcedure [dbo].[getProductsForTablet]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[getProductsForTablet] @today as nvarchar(10),@orderno as nvarchar(15),@gcode as int,@seatgcode as int,@seat as int,@dayno as int,@vaede AS NVARCHAR(50),@parentNo as int AS BEGIN SELECT num,fcode,Sellno,tSellItems.isout as isoutItem,Des,Price,PriceLevel,tSell.isOut,SeatgCode,Seat,ISNULL(NumInWeight,0) NumInWeight into #items  from tSellItems INNER JOIN tSell ON tSell.Code=tSellItems.SellNo WHERE [Date]=@today AND tSell.State in(-2,-1,-3,-21,6) and Vaede=@vaede;SELECT Code,gCode,Name,Num,Discount,DiscountAmount,pic,IsCheckNum,Des,OrderRow,Price1,numFix,isCheckNumFix,isLevelFor1,LevelFood,TimeToReady,isInc,ShowInKitchen,ShowInAccounting,ParentNo,CASE WHEN ISNULL(Unit,'') LIKE N'%کیلو%' OR ISNULL(Unit,'') LIKE N'%کیلو%' OR ISNULL(Unit,'') LIKE N'%کیلو%' THEN 1 ELSE 0 END AS isWeight into #foods1 FROM tBaseFood WHERE gCode=@gcode AND (@parentNo=0 OR (@parentNo>0 AND ISNULL(ParentNo,0)=@parentNo)); SELECT  Code,gCode,Name,Num,Discount,DiscountAmount,pic,IsCheckNum,Des,OrderRow,Price1,numFix,isCheckNumFix, isLevelFor1,LevelFood,TimeToReady,isInc,ShowInKitchen,ShowInAccounting,#foods1.ParentNo,ISNULL(tParent.SubProduct,0) AS SubProduct,isWeight INTO #foods FROM #foods1 LEFT JOIN (SELECT COUNT(*) AS SubProduct,ParentNo FROM #foods1 GROUP BY ParentNo) tParent ON tParent.ParentNo=#foods1.Code;SELECT ParentNo,isnull(titems.Des,'') as DES,isnull(titems.isoutItem,0) AS isOUT,#foods.Code,#foods.gCode,#foods.Name,#foods.Num,ISNULL(titems.Price,0) as Price,Price1,numFix,CASE WHEN #foods.isWeight=1 THEN ISNULL(titems.CCInWeight,0) ELSE isnull(titems.cc,0) END as cc,CASE WHEN #foods.isWeight=1 THEN ISNULL(titems22.NumUsedInWeight,0) ELSE isnull(titems22.NumUsed,0) END as NumUsed, #foods.OrderRow,SubProduct,#foods.Discount,#foods.DiscountAmount,#foods.pic,CASE WHEN #foods.isWeight=1 THEN ISNULL(titems.CCInWeight,0) ELSE isnull(titems.cc,0) END as numOrder, #foods.IsCheckNum ,ISNULL(isContainsLimit,0) AS isContainsLimit,#foods.isCheckNumFix,ISNULL(tFoodsSchedule2.isSchedule,0) AS isSchedule,isLevelFor1,LevelFood,TimeToReady, isInc,ShowInKitchen as isShowKitchen,ShowInAccounting as isShowBox,#foods.Des as ProductDesc into #sssdata  from #foods left join (SELECT CASE WHEN ISNULL(COUNT(*),0)>0 THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END AS isSchedule,fCode FROM tFoodsSchedule WHERE ((LEN(ISNULL(DateOf,''))>0 AND LEN(ISNULL(DateThan,''))>0 AND @today>=DateOf AND @today<=DateThan) OR (LEN(ISNULL(DateOf,''))=0 AND LEN(ISNULL(DateThan,''))=0)) group by fCode) tFoodsSchedule2 on tFoodsSchedule2.fCode=#foods.Code left join (SELECT CASE WHEN ISNULL(COUNT(*),0)>0 THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END AS isContainsLimit,fCode FROM tFoodsSchedule WHERE ((LEN(ISNULL(DateOf,''))>0 AND LEN(ISNULL(DateThan,''))>0 AND @today>=DateOf AND @today<=DateThan) OR (LEN(ISNULL(DateOf,''))=0 AND LEN(ISNULL(DateThan,''))=0)) AND DayNo=@dayno and Vaede=@vaede group by fCode) tFoodsSchedule on tFoodsSchedule.fCode=#foods.Code left join (select sum(num) as CC,SUM(ISNULL(NumInWeight,0)) AS CCInWeight,fcode,MAX(Sellno) as sellno,CAST(MIN(ISNULL(CAST(isoutItem AS INT),0)) as bit) as isoutItem,MAX(Des) as des,isnull(max(Price),0) as Price,Max(PriceLevel) as PriceLevel  from #items where SellNo=@orderno AND ((isOut=0 and  seat=@seat and SeatgCode=@seatgcode) OR isOut=1)  group by fCode) titems on titems.fcode=#foods.Code left join (select sum(num) as NumUsed,SUM(ISNULL(NumInWeight,0)) AS NumUsedInWeight,fcode  from #items where SellNo<>@orderno group by fCode) titems22 on titems22.fcode=#foods.Code ;SELECT *, CASE WHEN isCheckNumFix=1 THEN (numfix-isnull(NumUsed,0)) ELSE CASE WHEN IsCheckNum=1 THEN (num-isnull(NumUsed,0)) ELSE 0 END END AS NumBalance FROM #sssdata WHERE (Code IN(SELECT Code FROM #foods1 WHERE ParentNo=0) AND @parentNo=0) OR @parentNo>0 ORDER by CC DESC,OrderRow ASC;Drop TABLE #sssdata;DROP TABLE #foods;DROP TABLE #items;DROP TABLE #foods1;END
GO
/****** Object:  StoredProcedure [dbo].[getSeatsForTablet]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE procedure [dbo].[getSeatsForTablet] @today as nvarchar(10),@timeno as nvarchar(20), @seatGCode as int	,@garson as nvarchar(100),@vaede AS NVARCHAR(20) AS begin  DECLARE @isLockOtherUsers AS BIT; SELECT TOP 1 @isLockOtherUsers=ISNULL(isLockOtherUsers,0) FROM tSettPublic; SELECT tSell.Time as SellTime,DATEDIFF(minute,dbo.UDF_Julian_To_Gregorian(dbo.UDF_Persian_To_Julian(tsell.[Date]))+' '+SUBSTRING(tSell.[Time],1,5),dbo.UDF_Julian_To_Gregorian(dbo.UDF_Persian_To_Julian(@timeno))+' '+SUBSTRING(@timeno,11,5)) as pasteTime,Code,CustNo,Name,Garson,State,Seat,SeatgCode into #sells FROM tSell WHERE isOut=0 AND [Date]=@today AND State NOT IN(3,4,5,10,13) AND ISNULL(TimeTasviye,'')='' AND ISNULL(isReseted,0)=0 And SeatgCode=@seatGCode AND (Vaede=@vaede OR State<3); SELECT (t2.number+t1.Num)  as SeatNo,ISNULL(tSells.OrderNo,'') AS OrderNo,ISNULL(tSells.CustNo,'') AS CustNo,ISNULL(tSells.CustName,'') AS CustName,ISNULL(tSells.NumProductInOrder,0) AS NumProductInOrder,CASE WHEN @isLockOtherUsers=0 THEN @garson ELSE ISNULL(tSells.GarsonName,'') END as GarsonName,ISNULL(tSells.OrderState,-1) as OrderState,CAST(CASE WHEN tSells.GarsonName=@garson OR LEN(ISNULL(tSells.GarsonName,''))=0 OR @isLockOtherUsers=0 THEN 0 ELSE 1 END AS BIT) as isOtherUser,CASE WHEN tsells.pasteTime<1 THEN N'الان' ELSE CASE WHEN (pasteTime<60 AND pasteTime>=1) THEN (CAST(pasteTime AS nvarchar(10))+N' دقیقه پیش') ELSE ISNULL(tSells.OrderTime,'') END END AS OrderTime,t1.Name as SeatgName,t1.Code as SeatgCode   FROM    tSeatGroup t1 JOIN    master.dbo.spt_values t2 ON t2.type = 'P' AND t2.number < t1.NumThan Left Join (SELECT MAX(pasteTime) as pasteTime,MAX(Code) as OrderNo,MAX(CustNo) as CustNo,MAX(Name) as CustName,count(*) AS NumProductInOrder,MAX(Garson) as GarsonName,MAX(State) as OrderState,MAX(SellTime) as OrderTime,Seat,MAX(SeatgCode) as SeatgCode FROM #sells Group by Seat) tSells on tSells.Seat=(t2.number+t1.Num) where t1.Code=@seatGCode drop table #sells END; 
GO
/****** Object:  StoredProcedure [dbo].[getSumTotalBuyForCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
	
		create  PROCEDURE [dbo].[getSumTotalBuyForCallerID] @filter as nvarchar(50)
		AS
		BEGIN
		declare @mobileFilter nvarchar(50)=(@filter+'%');
		select SellNo,Num,Price into #items from tSellItems;
		select  Code,Tel,tel2,Mobile1,Mobile2,State,[Date],[Time]  into #sell from tSell
		where Tel Like @mobileFilter or Tel2 Like @mobileFilter or Mobile1 Like @mobileFilter or Mobile2 Like @mobileFilter;

		select ISNULL(Sum(Total),0) AS Total from #sell
		inner join (SELECT SUm(Num*Price) AS Total,SellNo From #items Group BY SellNo) t on t.SellNo=#sell.Code
		drop table #items ;
		drop table #sell ;
		END
	
GO
/****** Object:  StoredProcedure [dbo].[insertIntoCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
		create PROCEDURE [dbo].[insertIntoCallerID]
		@mobile as nvarchar(15),
		@custNo as nvarchar(10),
		@custName as nvarchar(70),
		@line as int,
		@datenow as nvarchar(10),
		@timenow as nvarchar(10),
		@isNew as bit,
		@numRings as int,
		@isSaveLog as bit
		AS
		BEGIN
		Declare @last  Table(Total  money,[Date]  nvarchar(10),[Time]  nvarchar(10));
		Declare @totalBuy  Table(Total  money);
		Declare @popular  Table(gName  nvarchar(70),[Name]  nvarchar(70));
		Declare @lastCallerIDRow as bigint;
		Declare @numCall as bigint;
		--###########################################################################
		--  EXEC getLastOrderForCallerID @mobile;
		declare @mobileFilter nvarchar(50)=(@mobile+'%');
		select Code,Tel,tel2,Mobile1,Mobile2,State,[Date],[Time] into #temp from tSell;
		select SellNo,Num,Price into #items from tSellItems;
		select  top 1 [Date],[Time],Code into #sell from #temp
		where Tel Like @mobileFilter or Tel2 Like @mobileFilter or Mobile1 Like @mobileFilter or Mobile2 Like @mobileFilter;
		INSERT INTO @last(Total,[Date],[Time])
		select t.Total,[Date],[Time] from #sell
		inner join (SELECT SUM(Num*Price) as Total,SellNo from #items Group by sellno) t on t.SellNo=#sell.code;
		drop table #items ;
		drop table #sell ;
		drop table #temp ;

		insert into @totalBuy  EXEC getSumTotalBuyForCallerID @mobile ;
		insert into @popular  EXEC PopularFoodCustForCallerID @mobile;
		--###########################################################################
		select * from @last;
		select * from @totalBuy;
		select * from @popular;
		if @isSaveLog=1
		BEGIN
		INSERT INTO [tCallLogs]([Number],[CustCode],[Name],[Line],[Date],[Time],[isNew],[NumRings])
		VALUES(@mobile,@custNo,@custName,@line,@datenow,@timenow,@isNew,@numRings);
		Select IDENT_CURRENT('tCallLogs') as rowid;
		SELECT Count(*) as numCall FROM tCallLogs WHERE Number=@mobile;
		END
		END
	
GO
/****** Object:  StoredProcedure [dbo].[NewSequenceID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
	

		CREATE PROCEDURE [dbo].[NewSequenceID]
		(
		@NewID char(7) out
		)
		AS
		BEGIN
		declare @isExsits as int=1
		WHILE (@isExsits>0)
		BEGIN
		INSERT INTO tSellNo DEFAULT VALUES

		SELECT @NewID = CAST(SCOPE_IDENTITY() AS nvarchar(7))
		Select @isExsits=Count(*) from tSellItems where SellNo=@NewID
		END;

		END;
GO
/****** Object:  StoredProcedure [dbo].[PopularFoodCustForCallerID]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
		create  PROCEDURE [dbo].[PopularFoodCustForCallerID] @filter as nvarchar(50)
		AS
		BEGIN
		declare @mobileFilter nvarchar(50)=(@filter+'%');
		select Code,Tel,tel2,Mobile1,Mobile2,State,Vaede into #temp from tSell where State not in (4) AND (Tel Like @mobileFilter or Tel2 Like @mobileFilter or Mobile1 Like @mobileFilter or Mobile2 Like @mobileFilter) ;
		select SellNo,Num,fCode into #items from tSellItems;
		select gName,Name,Code into #food from tBaseFood;

		select Sum(#items.Num) as Counts,#items.fcode into #ttemp2 from #items
		inner join #temp on #temp.Code=#items.SellNo
		inner join #food on #food.code=#items.fCode
		group by #temp.Vaede,#items.fCode

		select top 1 #food.gName,#food.Name from #ttemp2
		inner join #food on #food.Code=#ttemp2.fCode
		order by #ttemp2.Counts DESC

		drop table #temp ;
		drop table #items ;
		drop table #food ;
		drop table #ttemp2 ;
		END
GO
/****** Object:  StoredProcedure [dbo].[SP_CheckDailyOrderRow]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE PROCEDURE [dbo].[SP_CheckDailyOrderRow] @today AS NVARCHAR(10),@isFilterByVaede AS BIT,@CurrVaede AS NVARCHAR(20)
		AS
		BEGIN
		IF NOT EXISTS(select * from tOrderRow where Date=@today AND ((@isFilterByVaede=1 AND Vaede Like '%'+@CurrVaede+'%') OR @isFilterByVaede=0))
		BEGIN
		INSERT INTO tOrderRow(Code,CodeOut,Date,Vaede)
		SELECT StartOfNoInv,StartOfNoInvOut,@today,@CurrVaede FROM tSettPublic;

		INSERT INTO tOrderRowEmployee(Code,CodeOut,Date,Vaede)
		SELECT StartOfNoInv,StartOfNoInvOut,@today,@CurrVaede FROM tSettPublic;
		END;
		END
GO
/****** Object:  StoredProcedure [dbo].[SP_CheckProductMasrafiGoodsHaveNotCash]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_CheckProductMasrafiGoodsHaveNotCash]  
@FoodCode AS BIGINT,
@Quantity AS FLOAT,
@JustCount AS BIT
AS
BEGIN
      SELECT (@Quantity*tMavadeMasrafi.Num) AS UserConsuming,(tGoods.gName+'-'+tGoods.Name) AS GoodsName,UnitSell AS GoodsUnit,GoodsCash INTO #temp FROM tMavadeMasrafi
	  INNER  JOIN tGoods ON tGoods.Code=tMavadeMasrafi.fg_Code
	  LEFT JOIN (SELECT SUM(DebitNum-CreditNum) AS GoodsCash, GoodsNo FROM tGoodsCardex GROUP BY GoodsNo) tCardex ON tCardex.GoodsNo=tMavadeMasrafi.fg_Code
	  WHERE fCode=@FoodCode AND ISNULL(tGoods.IsNegativeCash,0)=0;

	  IF(@JustCount=1)
	  BEGIN
	      SELECT COUNT(*) FROM #temp
		  WHERE GoodsCash<UserConsuming
	  END
	  ELSE
	  BEGIN
	      SELECT '  * '+GoodsName+'-->'+CAST(GoodsCash AS NVARCHAR(100))+' '+GoodsUnit AS Des FROM #temp
		  WHERE GoodsCash<UserConsuming
	  END

	  DROP TABLE #temp
END
GO
/****** Object:  StoredProcedure [dbo].[SP_DataForPrintDelivery]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

CREATE PROCEDURE [dbo].[SP_DataForPrintDelivery] @sellNo AS BIGINT
		AS
		BEGIN
		DECLARE @myBit BIT =1;
		SELECT tSellItems.[Row],tSellItems.[f_gcode],tSellItems.[fCode],tSellItems.[SellNo],tSellItems.[Name],
		ABS((CASE WHEN tSellItems.State=0 THEN num ELSE tSellItems.[Num] END)) AS Num,tSellItems.[Price] AS Price
		,(tSellItems.Num*tSellItems.Price) as [Total],tSellItems.[Des],tSellItems.[ShowKitchen],tSellItems.[ShowAccounting],
		tSellItems.[State],tSellItems.[HDiscount],tSellItems.[HDiscountAmount],tSell.NumPerson AS [HDisAmount]
		,tSellItems.[isOut],tBaseFood.[ShowInAccounting],tBaseFood.[ShowInKitchen],tCategorys.PrinterName,tCategorys.PrinterTitle,
		tCategorys.PrinterCode,tBaseFood.ShowInPayk,tBaseFood.ShowInFish,tBaseFood.ShowInCust,tCategorys.TypeNo,isShowPriceColumn,
		isShowFooter,tSettPublic.Logo,@myBit AS isShowDes,ISNULL(tSellItems.ParentBatchName,'') AS ParentBatchName,tSellItems.ParentBatchNo,
		ISNULL(ParentBatchNum,0) AS ParentBatchNum,[isBatchTemplate] FROM tSellItems
		INNER JOIN (SELECT NumPerson,Code FROM tSell) tSell ON tSell.Code=tSellItems.SellNo
		INNER JOIN (SELECT tBaseFood.Code,tBaseFood.[ShowInAccounting],tBaseFood.[ShowInKitchen],ShowInFish,ShowInCust,Price1,ShowInPayk FROM tBaseFood) tBaseFood ON tBaseFood.Code=tSellItems.fCode
		LEFT JOIN (SELECT TOP 1 * FROM tSettPublic) tSettPublic ON LEN(tSettPublic.Title)>0
		LEFT JOIN (SELECT tCategory.Code ,tPrinters.PrinterName,tPrinters.TypeNo,tPrinters.Name AS PrinterTitle,tPrinters.Code AS PrinterCode,tPrinters.isShowPriceColumn,tPrinters.isShowFooter   FROM tCategory
		LEFT JOIN tPrinters on tPrinters.Code=tCategory.PrinterCode) tCategorys ON tSellItems.f_gcode=tCategorys.Code
		WHERE
		sellno=@sellNo AND 
		((tSellItems.num<=0 AND tSellItems.[state]=3) OR 
		(tSellItems.Num>0 AND tSellItems.[state]<>3))
		ORDER BY tSellItems.[Row] ASC

		END
	
GO
/****** Object:  StoredProcedure [dbo].[SP_DataForPrintSalon]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		
		
		CREATE  PROCEDURE [dbo].[SP_DataForPrintSalon]
		@sellNo AS BIGINT,
		@isCompletePrint AS BIT,
		@isResetedORisTasviye AS BIT,
		@isEditMode AS BIT,
		@PrintCompleteInvoiceOnRePring AS BIT
		
		AS
		BEGIN
		DECLARE @myBit BIT =1;
		SELECT tSellItems.[Row],tSellItems.[f_gcode],tSellItems.[fCode],tSellItems.[SellNo],
		tSellItems.[Name],
		ABS(CASE WHEN tSellItems.[State]=0 OR @PrintCompleteInvoiceOnRePring=1 THEN num ELSE CASE WHEN tSellItems.state=3 THEN 0 ELSE (tSellItems.Num-tSellItems.OldNum) END END) AS Num,
		tSellItems.[Price] AS Price
		,(tSellItems.Num*tSellItems.Price) AS [Total],tSellItems.[Des],tSellItems.[ShowKitchen],tSellItems.[ShowAccounting],
		tSellItems.[State],tSellItems.[HDiscount],tSellItems.[HDiscountAmount],tSell.NumPerson as [HDisAmount]
		,tSellItems.[isOut],tBaseFood.[ShowInAccounting],tBaseFood.[ShowInKitchen],tCategorys.PrinterName,
		tCategorys.PrinterTitle,tCategorys.PrinterCode,tBaseFood.ShowInFish,tBaseFood.ShowInPayk,tBaseFood.ShowInCust,
		tCategorys.TypeNo,isShowPriceColumn,isShowFooter,tSettPublic.Logo,@myBit AS isShowDes,tSellItems.ParentBatchNo,
		ISNULL(tSellItems.ParentBatchName,'') AS ParentBatchName,ISNULL(ParentBatchNum,0) AS ParentBatchNum,[isBatchTemplate]
		 FROM tSellItems
		INNER JOIN (SELECT NumPerson,Code FROM tSell) tSell on tSell.Code=tSellItems.SellNo
		INNER JOIN (SELECT tBaseFood.Code,tBaseFood.[ShowInAccounting],tBaseFood.[ShowInKitchen],ShowInFish,ShowInCust,Price1,ShowInPayk FROM tBaseFood ) tBaseFood ON tBaseFood.Code=tSellItems.fCode
		LEFT JOIN (SELECT TOP 1 * FROM tSettPublic) tSettPublic on Len(tSettPublic.Title)>0
		LEFT JOIN (SELECT tCategory.Code ,tPrinters.PrinterName,tPrinters.TypeNo,tPrinters.[Name] AS PrinterTitle,tPrinters.Code AS PrinterCode,tPrinters.isShowPriceColumn,tPrinters.isShowFooter   FROM tCategory LEFT JOIN tPrinters ON tPrinters.Code=tCategory.PrinterCode) tCategorys ON tSellItems.f_gcode=tCategorys.Code
		WHERE sellno=@sellNo AND
		(
		   @isCompletePrint=0 OR 
		  (@isCompletePrint=1 AND OldNum<>0 AND ((tSellItems.num<=0 and tSellItems.[state]=3) OR (tSellItems.Num>0 AND tSellItems.[state]<>3)))
		) AND
		(
		  @PrintCompleteInvoiceOnRePring=1 OR  
		  (@PrintCompleteInvoiceOnRePring=0 AND 
		  (
		      ((@isResetedORisTasviye=1 OR (@isEditMode=1 AND  @isCompletePrint=1)) AND tSellItems.State in(-1,0,1,2,3)) OR
		      (@isEditMode=0 AND  tSellItems.State=-1) OR
		       tSellItems.State in(0,1,2,3))
		  )
		)
		ORDER BY tSellItems.[Row] ASC
		END

GO
/****** Object:  StoredProcedure [dbo].[SP_Get_InvoiceSellPayments]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_Get_InvoiceSellPayments] @InvoiceNo AS BIGINT
AS
BEGIN
     SELECT tSellPayments.[TypePayNo],tSellPayments.[BankId],tSellPayments.[ChequeSerialId],tSellPayments.[Amount],tSellPayments.[TrancNo] ,
	tSellPayments.[Date],tSellPayments.[CustomerCardNo],tSellPayments.[ReferenceNumber],tSellPayments.[TraceNumber] ,tSellPayments.[DocNo] ,
	tSellPayments.[IsDongi],tSellPayments.[DongNum],tSellPayments.[IsCash],tSellPayments.[IsCard],tSellPayments.[IsCheque] ,
	tBank.Logo,(tBank.Name+' '+tBank.Branch) AS BankName,tBank.AccNo,
	tTypePay.Title AS TypePayTitle,ISNULL(IsCustomerClub,0) AS IsCustomerClub,ISNULL(IsBayeane,0) AS IsBayeane
	FROM tSellPayments
	LEFT JOIN tBank ON tBank.Code=tSellPayments.BankId
	LEFT JOIN tTypePay ON tTypePay.Code=tSellPayments.TypePayNo
	WHERE SellNo=@InvoiceNo
END;

GO
/****** Object:  StoredProcedure [dbo].[SP_Get_List_Sell]    Script Date: 4/4/2024 7:04:33 PM ******/

CREATE PROCEDURE [dbo].[SP_Get_List_Sell] 
@IsGenerateOrderRowForInvoice AS BIT,
@NotReset AS INT,
@NotReseted AS INT,
@SaveInCustAcc AS INT,
@Returned AS INT,
@Deleted AS INT,
@Reseted AS INT,

@NotResetTxt AS NVARCHAR(50),
@SaveInCustAccTxt AS NVARCHAR(50),
@ReturnedTxt AS NVARCHAR(50),
@DeletedTxt AS NVARCHAR(50),
@ResetedTxt AS NVARCHAR(50),

@lbInvoiceNotVagozar AS NVARCHAR(50),
@lbInvoiceVagozarToDriver AS NVARCHAR(50),
@lbInvoiceResetedByDriver AS NVARCHAR(50),

@DateOf AS NVARCHAR(10),
@DateThan AS NVARCHAR(10),
@filter AS NVARCHAR(50)='',
@ByVaedes AS NVARCHAR(100)='',
@TypeOrder AS INT=-1,
@IncludeCash AS SMALLINT=-1,
@IncludeCard AS SMALLINT=-1,
@IncludeOnline AS SMALLINT=-1,
@isJustSave AS SMALLINT=-1,
@SellNo AS BIGINT=-1,
@IsReseted AS SMALLINT=-1,
@IsNotReseted AS SMALLINT=-1,
@IsDeleted AS SMALLINT=-1,
@IsReturned AS SMALLINT=-1,
@Reserved AS INT,
@ReservedTxt AS NVARCHAR(50)
AS
BEGIN
       
       SELECT ROW_NUMBER() OVER (ORDER BY  CASE WHEN @IsGenerateOrderRowForInvoice=1 THEN  tSell.OrderRow ELSE  tsell.[time] END   DESC) AS r,
            tSell.OrderRow,
			
            CASE WHEN tSell.State=@NotReset OR tSell.State=@NotReseted THEN @NotResetTxt 
            ELSE CASE WHEN tSell.State=@SaveInCustAcc THEN @SaveInCustAccTxt
            ELSE CASE WHEN tSell.State=@Returned THEN @ReturnedTxt
            ELSE CASE WHEN tSell.State=@Deleted THEN @DeletedTxt 
            ELSE CASE WHEN tSell.State=@Reseted  THEN @ResetedTxt 
            ELSE CASE WHEN tSell.State=@Reserved THEN @ReservedTxt
            END END END END END END AS StateDES,

            CASE WHEN tSell.isOut=1 AND tSell.isCourier=0 THEN tSettPublic.isOutOnlyTxt  
            ELSE CASE WHEN tSell.isOut=1 AND tSell.isCourier=1 THEN tSettPublic.isOutWithDeliveryTxt  
            ELSE CASE WHEN tSell.isOut=1 AND tSell.isMobile=1 THEN N'آنلاین'  
            ELSE CASE WHEN tSell.isOut=0 THEN tSettPublic.isSalonTxt  
            END END END END AS TypeOrder,
			tSell.[Time],
			tSell.Garson,
			(CASE WHEN isOut=0 THEN ISNULL(tSeatGroup.Name,'')+' '+CAST(Seat AS NVARCHAR(5)) END ) AS SeatInf,
            tSell.[CustNo],
			tSell.CashBoxNo,
			
			ISNULL(tBase.Total,0) AS Total,
			ISNULL(tSell.Service,0) AS [Service],
			ISNULL(tSell.Scot,0) AS Scot,
			tSell.Rent,
			(ISNULL(tBase.Total,0)+ISNULL(tSell.Service,0)+ISNULL(tSell.Scot,0)+ISNULL(tSell.Rent,0)) AS TOTTOT,
			isnull(tSell.[Discount],0) AS Discount,
			tSell.CardAmount,
			tSell.CashAmount,
			isnull(tSell.Online,0) AS Online,
			isnull(tSell.CustomerClubCreditAffectedAmount,0) AS CustomerClubCreditAffectedAmount,
            ((tBase.Total+ISNULL(tSell.Rent,0)+isnull(tSell.Scot,0)-isnull(tSell.Discount,0)+ISNULL(tSell.Service,0))-(ISNULL(tSell.CardAmount,0)+ISNULL(CashAmount,0)+ISNULL(tSell.Online,0)+ISNULL(ChequeAmount,0)+ISNULL(tSell.CustomerClubCreditAffectedAmount,0))) AS Balance,
			tSell.[Name] AS NameCust,
			tSell.Mobile1,
			tSell.[Date],
			tSell.[Vaede],
			tSell.[Code],

			CourierName,
            CASE WHEN tSell.isPaykTasviye=0 THEN @lbInvoiceNotVagozar
            ELSE CASE WHEN tSell.isPaykTasviye=1 THEN @lbInvoiceVagozarToDriver 
            ELSE CASE WHEN tSell.isPaykTasviye=2 THEN @lbInvoiceResetedByDriver  END END END AS PaykStateDes, 
         	isPaykTasviye,
			tSell.UserName,
			[State],
			tSell.TimeTasviye,
			isCash,
			tSell.Mobile2,
			tSell.Tel,
			tSell.[Address],
			[tOrderEdited].EditCount,
			tSell.isOut,
			tSell.isCourier,
			ISNULL(tSell.ChequeAmount,0) AS ChequeAmount,
			isJustSave,
			isMobile,
			[LinkPayState],
			[LinkPayID],
			OnlinePayRefID ,
			dbo.Func_GetSellPaymentsTitles(tSell.Code) AS PaymentsTitle,
			CustomerClubCreditCardId,CustomerClubCreditCardHundred,CustomerClubCreditCardAmount ,
			tSell.ReasonCanceled
			INTO #Temp
			FROM tSell 
             LEFT JOIN (SELECT COUNT(*) AS EditCount,SellNo FROM [tOrderEdited] group by SellNo) [tOrderEdited] on [tOrderEdited].SellNo=tSell.Code
             INNER JOIN (SELECT Sum(tSellItems.BaseAmount*tSellItems.Num) AS BaseAmount,Sum(tSellItems.Num*tSellItems.Price) AS Total,SellNo FROM tSellItems group by SellNo) tBase on tBase.SellNo=tSell.Code 
             LEFT JOIN tSeatGroup  ON tSeatGroup.Code=tsell.SeatgCode 
			 LEFT JOIN tSettPublic ON 1=1
             WHERE
			 (@SellNo=-1 OR (@SellNo>-1 AND tSell.Code=@SellNo)) AND
			 SUBSTRING(Date,1,10)>=@DateOf AND SUBSTRING(Date,1,10)<=@DateThan AND 
			 (@filter='' OR (@filter<>'' AND  (tSell.[CustNo]=@filter OR tSell.[Name] LIKE '%'+@filter+'%' OR tSell.[Mobile1] LIKE '%'+@filter+'%' OR tSell.[Mobile2] LIKE '%'+@filter+'%' OR tSell.[Tel] LIKE '%'+@filter+'%' OR tSell.[Address] LIKE '%'+@filter+'%' OR tSell.[username] LIKE '%'+@filter+'%' OR tSell.[Garson] LIKE '%'+@filter+'%' OR tSell.[Vaede]=@filter))) AND
			 (@ByVaedes='' OR (@ByVaedes<>'' AND @ByVaedes LIKE '%'+tSell.[Vaede]+'%')) AND
			 (@TypeOrder=-1 OR 
			    (
				  @TypeOrder>-1 AND 
				  (
				    (@TypeOrder = 1  AND isOut=1 AND isCourier=0) OR
                    (@TypeOrder = 2  AND  isOut=1 AND isCourier=1) OR
                    (@TypeOrder = 3  AND  isOut=0 AND isCourier=0) OR
                    (@TypeOrder = 4  AND  isOut=1 AND isMobile=1) 
				  )
			    )
			 ) AND
			 (@IsReseted=-1 OR (@IsReseted>-1 AND tSell.isReseted=1)) AND
			 (@IsNotReseted=-1 OR (@IsNotReseted>-1 AND tSell.isReseted=0)) AND
			 (@IsDeleted=-1 OR (@IsDeleted>-1 AND tSell.[State]=3)) AND
			 (@IsReturned=-1 OR (@IsReturned>-1 AND tSell.[State]=4)) AND
			 
			 (@IncludeCash=-1 OR (@IncludeCash>-1 AND tSell.CashAmount>0)) AND
			 (@IncludeCard=-1 OR (@IncludeCard>-1 AND tSell.CardAmount>0)) AND
			 (@IncludeOnline=-1 OR (@IncludeOnline>-1 AND tSell.[Online]>0)) AND
			 (@isJustSave=-1 OR (@isJustSave>-1 AND tSell.isJustSave=1)) 

			 
            

			SELECT * FROM #Temp
			ORDER BY OrderRow DESC;

			DROP TABLE #Temp;
END
GO
/****** Object:  StoredProcedure [dbo].[SP_Get_Printers]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

CREATE  PROCEDURE [dbo].[SP_Get_Printers] @PCID AS NVARCHAR(100)=''
		AS
		BEGIN
		SELECT      isShowContactInf,isShowQRPayInPrint,NumCopyOutOnly,NumRePrintOutOnly,isJustInfCustomer,TypeNo,PCID,Code,PrinterName,Size,FontTitle,FontContent,
		FontSize,RightMargin,LeftMargin,TopMargin,BottomMargin,isShowPriceColumn,isShowFooter,NumCopy,NumReprint,NumCopyOut,
		NumReprintOut,isShowLogo,TypeFish,isShowBarcode,[isShowFamuseTerm],[isShowTotal1],[isShowTotal2],[isShowTypeDelivery],
		isShowDes,isShowSummaryFoods,Name,
		isShowTimeReadyFood ,
		isShowFamusTerm ,
		isShowScot ,
		isShowDiscount ,
		isShowRent ,
		isShowService ,
		isShowBirthdayOnFish ,
		isShowFooterMSG_Order ,
		LanguagePrint ,
		IsPrintFishAfterTasviye ,
		isReprintFishInChangeTablet ,
		isShowReprintAlert ,
		IsPrintFishBoxInSalon,
		isPrintFishPayk,
		isShowOtherFishInformatio,
		isShowDiffrenceTotal,
		OtherDes,IP,
		PrintCompleteInvoiceOnRePring FROM tPrinters
		WHERE @PCID='' OR (@PCID<>'' AND PCID=@PCID) AND isActive=1
END
GO
/****** Object:  StoredProcedure [dbo].[SP_Get_Top_Customer_Favorite_Products]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_Get_Top_Customer_Favorite_Products] 
@CustNo AS NVARCHAR(10),
@Mobile1 AS NVARCHAR(11),
@Mobile2 AS NVARCHAR(11),
@Tel1 AS NVARCHAR(11),
@Tel2 AS NVARCHAR(11)
AS
BEGIN

		SELECT TOP 5 Code,Name,TotalCount from tbasefood
		INNER JOIN (
					SELECT fCode,SUM(Num) AS TotalCount FROM tSellItems 
					INNER JOIN tSell ON tSell.Code=tSellItems.SellNo 
					WHERE (
					       (tSell.CustNo=@CustNo AND @CustNo<>'') OR 
					       (tSell.Mobile1=@Mobile1 AND @Mobile1<>'') OR
						   (tSell.Mobile1=@Mobile2 AND @Mobile2<>'') OR
						   (tSell.Mobile1=@Tel1 AND @Tel1<>'') OR
						   (tSell.Mobile1=@Tel2 AND @Tel2<>'') OR
						   (tSell.Mobile2=@Mobile2 AND @Mobile2<>'') OR 
						   (tSell.Mobile2=@Tel1 AND @Tel1<>'') OR 
						   (tSell.Mobile2=@Tel2 AND @Tel2<>'') OR 
						   (tSell.Tel=@Tel1 AND @Tel1<>'') OR 
						   (tSell.Tel2=@Tel2 AND @Tel2<>'')
						   )
					GROUP BY fCode
					) tTotal ON tTotal.fCode=tBaseFood.Code
		WHERE IsShowInFavoriteProduct=1 AND tBaseFood.IsActive=1 AND ISNULL(TotalCount,0)>0
		ORDER By TotalCount DESC
END
GO
/****** Object:  StoredProcedure [dbo].[SP_GetDailyOrderRow]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetDailyOrderRow] @typeOrder AS int, @today AS NVARCHAR(10),@CurrVaede AS NVARCHAR(20) AS BEGIN DECLARE @isFilterByVaede AS BIT; DECLARE @StartOut AS INT; DECLARE @StartSalon AS INT; DECLARE @MergeVaedes AS BIT; SELECT TOP 1 @isFilterByVaede=isFilterByVaede, @StartOut=StartOfNoInvOut, @StartSalon=StartOfNoInv,@MergeVaedes=IsMergeSalonAndOutNo FROM tSettPublic;  IF NOT EXISTS(SELECT * FROM tOrderRow WHERE Date=@today AND ((@isFilterByVaede=1 AND Vaede LIKE '%'+@CurrVaede+'%') OR @isFilterByVaede=0)) BEGIN INSERT INTO [tOrderRow]([Code],[CodeOut],[Date],[Vaede]) VALUES(@StartSalon,@StartOut,@today,CASE WHEN @isFilterByVaede=1 THEN @CurrVaede ELSE '' END); END;SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;BEGIN TRANSACTION;IF(@typeOrder=0 OR @MergeVaedes=1) BEGIN SELECT MAX(Code) FROM tOrderRow WHERE Date=@today AND ((@isFilterByVaede=1 AND Vaede LIKE '%'+@CurrVaede+'%') OR @isFilterByVaede=0); END ELSE BEGIN SELECT MAX(CodeOut) FROM tOrderRow WHERE Date=@today AND ((@isFilterByVaede=1 AND Vaede LIKE '%'+@CurrVaede+'%') OR @isFilterByVaede=0); END COMMIT TRANSACTION; END; 
GO
/****** Object:  StoredProcedure [dbo].[SP_getLastOrder]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		
	
		CREATE PROCEDURE [dbo].[SP_getLastOrder] @CurrentDate AS NVARCHAR(10),@CurrentVaede AS NVARCHAR(15),@isFilterByVaede AS BIT,@isResetOrderRow AS BIT
		AS
		BEGIN
		SELECT CASE WHEN @isResetOrderRow =1 THEN ISNULL(tSell.OrderRow,tSell.Code) ELSE tSell.Code END AS InvNo_OrderRow ,Vaede,
		((ISNULL(t13.Toti,0)+ISNULL(tSell.Rent,0)+ISNULL(tSell.Service,0)+ISNULL(tSell.Scot,0)+ISNULL(tSell.RoundAmount,0))-ISNULL(tSell.Discount,0)) AS Toti,tSell.isOut,tSell.Date,tSell.TableNo,tSell.GroupName,tSell.isReseted ,
		tSell.Code,tSell.isCourier,Time,State,[LinkPayState],[LinkPayID],OnlinePayRefID INTO #sells FROM tSell
		INNER JOIN (SELECT SellNo AS OrderST2,Sum(Total) AS Toti FROM tSellItems GROUP BY SellNo) t13 ON tSell.Code=t13.OrderST2
		WHERE   State NOT IN (3,4) AND SUBSTRING(Date,1,10)=@CurrentDate

		IF(@isFilterByVaede=1)
		BEGIN
		SELECT InvNo_OrderRow,Toti,Date,TableNo,GroupName,isReseted,
		Code,isCourier,isOut,Time,State,[LinkPayState],[LinkPayID],OnlinePayRefID FROM #sells
		WHERE Vaede=@CurrentVaede
		ORDER BY Code ASC
		END
		ELSE
		BEGIN
		SELECT InvNo_OrderRow,Toti,Date,TableNo,GroupName,isReseted,
		Code,isCourier,isOut,Time,State,[LinkPayState],[LinkPayID],OnlinePayRefID FROM #sells
		ORDER BY Code ASC
		END
		DROP TABLE #sells
		END
	
GO
/****** Object:  StoredProcedure [dbo].[SP_GetLastOrderRow]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetLastOrderRow] @typeOrder AS int,@today AS NVARCHAR(10),@CurrVaede 	AS NVARCHAR(20) AS BEGIN  DECLARE @isFilterByVaede AS BIT;  BEGIN  DECLARE @isMergeSalonAndOutNo AS BIT;  SELECT TOP 1 @isFilterByVaede=isFilterByVaede,@isMergeSalonAndOutNo=IsMergeSalonAndOutNo FROM tSettPublic; SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;BEGIN TRANSACTION;  SELECT MAX(OrderRow) FROM tSell  WHERE (@isMergeSalonAndOutNo=1 OR isOut=(CASE WHEN @typeOrder <> 0 THEN 1 ELSE 0 END)) AND SUBSTRING(Date,1,10)=@today AND ((@isFilterByVaede=1 AND Vaede LIKE '%' + @CurrVaede + '%') OR @isFilterByVaede=0); COMMIT TRANSACTION; END; end;
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderHeadersSalon]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderHeadersSalon] @today AS NVARCHAR(10), @vaede NVARCHAR(20),@currentTime AS NVARCHAR(20),@OrderBy AS INT=0 AS BEGIN SELECT Code AS OrderNo,NumPerson,SeatgCode,seat,[Time],DATEDIFF(minute,dbo.UDF_Julian_To_Gregorian(dbo.UDF_Persian_To_Julian(tsell.[Date]))+' '+SUBSTRING(tSell.[Time],1,5),dbo.UDF_Julian_To_Gregorian(dbo.UDF_Persian_To_Julian(@currentTime))+' '+SUBSTRING(@currentTime,11,5)) as pasteTime,CustNo,Name AS CustName,Mobile1 AS CustMobile,Garson,OrderRow INTO #temp FROM tSell WHERE Date=@today AND ISNULL(TimeTasviye,'')='' AND ISNULL(isReseted,0)=0  AND ((vaede=@vaede AND State<3 ) OR State NOT IN(3,4,5,10,13)) AND isOut=0 SELECT OrderNo,NumPerson,SeatgCode,seat,OrderRow,[Time],CASE WHEN pasteTime<1 THEN N'الان' ELSE CASE WHEN (pasteTime<60 AND pasteTime>=1) THEN (CAST(pasteTime AS nvarchar(10))+N' دقیقه پیش') ELSE ISNULL([Time],'') END END AS [OrderTime],CustNo,CustName,CustMobile,Garson INTO #List FROM #temp  IF(@OrderBy=0) BEGIN SELECT * FROM #List ORDER BY [Time] ASC END IF(@OrderBy=1) BEGIN SELECT * FROM #List ORDER BY [Time] DESC END  IF(@OrderBy=2) BEGIN SELECT * FROM #List ORDER BY NumPerson DESC END  DROP TABLE #temp DROP TABLE #List  END; 
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderItems]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderItems] @orderNo AS bigint AS BEGIN  SELECT tSellItems.Row,tSellItems.f_gcode AS CategoryId,tSellItems.fCode AS ProductId,tSellItems.Num AS Quantity,tSellItems.Price, tSellItems.HDiscountAmount AS Discount,tSellItems.Name AS ItemName,tSellItems.Des AS Explication,tSellItems.State,ISNULL(tBaseFood.isMonitor,0) AS  isMonitor, tBaseFood.Unit AS ProductUnit, tBaseFood.IsCheckNum, tBaseFood.IsCheckNumFix, tBaseFood.NumFix, tBaseFood.Num, tBaseFood.Name AS ProductName,ISNULL(NumInWeight,0) NumInWeight FROM tSellItems  LEFT JOIN tBaseFood ON tBaseFood.Code=tSellItems.fCode WHERE SellNo=@orderNo END; 
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderItemsForEdit]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderItemsForEdit] @InvNo BIGINT AS BEGIN SELECT tSellItems.*,t1.n1,t1.is1,t1.isCheckNum,t1.gn1,t1.PrinterName,tSellItems.Price as Price1,(tSellItems.Num*tSellItems.Price) as Total2,ProductFormula,ISNULL(ParentNo,0) AS ParentNo,hasServingFood,isBatchTemplate,'' as ColSubFoodBatchNo,ISNULL(tSellItems.ParentBatchName,'') AS ParentBatchName,ISNULL(tSellItems.ParentBatchNum,0) AS ParentBatchNum,DefaultNumBatchFood,Unit,tSellItems.NumInWeight FROM tSellItems INNER JOIN (SELECT Num AS n1,isInc AS is1,goodsNO AS gn1,Code AS ffcode,PrinterName,Price1,isCheckNum,ProductFormula,ParentNo,hasServingFood,DefaultNumBatchFood,Unit FROM tBasefood LEFT JOIN (SELECT COUNT(*) AS ProductFormula, fCode FROM tMavadeMasrafi GROUP BY fCode) tFormula ON tFormula.fCode=tBaseFood.Code) t1 ON t1.ffcode=tSellItems.fcode WHERE SellNo=@InvNo ORDER BY tSellItems.Row ASC END;
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderItemsForListSell]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderItemsForListSell] @InvNo BIGINT AS BEGIN SELECT [Name], [Num],[Price],[Total],[Des],[hDisAmount] FROM [tSellItems] WHERE SellNo=@InvNo  END;
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderItemTimeLogs]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderItemTimeLogs] @orderNo AS bigint AS BEGIN SELECT ProductId,[Time],Operation,Num FROM tSellItemsTimeLog WHERE SellNo=@orderNo; END;
GO
/****** Object:  StoredProcedure [dbo].[SP_GetOrderRowDelivery]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetOrderRowDelivery] @today AS NVARCHAR(10),@CurrVaede AS NVARCHAR(20)
			AS
			BEGIN
			SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
			BEGIN TRANSACTION;
			SELECT COUNT(*) FROM tSell
			WHERE isOut=1 AND isCourier=1 AND Date=@today AND Vaede=@CurrVaede AND State NOT IN(3,4,13)
			COMMIT TRANSACTION;
			END
GO
/****** Object:  StoredProcedure [dbo].[SP_GetSeatGroups]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_GetSeatGroups] @today AS NVARCHAR(10), @vaede AS NVARCHAR(20) AS  BEGIN Select  tSeatGroup.Code as ID,tSeatGroup.[Name] AS Title,tSeatGroup.Num AS NumOf,tSeatGroup.NumThan,ISNULL(tSells.cc,0) AS NumBusy FROM tSeatGroup  LEFT JOIN (SELECT COUNT(*) AS cc,SeatgCode FROM tSell  WHERE isOut=0 AND [Date]=@today AND  [State] NOT IN (3,4,5,10,13) AND ISNULL(seat,0)>0  AND  ISNULL(TimeTasviye,'')='' AND ISNULL(isReseted,0)=0 AND  (Vaede=@vaede OR State<3)  GROUP BY SeatgCode)  tsells on tsells.SeatgCode=tSeatGroup.Code END; 
GO
/****** Object:  StoredProcedure [dbo].[SP_GetSellCompareProduce]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO


		create procedure [dbo].[SP_GetSellCompareProduce] @DateOf AS NVARCHAR(10),@DateThan AS NVARCHAR(10),
		@goodsName AS NVARCHAR(50),@storageNo AS NVARCHAR(10)=''
		AS
		BEGIN

		SELECT SUM(tSell.NumInvoiceSell) AS NumInvoiceSell,tGoods.Code,
		SUM(tBuyItems.Num) AS Buy,
		SUM((ISNULL(tSellItems.Num,0)+ISNULL(tSellEmployeeItems.Num,0))*ISNULL(tMavadeMasrafi.Num,1)) AS Sell,
		SUM(ISNULL(tSellItems.Num,0)+ISNULL(tSellEmployeeItems.Num,0)) AS SellNum
		INTO #temp FROM tGoods
		INNER JOIN tMavadeMasrafi on tMavadeMasrafi.fg_Code=tGoods.Code
		INNER JOIN tBaseFood on tBaseFood.Code=tMavadeMasrafi.fCode
		LEFT JOIN tSellItems on tSellItems.fCode=tBaseFood.Code
		LEFT JOIN (Select Code,COUNT(*) AS NumInvoiceSell FROM tSell WHERE (SUBSTRING(tSell.Date,1,10)>=@Dateof and SUBSTRING(tSell.Date,1,10)<=@DateThan) AND State NOT IN(3,4) GROUP BY Code) tSell ON tSell.Code=tSellItems.SellNo
		LEFT JOIN tSellEmployeeItems ON tSellEmployeeItems.fCode=tBaseFood.Code
		LEFT JOIN (Select GoodsNo,Num FROM tBuyItems
		INNER JOIN tBuy ON tBuy.Code=tBuyItems.BuyNo
		WHERE (SUBSTRING(tBuy.Date,1,10)>=@DateOf and SUBSTRING(tBuy.Date,1,10)<=@DateThan)) tBuyItems ON tBuyItems.GoodsNo=tGoods.Code
		where ((tGoods.Name Like '%' + @goodsName + '%' AND @goodsName<>'') OR @goodsName='')
		GROUP BY tGoods.Code


		SELECT tgoods.Code,tgoods.Name,
		ISNULL(#temp.Buy,0) as Buy,
		ISNULL(#temp.Sell,0) as Sell,
		(ISNULL(#temp.Buy,0)-ISNULL(tGoods.FirstNum,0)+ISNULL(#temp.Sell,0)) AS Balance,
		ISNULL(tCardex.Num,0) AS Num,
		( ISNULL(tCardex.Num,0)-(ISNULL(#temp.Buy,0)-ISNULL(tGoods.FirstNum,0)+ISNULL(#temp.Sell,0)) ) AS deviation,
		SellNum,
		NumInvoiceSell FROM #temp
		INNER JOIN tGoods ON tgoods.Code=#temp.Code
		LEFT JOIN (SELECT SUM(DebitNum-CreditNum) AS Num,GoodsNo FROM tGoodsCardex WHERE (@storageNo='' OR (@storageNo<>'' AND @storageNo=StorageNo))  GROUP BY GoodsNo) tCardex ON tCardex.GoodsNo=tGoods.Code
		ORDER BY tGoods.Name ASC
		DROp TABLE #temp
		END
	
	
GO
/****** Object:  StoredProcedure [dbo].[SP_GoodsCardex]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO


		CREATE PROCEDURE [dbo].[SP_GoodsCardex]
		@goodsNo AS BIGINT,
		@StorageNo AS INT,
		@DateOf AS NVARCHAR(10),
		@DateThan AS NVARCHAR(10),
		@TypeOp int
		AS
		BEGIN
		SELECT [DocNo],[GoodsNo],[CatNo],[StorageNo],[Date],[TypeDoc]
		,[TypeNo],[DebitNum],[CreditNum],[Balance],[Exp],[Price]
		INTO #card
		FROM tGoodsCardex

		WHERE
		(@TypeOp=0 OR (@TypeOp>0 AND  TypeNo=@TypeOp)) AND
		GoodsNo=@goodsNo AND
		(LEN(@DateOf)=0 OR (LEN(@DateOf)>0 AND SUBSTRING([Date],1,10)>=@DateOf AND SUBSTRING([Date],1,10)<=@DateThan)) AND
		(@StorageNo=0 OR (@StorageNo>0 AND StorageNo=@StorageNo));


		SELECT  ROW_NUMBER() OVER (ORDER BY [DocNo] ASC) as r,
		[DocNo],ISNULL(tStorage.Name,N'[نا مشخص]') as [StorageName],
		[Date],[TypeDoc],[DebitNum],[CreditNum],Price,StorageNo,
		(SELECT SUM(b.DebitNum-b.CreditNum) as Balance FROM #card b WHERE   b.DocNo <= a.DocNo) as Balance,
		'BalanceTXT'=CASE
		WHEN (SELECT SUM(DebitNum-CreditNum)  FROM #card WHERE   DocNo <= a.DocNo)<0 THEN  N''
                            WHEN(SELECT SUM(DebitNum-CreditNum)  FROM #card WHERE   DocNo<= a.DocNo)>0 THEN   N'[مانده]'
		WHEN (SELECT SUM(DebitNum-CreditNum)  FROM #card WHERE   DocNo <= a.DocNo)=0 THEN N'[صفر]'
		END
		FROM #card a
		LEFT JOIN tStorage ON tStorage.Code=a.StorageNo
		ORDER BY DocNo ASC;
		END;

GO
/****** Object:  StoredProcedure [dbo].[SP_ListCeremony]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

CREATE PROCEDURE [dbo].[SP_ListCeremony]  
@today AS NVARCHAR(10),
@DueDateOf AS NVARCHAR(10),
@DueDateThan AS NVARCHAR(10),
@Vaede AS NVARCHAR(10)='',
@Type AS INT=0,
@SaveDateOf AS NVARCHAR(10)='',
@SaveDateThan AS NVARCHAR(10)=''
AS
BEGIN
  SELECT Code,[Date],DueDate,[DayName],[Vaede],[CustNo],[CustName],[Mobile1],[Mobile2],[Tel1],[Tel2],
  InvoiceId,[NumPerson],[NumPors],[Total],[Cash],[isReset],[Des],
 (CAST( (((CAST(SUBSTRING(DueDate,1,4) as int)-CAST(SUBSTRING(@today,1,4) as int))*365+
(CAST(SUBSTRING(DueDate,6,2) as int)-CAST(SUBSTRING(@today,6,2) as int))*30+
(CAST(SUBSTRING(DueDate,9,2) as int)-CAST(SUBSTRING(@today,9,2) as int))))  AS NVARCHAR(50))) AS remand 
INTO #temp FROM [tCeremony]  
WHERE 
(@DueDateOf='' OR (@DueDateOf<>'' AND DueDate>=@DueDateOf AND DueDate<=@DueDateThan)) AND
(@SaveDateOf='' OR (@SaveDateOf<>'' AND [Date]>=@SaveDateOf AND [Date]<=@SaveDateThan)) AND
(@Type=0 OR (@Type<>0 AND (@Type=1 AND isReset=1)));

SELECT Code,[DayName],[Vaede],remand,[CustName],[Mobile1],
  DueDate,InvoiceId,Date,[NumPerson],[NumPors],[Total],[Cash],
  (ISNULL(Total,0)-ISNULL(Cash,0)) AS Balance,[isReset],[Des],[Mobile2],[Tel1],[Tel2],[CustNo]
   FROM #temp
   WHERE
   (@Type=0 OR (@Type=2 AND remand>0))
   ORDER BY remand DESC;

DROP TABLE #temp;

END
GO
/****** Object:  StoredProcedure [dbo].[SP_ListCustomer]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE PROCEDURE [dbo].[SP_ListCustomer] @startPage AS INT,@endPage AS INT,@filterName AS NVARCHAR(30),
		@UnitedNo AS INT,@CityNo AS INT,@isDebits AS bit,@moearefNo AS nvarchar(20),
		@catname AS nvarchar(20),@isprint AS bit,@isBlackList as bit
		AS
		BEGIN
		SELECT SUM(ISNULL(TotalBuy,0)) AS TotalBuy,CustNo,MAX([Date]) as LastDate,Count(*) AS NumBuy INTO #sells FROM tSell
		INNER JOIN (SELECT SUM(tSellItems.Total) as TotalBuy,SellNo FROM tSellItems GROUP BY SellNo) titems on titems .SellNo=tSell.Code
		WHERE  tSell.State NOT IN(3,4)
		GROUP BY tsell.CustNo;
		SELECT Sum(Debit-Credit) AS Balance,CustNo INTO #custaccs FROM tCustAcc GROUP BY CustNo;

		select  row_number() over( Order By tCustomer.Name ASC) as r,ISNULL(Category,N'[بدون گروه]') AS Category,tCustomer.Code,(ISNULL(Prefix,'')+' '+tCustomer.Name) as Name,ABS(ISNULL(#custaccs.Balance,0)) as Balance,
		CASE WHEN #custaccs.Balance>0 THEN N'[بد]' ELSE CASE WHEN #custaccs.Balance<0 THEN N'[بس]' ELSE N'[بی حساب]' END END as BalanceTXT,
		Mobile1,Tel1,United,City,Address,WorkAddress,Rent,TypeDelivery,CategoryNo,ISNULL(#sells.TotalBuy,0) AS TotalBuy,#sells.NumBuy,#sells.LastDate,isBlackList,Tel2,Mobile2,tMoearefash.Code as MoearefNo,
		tMoearefash.Name as MoearefName,tMoearef.MoearefKardan,MaxMoearef,CityNo,UnitedNo INTO #list from tcustomer

		left join (Select Count(*) as MoearefKardan,MoearefNo from tCustomer group by MoearefNo) tMoearef on tCustomer.Code=tMoearef.MoearefNo
		left join (Select Name,Code from tCustomer) tMoearefash on tCustomer.MoearefNo=tMoearefash.Code
		left join #custaccs  ON #custaccs .CustNo=tCustomer.Code
		left join #sells  on #sells.CustNo=tCustomer.Code
		WHERE
		(@isBlackList=0 OR (@isBlackList=1 AND tCustomer.isBlackList=1)) AND
		(@isDebits='0' OR (@isDebits='1' AND #custaccs.Balance<>0)) AND
		(@UnitedNo=0 OR (@UnitedNo>0 AND tCustomer.UnitedNo=@UnitedNo)) AND
		(@CityNo=0 OR (@CityNo>0 AND tCustomer.CityNo=@CityNo)) AND
		(@moearefNo='' OR (@moearefNo<>'' AND tCustomer.MoearefNo=@moearefNo)) AND
		(@catname='' OR (@catname<>'' AND tCustomer.Category LIKE N'%'+@catname+'%')) AND
		((LEN(@filterName)>0 AND (tCustomer.Code=@filterName OR tCustomer.Name like N'%'+@filterName+'%' or tCustomer.Tel1 like N'%'+@filterName+'%' or tCustomer.Tel2 like N'%'+@filterName+'%' or tCustomer.mobile1 like N'%'+@filterName+'%' or tCustomer.Mobile2 like N'%'+@filterName+'%' or tCustomer.WorkAddress like N'%'+@filterName+'%' or tCustomer.Address like N'%'+@filterName+'%')) OR LEN(@filterName)=0)
		SELECT * FROM #list
		WHERE (@isprint=1 OR (@isprint=0 AND r>=@startPage AND r<=@endPage))
		Order by [Name] ASC;
		DROP TABLE #list;
		DROP TABLE #sells;
		END
GO
/****** Object:  StoredProcedure [dbo].[SP_LoadListGoods]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO




		CREATE PROCEDURE [dbo].[SP_LoadListGoods]  @storageNo AS NVARCHAR(10)=''
		AS
		BEGIN
		SELECT  Code,[Name],
		ISNUll(		tCardex.Num,0) AS num,Price1,Amount,gName,gCode,UnitSell,ShortcutKey,OrderRow,
		CASE WHEN LEN(ISNULL(Salon,''))>0 THEN Salon ELSE ' ' END AS Salon,
		CASE WHEN LEN(ISNULL(Shelf,''))>0 THEN Shelf ELSE ' ' END AS Shelf,
		CASE WHEN LEN(ISNULL(Floor,''))>0 THEN [Floor] ELSE ' ' END AS [Floor],
		Barcode,BarCode2,Discount,DiscountAmount
		FROM tGoods
		LEFT JOIN (SELECT SUM(DebitNum-CreditNum) AS Num,GoodsNo FROM tGoodsCardex WHERE (@storageNo='' OR (@storageNo<>'' AND @storageNo=StorageNo))  GROUP BY GoodsNo) tCardex ON tCardex.GoodsNo=tGoods.Code
		WHERE  isActive=1;
		END
GO
/****** Object:  StoredProcedure [dbo].[SP_LoadListGoodsForDiff]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO



		CREATE  PROCEDURE [dbo].[SP_LoadListGoodsForDiff]  @storageNo AS NVARCHAR(10)
		AS
		BEGIN
		DECLARE @CurrentNewNum FLOAT=0.000;
		DECLARE @CurrentDiffrenceNum FLOAT=0.000;
		SELECT  Code,gName,[Name],
		ISNULL(tCardex.Num,0) AS Num,@CurrentNewNum AS CurrentNewNum,@CurrentDiffrenceNum AS CurrentDiffrenceNum,gCode,Barcode
		FROM tGoods
		LEFT JOIN (SELECT SUM(ISNULL(DebitNum,0)-ISNULL(CreditNum,0)) AS Num,GoodsNo FROM tGoodsCardex WHERE (@storageNo='' OR (@storageNo<>'' AND @storageNo=StorageNo))  GROUP BY GoodsNo) tCardex ON tCardex.GoodsNo=tGoods.Code
		WHERE  isActive=1;
		END

	
	
GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
		cREATE PROCEDURE [dbo].[SP_Monthly_Report] @year as nvarchar(4)
		AS
		BEGIN
		CREATE TABLE #monthTitles(MonthNo NVARCHAR(2),MonthTitle NVARCHAR(50));
		INSERT INTO #monthTitles
		VALUES('01',N'فروردین'),
		('02',N'اردیهشت'),
		('03',N'خرداد'),
		('04',N'تیر'),
		('05',N'مرداد'),
		('06',N'شهریور'),
		('07',N'مهر'),
		('08',N'آبان'),
		('09',N'آذر'),
		('10',N'دی'),
		('11',N'بهمن'),
		('12',N'اسفند');

		SELECT  SUBSTRING([Date],1,8) AS Monthly ,ISNULL(tItems.Total,0) AS Total ,isOut,isCash,isCourier,Rent,isOnlinePayed INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year;

		SELECT SUM(Total) AS Total,COUNT(*) AS Num,Monthly INTO #salon FROM #sells WHERE isOut=0 GROUP BY Monthly;
		SELECT SUM(Total) AS Total,COUNT(*) AS Num,Monthly INTO #outInPerson FROM #sells WHERE isOut=1 AND isCourier=0 GROUP BY Monthly;
		SELECT SUM(Total) AS Total,COUNT(*) AS Num,Monthly INTO #outDelivery FROM #sells WHERE isOut=1 AND isCourier=1 GROUP BY Monthly;
		SELECT SUM(Total) AS Total,COUNT(*) AS Num,Monthly INTO #onlinePayed FROM #sells WHERE isOnlinePayed=1 GROUP BY Monthly;
		SELECT SUM(Rent) AS Total,COUNT(*) AS Num,Monthly INTO #rents FROM #sells WHERE isOut=1 AND isCourier=1 AND Rent>0 GROUP BY Monthly;


		SELECT 
		SUBSTRING(#outDelivery.Monthly,6,2) AS Monthly,
		(ISNULL(#salon.Num,0)+ISNULL(#outInPerson.Num,0)+ISNULL(#outDelivery.Num,0)) as TotalNum,
		ISNULL(#outDelivery.Total,0) as outDeliverySell,
		ISNULL(#outDelivery.Num,0) as outDeliveryCount,
		ISNULL(#outInPerson.Total,0) as outInPersonSell,
		ISNULL(#outInPerson.Num,0) as outInPersonCount,
		ISNULL(#salon.Total,0) as salonSell,
		ISNULL(#salon.Num,0) as salonCount,
		ISNULL(#onlinePayed.Total,0) as onlineSell,
		ISNULL(#onlinePayed.Num,0) as onlineCount,
		ISNULL(#rents.Num,0) as rentCount,
		ISNULL(#rents.Total,0) as rentSell,
		
		(ISNULL(#rents.Total,0)+ISNULL(#outDelivery.Total,0)+ISNULL(#onlinePayed.Total,0)+
		ISNULL(#outInPerson.Total,0)+ISNULL(#salon.Total,0)) as Total 
		INTO
		#final
		FROM #outDelivery
		LEFT JOIN #outInPerson ON #outInPerson.Monthly=#outDelivery.Monthly
		LEFT JOIN #salon ON #salon.Monthly=#outDelivery.Monthly
		LEFT JOIN #onlinePayed ON #onlinePayed.Monthly=#outDelivery.Monthly
		LEFT JOIN #rents ON #rents.Monthly=#outDelivery.Monthly
		ORDER BY Monthly ASC

		SELECT 
		SUM(TotalNum) TotalNum,
		SUM(outDeliverySell) outDeliverySell,
		SUM(outDeliveryCount) outDeliveryCount,
		SUM(outInPersonSell) outInPersonSell,
		SUM(outInPersonCount) outInPersonCount,
		SUM(salonSell) salonSell,
		SUM(salonCount) salonCount,
		SUM(onlineSell) onlineSell,
		SUM(onlineCount) onlineCount,
		SUM(rentCount) rentCount,
		SUM(rentSell) rentSell,
		SUM(Total) Total
		INTO #Summary
		FROM #final

		INSERT INTO #final(Monthly,TotalNum,
		outDeliverySell,
		outDeliveryCount,
		outInPersonSell,
		outInPersonCount,
		salonSell,
		salonCount,
		onlineSell,
		onlineCount,
		rentCount,
		rentSell,
		Total)
		SELECT N'  ',
		(TotalNum),
		(outDeliverySell),
		(outDeliveryCount),
		(outInPersonSell),
		(outInPersonCount),
		(salonSell),
		(salonCount),
		(onlineSell),
		(onlineCount),
		(rentCount),
		(rentSell),
		(Total)
		FROM #Summary

		SELECT #monthTitles.MonthTitle AS Monthly,TotalNum,
		outDeliverySell,
		outDeliveryCount,
		outInPersonSell,
		outInPersonCount,
		salonSell,
		salonCount,
		onlineSell,
		onlineCount,
		rentCount,
		rentSell,
		Total FROM #final
	    LEFT JOIN #monthTitles ON #monthTitles.MonthNo=#final.Monthly

		DROP TABLE #monthTitles
		DROP TABLE #final
		DROP TABLE #Summary
		DROP TABLE #sells
		DROP TABLE #outDelivery
		DROP TABLE #outInPerson
		DROP TABLE #salon
		DROP TABLE #onlinePayed

		end

GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report_By_Area]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO


		create PROCEDURE [dbo].[SP_Monthly_Report_By_Area] @year as nvarchar(4)
		AS
		BEGIN
		SELECT ISNULL(tItems.Total,0) AS Total,ISNULL(tCustomer.Area,'') AS ByMonth,tSell.Discount,ISNULL(tSell.Rent,0) AS TotalRent INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		INNER JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year AND ISNULL(tCustomer.Area,'')<>'';


		SELECT SUM(total) AS Total,SUM(Discount) AS Discount,SUM(TotalRent) AS TotalRent,ByMonth INTO #sells2 from #sells
		GROUP BY ByMonth

		SELECT #sells2.ByMonth,
		(#sells2.Total) as sells,
		0 as sellDebit,
		#sells2.TotalRent as rents,
		0 as [returns],
		0 as waste,
		0 as amani,
		0 as expense ,
		(#sells2.Discount) as discounts FROM #sells2
		ORDER BY #sells2.ByMonth ASC

		DROP TABLE #sells
		DROP TABLE #sells2
		end
	

	
GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report_By_CustGroup]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE PROCEDURE [dbo].[SP_Monthly_Report_By_CustGroup] @year as nvarchar(4)
		AS
		BEGIN
		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tCategoryCust.[Name],'') AS ByMonth,tSell.Discount,ISNULL(tSell.Rent,0) TotalRent INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tCategoryCust ON tCategoryCust.Code=tCustomer.CategoryNo
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year;

		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tCategoryCust.[Name],'') AS ByMonth,tSell.Discount INTO #sellDebits FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tCategoryCust ON tCategoryCust.Code=tCustomer.CategoryNo
		WHERE  tSell.State IN(0,-1,10) AND SUBSTRING([Date],1,4)=@year;

		SELECT SUM(total) AS Total,ByMonth INTO #sellDebits2 from #sellDebits
		GROUP BY ByMonth

		SELECT SUM(total) AS Total,SUM(Discount) AS Discount,SUM(TotalRent) AS TotalRent,ByMonth INTO #sells2 from #sells
		GROUP BY ByMonth

		SELECT #sells2.ByMonth,
		(#sells2.Total) as sells,
		(#sellDebits2.Total) as sellDebit,
		#sells2.TotalRent as rents,
		0 as [returns],
		0 as waste,
		0 as amani,
		0 as expense ,
		(#sells2.Discount) as discounts FROM #sells2
		LEFT JOIN #sellDebits2 on #sellDebits2.ByMonth=#sells2.ByMonth
		ORDER BY #sells2.ByMonth ASC
		DROP TABLE #sells
		DROP TABLE #sells2
		end
	
	
GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report_By_CustPrefix]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE  PROCEDURE [dbo].[SP_Monthly_Report_By_CustPrefix] @year as nvarchar(4)
		AS
		BEGIN
		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tTitleCustomer.[Name],'') AS ByMonth,tSell.Discount,ISNULL(tSell.Rent,0) AS TotalRent INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tTitleCustomer ON tTitleCustomer.Code=tCustomer.CategoryNo
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year;

		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tTitleCustomer.[Name],'') AS ByMonth,tSell.Discount INTO #sellDebits FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tTitleCustomer ON tTitleCustomer.Code=tCustomer.CategoryNo
		WHERE  tSell.State IN(-1,0,10) AND SUBSTRING([Date],1,4)=@year;

		SELECT SUM(total) AS Total,ByMonth INTO #sellDebits2 from #sellDebits
		GROUP BY ByMonth

		SELECT SUM(total) AS Total,SUM(Discount) AS Discount,SUM(TotalRent) AS TotalRent,ByMonth INTO #sells2 from #sells
		GROUP BY ByMonth

		SELECT #sells2.ByMonth,
		(#sells2.Total) as sells,
		(#sellDebits2.Total) as sellDebit,
		#sells2.TotalRent as rents,
		0 as [returns],
		0 as waste,
		0 as amani,
		0 as expense ,
		(#sells2.Discount) as discounts FROM #sells2
		LEFT JOIN #sellDebits2 on #sellDebits2.ByMonth=#sells2.ByMonth
		ORDER BY #sells2.ByMonth ASC
		DROP TABLE #sells
		DROP TABLE #sells2
		end
	

	
GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report_By_introduced]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

	
		CREATE  PROCEDURE [dbo].[SP_Monthly_Report_By_introduced] @year as nvarchar(4)
		AS
		BEGIN
		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tMoearef.[Name],'') AS ByMonth,tSell.Discount,ISNULL(tSell.Rent,0) AS TotalRent INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tCustomer tMoearef  ON tMoearef.Code=tCustomer.MoearefNo
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year;

		Select ISNULL(tItems.Total,0) AS Total,ISNULL(tMoearef.[Name],'') AS ByMonth,tSell.Discount INTO #sellDebits FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN tCustomer ON tCustomer.Code=tSell.CustNo
		LEFT JOIN tCustomer tMoearef  ON tMoearef.Code=tCustomer.MoearefNo
		WHERE  tSell.State IN(0,-1,10) AND SUBSTRING([Date],1,4)=@year;

		SELECT SUM(total) AS Total,ByMonth INTO #sellDebits2 from #sellDebits
		GROUP BY ByMonth

		SELECT SUM(total) AS Total,SUM(Discount) AS Discount,SUM(TotalRent) AS TotalRent,ByMonth INTO #sells2 from #sells
		GROUP BY ByMonth

		SELECT #sells2.ByMonth,
		(#sells2.Total) as sells,
		(#sellDebits2.Total) as sellDebit,
		(#sells2.TotalRent) as rents,
		0 as [returns],
		0 as waste,
		0 as amani,
		0 as expense ,
		(#sells2.Discount) as discounts FROM #sells2
		LEFT JOIN #sellDebits2 on #sellDebits2.ByMonth=#sells2.ByMonth
		ORDER BY #sells2.ByMonth ASC
		DROP TABLE #sells
		DROP TABLE #sells2
		end
	
	

	
	
GO
/****** Object:  StoredProcedure [dbo].[SP_Monthly_Report_By_User]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO

		CREATE PROCEDURE [dbo].[SP_Monthly_Report_By_User] @year as nvarchar(4)
		AS
		BEGIN
		Select ISNULL(tItems.Total,0) AS Total,ISNULL(UserName,'') AS ByMonth,tSell.Discount,ISNULL(tSell.Rent,0) AS TotalRent INTO #sells FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		WHERE  tSell.State NOT IN(3,4,13) AND SUBSTRING([Date],1,4)=@year;

		Select ISNULL(tItems.Total,0) AS Total,ISNULL(UserName,'') AS ByMonth,tSell.Discount INTO #sellDebits FROM tSell
		INNER JOIN (SELECT Sum(Num*Price) AS Total,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		WHERE  tSell.State IN(-1,0,10) AND SUBSTRING([Date],1,4)=@year;

		SELECT SUM(total) AS Total,ByMonth INTO #sellDebits2 from #sellDebits
		GROUP BY ByMonth

		SELECT SUM(total) AS Total,SUM(Discount) AS Discount,SUM(TotalRent) AS TotaLRent,ByMonth INTO #sells2 from #sells
		GROUP BY ByMonth

		SELECT #sells2.ByMonth,
		(#sells2.Total) as sells,
		(#sellDebits2.Total) as sellDebit,
		#sells2.TotalRent as rents,
		0 as [returns],
		0 as waste,
		0 as amani,
		0 as expense ,
		(#sells2.Discount) as discounts FROM #sells2
		LEFT JOIN #sellDebits2 on #sellDebits2.ByMonth=#sells2.ByMonth
		ORDER BY #sells2.ByMonth ASC
		DROP TABLE #sells
		DROP TABLE #sells2
		end
	
	

	
	
GO
/****** Object:  StoredProcedure [dbo].[SP_OtherAddress_No_Subscribe]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_OtherAddress_No_Subscribe] @filter as nvarchar(50),@custno as nvarchar(10) ,@mobile1 as nvarchar(50),@mobile2 as nvarchar(50),@tel as nvarchar(50),@isJustCount as bit AS BEGIN  SELECT COUNT(*) AS CC,[Address] INTO #data FROM tSell WHERE (@mobile1='' OR  (@mobile1<>'' AND (Mobile1=@mobile1 OR Mobile2=@mobile1 OR Tel=@mobile1 OR Tel2=@mobile1))) AND (@mobile2='' OR  (@mobile2<>'' AND (Mobile1=@mobile2 OR Mobile2=@mobile2 OR Tel=@mobile2 OR Tel2=@mobile2))) AND (@tel='' OR  (@tel<>'' AND (Mobile1=@tel OR Mobile2=@tel OR Tel=@tel OR Tel2=@tel))) AND (@filter='' OR @mobile1<>'' OR  (@filter<>'' AND [Name]=@filter)) AND (@custno='' OR @mobile1<>'' OR  (@custno<>'' AND CustNo=@custno)) AND LEN([Address])>0  GROUP BY [Address]  ORDER BY COUNT(*) DESC;  if @isJustCount=1 BEGIN SELECT COUNT(*) FROM #data; END ELSE BEGIN SELECT [Address],CC,'' AS Title,'' AS Area,'' AS Street,'' AS Koche,'' AS Mojtamae,'' AS Plaq,0 AS Rent,0 AS Row,0 AS AreaNo,'' AS Tel,'' AS Mobile1,'' AS Mobile2,ROW_NUMBER() over (ORDER BY CC DESC) AS OrderRow  FROM #data; END DROP TABLE #data; END;
  
GO
/****** Object:  StoredProcedure [dbo].[SP_ProductProfitLoss]    Script Date: 4/4/2024 7:04:33 PM ******/

GO

GO
CREATE PROCEDURE [dbo].[SP_ProductProfitLoss] 
@AvgOrLastOrFirst AS SMALLINT,
@DateOf AS NVARCHAR(10),
@DateThan AS NVARCHAR(10),
@Filter AS NVARCHAR(10)
AS
BEGIN
SELECT tBaseFood.Code AS ProductCode,tBaseFood.Name AS ProductName,ProductCost,LastSellPrice,
       CASE WHEN  ProductCost>LastSellPrice THEN ProductCost-LastSellPrice
	   ELSE CASE WHEN  ProductCost<LastSellPrice THEN LastSellPrice-ProductCost
	   ELSE 0 END END AS ProfiLoss,
	   CASE WHEN  ProductCost>LastSellPrice THEN N'زیان'
	   ELSE CASE WHEN  ProductCost<LastSellPrice THEN N'سود'
	   ELSE N'بدون سود' END END AS ProfiLossTxt
INTO #temp
FROM tBaseFood

LEFT JOIN (SELECT ISNULL(BuyPrice,tMavadeMasrafi.Price)*tMavadeMasrafi.Num AS ProductCost,
                 ISNULL(LastSellPrice,0) AS LastSellPrice,tMavadeMasrafi.fCode 
		   FROM tMavadeMasrafi
			LEFT JOIN (SELECT AVG(Price) AS BuyPrice,GoodsNo FROM tGoodsCardex
		                  WHERE Price>0 AND TypeNo=1 AND SUBSTRING([Date],1,10)>=@DateOf AND SUBSTRING([Date],1,10)<=@DateThan
					      GROUP BY GoodsNo
				         ) tBuyPrice ON tBuyPrice.GoodsNo=tMavadeMasrafi.fCode

			LEFT JOIN (SELECT AVG(Price) AS LastSellPrice,fCode FROM tSellItems
						INNER JOIN tSell ON tSell.Code=tSellItems.SellNo
						WHERE Price>0 AND SUBSTRING([Date],1,10)>=@DateOf AND SUBSTRING([Date],1,10)<=@DateThan AND tSell.[State] IN(-1,0,5,10)
						GROUP BY fCode
					   ) tSells ON tSells.fCode=tMavadeMasrafi.fCode

		   ) tProductSellAndProductCost ON tProductSellAndProductCost.fCode=tBaseFood.Code
 WHERE @Filter='' OR (@Filter<>'' AND (tBaseFood.Name LIKE N'%'+@Filter+'%'))

 SELECT * FROM #temp
 ORDER BY ProfiLoss DESC

 DROP TABLE #temp;
END
GO
/****** Object:  StoredProcedure [dbo].[SP_UpdateSellCustomerInfs]    Script Date: 4/4/2024 7:04:34 PM ******/

GO

GO
create procedure dailyReportTalar 
@DateOf NVARCHAR(10),
@DateThan NVARCHAR(10)
AS
BEGIN
      SELECT SUM(Total) AS TotalAmountCeremony,
	  COUNT(*) AS TotalCountCeremony FROM tSell
	  WHERE IsCeremony=1 AND State NOT IN(4,5) AND
	  SUBSTRING(Date,1,10)>=@DateOf AND SUBSTRING(Date,1,10)<=@DateThan;
END

GO

GO

	
	
CREATE PRocedure [dbo].[SP_UpdateSellCustomerInfs] @custNo AS NVARCHAR(20),@name AS NVARCHAR(50),@mobile1 AS NVARCHAR(20),@mobile2 AS NVARCHAR(20),@tel AS NVARCHAR(20),@address AS NVARCHAR(300)
AS
BEGIN
		print 'start:'
        print getdate()
        DECLARE @BusinessCursor as CURSOR;
		DECLARE @SellNo as NVARCHAR(50);

		SET @BusinessCursor = CURSOR FOR
		SELECT Code FROM tSell
		WHERE  State<>4 AND (
		(LEN(@mobile1)>0 AND (Mobile1=@mobile1 OR Mobile2=@mobile1 OR Tel=@mobile1)) OR
		(LEN(@mobile2)>0 AND (Mobile1=@mobile2 OR Mobile2=@mobile2 OR Tel=@mobile2)) OR
		(LEN(@tel)>0 AND (Mobile1=@tel OR Mobile2=@tel OR Tel=@tel)));
				
		print 'fetch(0):'
		print getdate()
 
		OPEN @BusinessCursor;
        FETCH NEXT FROM @BusinessCursor INTO @SellNo;
        WHILE @@FETCH_STATUS = 0
        BEGIN
          UPDATE tSell SET Name=@name, Tel=@tel, Mobile1=@mobile1, Mobile2=@mobile2
            WHERE Code=@SellNo
          FETCH NEXT FROM @BusinessCursor INTO @SellNo;
        END

		UPDATE tCustomer SET Name=@name, Tel1=@tel, Mobile1=@mobile1, Mobile2=@mobile2

            WHERE Code=@custNo;
        print 'finish:'
        print getdate()

END
GO
GO
CREATE PROCEDURE SP_GetInvoiceEmployees @InvoiceId BIGINT
AS
BEGIN
      SELECT tEmployee.Code EmployeeId,tEmployee.Name AS EmployeeName,t.Wage FROM tEmployee
	  LEFT JOIN tInvoiceEmployeeTalar t ON t.EmployeeId=tEmployee.Code
	  WHERE t.InvoiceId=@InvoiceId
END

GO
GO
CREATE PROCEDURE SP_GetCurrentVaede @CurrentTime AS NVARCHAR(10),@DayNo AS SMALLINT
AS
BEGIN
SELECT top 1 
        VaedeCode,Title FROM [tVaede] 
		INNER JOIN tVaedeSchedules t ON t.VaedeCode=tVaede.Code
		where t.DayNo=@DayNo AND 
                 (((TimeThan < TimeOf) and (@CurrentTime BETWEEN TimeOf AND '24:00' OR @CurrentTime BETWEEN '00:00' AND TimeThan)) OR  (@CurrentTime BETWEEN TimeOf AND TimeThan)) 


END
GO

CREATE PROCEDURE SP_Get_Employee_Karkard 
@EmployeeId AS BIGINT,
@DateOf AS NVARCHAR(10),
@DateThan AS NVARCHAR(10)
AS
BEGIN
SELECT tInvoiceEmployeeTalar.InvoiceId,tSell.DateReserve DateCeremony,tSell.Vaede AS CeremonyVaede,'' AS [DayOfWeek],
tInvoiceEmployeeTalar.Wage,tSell.Name AS CustomerName FROM tSell
LEFT JOIN tInvoiceEmployeeTalar ON tInvoiceEmployeeTalar.InvoiceId=tSell.Code 
WHERE tInvoiceEmployeeTalar.EmployeeId=@EmployeeId AND
(SUBSTRING(tSell.DateReserve,1,10)>=@DateOf AND SUBSTRING(tSell.DateReserve,1,10)<=@DateThan) AND
State NOT IN(4,5) AND IsCeremony=1;

END
GO

CREATE PROCEDURE  [SP_GetCeremonies] 
@DateOf AS NVARCHAR(10),
@DateThan AS NVARCHAR(10)
AS
BEGIN
SELECT tSell.Code InvoiceId,tSell.Name,tSell.Mobile1,tSell.Vaede,
		SUBSTRING(DateReserve,9,2) as DayNo,DateReserve,1 AS IsReserve,tVaede.Code AS VaedeCode,
		TotalBaeyane,
		ISNULL(TotalInvoice,0) TotalInvoice,
		ISNULL(tTotalPay.TotalPayment,0) TotalPayment,
		(ISNULL(TotalInvoice,0)-ISNULL(tTotalPay.TotalPayment,0)) Balance,
		tTalar.ListMojavez,tSell.[State],tSell.ReasonCanceled 
		from tSell
		LEFT JOIN tVaede ON tVaede.Title=tSell.Vaede
		LEFT JOIN tInvoiceEmployeeTalar tTalar ON tTalar.InvoiceId=tSell.Code
		LEFT JOIN (SELECT SUM(Total) AS TotalInvoice,SellNo FROM tSellItems  GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
		LEFT JOIN (SELECT SUM(Amount) AS TotalBaeyane,SellNo FROM tSellPayments WHERE IsBayeane=1 GROUP BY SellNo) tBayeane ON tBayeane.SellNo=tsell.Code
		LEFT JOIN (SELECT SUM(Amount) AS TotalPayment,SellNo FROM tSellPayments GROUP BY SellNo) tTotalPay ON tTotalPay.SellNo=tsell.Code


		WHERE IsCeremony=1 AND DateReserve>=@DateOf and DateReserve<=@DateThan AND State NOT IN(4,3)
END

GO

CREATE PROCEDURE SP_GetKarkardEmpoloyeesByVaede
@DateOf AS NVARCHAR(10),
@DateThan AS NVARCHAR(10)
AS
BEGIN
SELECT COUNT(*) AS TotalCeremony,tInvoiceEmployeeTalar.EmployeeId,SUM(Wage) AS TotalWage,SUM(TotalRec) TotalRec,tVaede.Code AS VaedeCode FROM tInvoiceEmployeeTalar
LEFT JOIN tSell ON tSell.Code=tInvoiceEmployeeTalar.InvoiceId
LEFT JOIN tVaede ON tVaede.Title=tSell.Vaede
LEFT JOIN (SELECT SUM(Debit) AS TotalRec,EmNo EmployeeId FROM tEmployeeAcc WHERE TypeNo=2 AND 
				SUBSTRING([Date],1,10)>=@DateOf and SUBSTRING([Date],1,10)<=@DateThan
				GROUP BY EmNo
		  ) 
		  tRec ON tRec.EmployeeId=tInvoiceEmployeeTalar.EmployeeId
WHERE tSell.State NOT IN(3,4) AND tsell.IsCeremony=1 AND 
DateReserve>=@DateOf and DateReserve<=@DateThan
GROUP BY tInvoiceEmployeeTalar.EmployeeId,tVaede.Code			

END

GO

CREATE PROCEDURE SP_GetSellForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10),@addTotalAmountSellThisMonth  AS BIT
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));

      SELECT SUM(TotalAmount) AS SumSell,SUM(Discount) AS TotalDiscount INTO #Sell FROM tSell
	  INNER JOIN (SELECT SUM(Price*Num) AS TotalAmount,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
	  WHERE tSell.Date>=@dateof AND tSell.Date<=@dateThan AND [State] NOT IN(3,4);

	  IF(@addTotalAmountSellThisMonth=1)
	  BEGIN
	       SELECT SUM(TotalAmount) AS SumSell INTO #SellInMonth FROM tSell
	       INNER JOIN (SELECT SUM(Price*Num) AS TotalAmount,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
	       WHERE SUBSTRING(tSell.Date,1,6)=SUBSTRING(@dateof ,1,6) AND [State] NOT IN(3,4); 
		   
		    IF EXISTS(SELECT * FROM #SellInMonth WHERE SumSell>0) 
	        BEGIN
		       INSERT INTO #tResult 
	           SELECT TOP 1 (N'جمع فروش این ماه: '+dbo.FormatMoney(SumSell))  FROM #SellInMonth;
			END;
	  END;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'جمع فروش: '+dbo.FormatMoney(SumSell))  FROM #Sell;
	  
	  IF EXISTS(SELECT * FROM #Sell WHERE TotalDiscount>0) 
	  BEGIN
	      INSERT INTO #tResult 
	      SELECT TOP 1 (N'جمع تحفیف: '+dbo.FormatMoney(TotalDiscount)) FROM #Sell;
	  END


	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Sell;
	  DROP TABLE #tResult;
END

GO
CREATE  PROCEDURE SP_GetSellByTypeOrderForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10),@addTotalAmountSellThisMonth  AS BIT
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));
	  DECLARE @isInPersonTxt AS NVARCHAR(50);
	  DECLARE @isDeliveryTxt AS NVARCHAR(50);
	  DECLARE @isSalonTxt AS NVARCHAR(50);

	  SELECT @isInPersonTxt=isOutOnlyTxt,
	         @isDeliveryTxt=isOutWithDeliveryTxt,
			 @isSalonTxt=isSalonTxt FROM tSettPublic;

      SELECT SellNo,(tItems.Num*tItems.Price) AS TotalItem,ISNULL(Discount,0) Discount,
	  CASE WHEN tSell.isOut=1 AND isCourier=1 THEN @isDeliveryTxt
	  ELSE CASE WHEN tSell.isOut=1 AND isCourier=0 THEN @isInPersonTxt
	  ELSE CASE WHEN tSell.isOut=0 THEN @isInPersonTxt
	  END END END AS TypeOrder
	  INTO #Sell FROM tSell
	  INNER JOIN tSellItems tItems ON tItems.SellNo=tSell.Code
	  WHERE tSell.Date>=@dateof AND tSell.Date<=@dateThan AND tSell.[State] NOT IN(3,4);

	  SELECT SUM(TotalItem) AS TotalAmount,SUM(Discount) AS TotalDiscount,TypeOrder INTO #Sell2 FROM #Sell
	  GROUP BY SellNo,TypeOrder

	  IF(@addTotalAmountSellThisMonth=1)
	  BEGIN
	       SELECT SUM(TotalAmount) AS SumSell INTO #SellInMonth FROM tSell
	       INNER JOIN (SELECT SUM(Price*Num) AS TotalAmount,SellNo FROM tSellItems GROUP BY SellNo) tItems ON tItems.SellNo=tSell.Code
	       WHERE SUBSTRING(tSell.Date,1,6)=SUBSTRING(@dateof ,1,6) AND [State] NOT IN(3,4); 
		   
		    IF EXISTS(SELECT * FROM #SellInMonth WHERE SumSell>0) 
	        BEGIN
		       INSERT INTO #tResult 
	           SELECT TOP 1 (N'جمع فروش این ماه: '+dbo.FormatMoney(SumSell))  FROM #SellInMonth;
			END;
	  END;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'جمع فروش '+TypeOrder+':'+dbo.FormatMoney(TotalAmount))  FROM #Sell2;
	  
	  IF EXISTS(SELECT * FROM #Sell2 WHERE TotalDiscount>0) 
	  BEGIN
	      INSERT INTO #tResult 
	      SELECT TOP 1 (N'جمع تحفیف: '+dbo.FormatMoney(SUM(TotalDiscount))) FROM #Sell2;
	  END


	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Sell;
	  DROP TABLE #tResult;
END
GO
CREATE PROCEDURE SP_CeremoniesForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10),@isAddSumKarkardPersonlOfVaede  AS BIT
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));
      
	  SELECT SellNo,(tItems.Num*tItems.Price) AS TotalItem,ISNULL(Discount,0) Discount,ISNULL(PersonelsWage,0) AS PersonelsWage
	  INTO #Sell FROM tSell
	  INNER JOIN tSellItems tItems ON tItems.SellNo=tSell.Code
	  LEFT JOIN (SELECT SUM(Wage) AS PersonelsWage,InvoiceId FROM tInvoiceEmployeeTalar GROUP BY InvoiceId) tEmp ON tEmp.InvoiceId=tSell.Code
	  WHERE tSell.DateReserve>=@dateof AND tSell.DateReserve<=@dateThan AND IsCeremony=1 AND tSell.[State] NOT IN(3,4);

	  SELECT SUM(TotalItem) AS TotalAmount,SUM(Discount) AS TotalDiscount,SUM(PersonelsWage) PersonelsWage,COUNT(*) AS TotalCount INTO #Sell2 FROM #Sell

	  IF(@isAddSumKarkardPersonlOfVaede=1 AND EXISTS(SELECT * FROM #Sell2 WHERE PersonelsWage>0)) 
	  BEGIN
		    INSERT INTO #tResult 
	        SELECT TOP 1 (N'جمع دستمزد وعده مزد: '+dbo.FormatMoney(PersonelsWage))  FROM #Sell2;
	  END;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'مراسمات ['+CAST(TotalCount AS nvarchar(10))+']:'+dbo.FormatMoney(TotalAmount))  FROM #Sell2;
	  
	  IF EXISTS(SELECT * FROM #Sell2 WHERE TotalDiscount>0) 
	  BEGIN
	      INSERT INTO #tResult 
	      SELECT TOP 1 (N'جمع تحفیف: '+dbo.FormatMoney(SUM(TotalDiscount))) FROM #Sell2;
	  END


	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Sell;
	  DROP TABLE #tResult;
END
GO

CREATE  PROCEDURE SP_GetBuyForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10)
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));
      
	  SELECT SUM(tItems.Num*tItems.Price) AS TotalAmount,COUNT(*) AS TotalCount INTO #Buy FROM tBuy
	  INNER JOIN tBuyItems tItems ON tItems.BuyNo=tBuy.Code
	  WHERE SUBSTRING(tBuy.Date,1,10)>=@dateof AND SUBSTRING(tBuy.Date,1,10)<=@dateThan;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'خرید ['+CAST(TotalCount AS nvarchar(10))+']:'+dbo.FormatMoney(TotalAmount))  FROM #Buy;
	  
	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Buy;
	  DROP TABLE #tResult;
END
GO
CREATE PROCEDURE [dbo].[SP_GetPaymentsForAdminSMS] @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10),@groupedByBank AS BIT
			AS
			BEGIN
			CREATE TABLE #tResult([Value]  NVARCHAR(100));

			SELECT tSellPayments.Amount,
			CASE WHEN tSellPayments.isCash=0 THEN N'کارت'
			ELSE CASE WHEN tSellPayments.isCard=0 THEN N'نقدی'
			ELSE CASE WHEN IsBayeane=0 THEN N'بیعانه'
			ELSE CASE WHEN IsCustomerClub=0 THEN N'باشگاه مشتریان'
			END END END END  AS TypePayTxt,TypePayNo
			INTO #Pays FROM tSellPayments
			INNER JOIN tSell ON tSell.Code=tSellPayments.SellNo
			WHERE SUBSTRING(tSell.Date,1,10)>=@dateof AND SUBSTRING(tSell.Date,1,10)<=@dateThan;

			SELECT tRecPayCustomer.Amount,
			CASE WHEN tRecPayCustomer.Card>0 THEN N'کارت'
			ELSE CASE WHEN tRecPayCustomer.Cash>0 THEN N'نقدی'
			END END AS TypePayTxt,ISNULL(tTypePay.Code,0) TypePayNo
			INTO #Pays4 FROM tRecPayCustomer
			LEFT JOIN tTypePay ON tTypePay.BankAccNo=tRecPayCustomer.AccNo
			WHERE SUBSTRING(tRecPayCustomer.Date,1,10)>=@dateof AND SUBSTRING(tRecPayCustomer.Date,1,10)<=@dateThan;

			INSERT INTO #Pays(Amount,TypePayTxt,TypePayNo)
			SELECT 
			Amount,TypePayTxt,TypePayNo
			FROM #Pays4

			SELECT SUM(Amount) AS TotalAmount,COUNT(*) AS TotalCount,TypePayTxt INTO #Pays2 FROM #Pays
			GROUP BY TypePayTxt;

			INSERT INTO #tResult
			SELECT TOP 1 (N'پرداخت '+TypePayTxt+' ['+CAST(TotalCount AS nvarchar(10))+']:'+dbo.FormatMoney(TotalAmount))  FROM #Pays2;

			IF(@groupedByBank=1)
			BEGIN
				SELECT SUM(Amount) AS TotalAmount,COUNT(*) AS TotalCount,tTypePay.Title TypePayTxt INTO #Pays3 FROM #Pays
				INNER JOIN tTypePay ON tTypePay.Code=#Pays.TypePayNo
				WHERE ISNULL(#Pays.TypePayNo,0)>0
				GROUP BY tTypePay.Title;

				INSERT INTO #tResult
				SELECT TOP 1 (TypePayTxt+' ['+CAST(TotalCount AS nvarchar(10))+']:'+dbo.FormatMoney(TotalAmount))  FROM #Pays3;
			    
				DROP TABLE #Pays3;
			END

			SELECT [Value] FROM #tResult;

			DROP TABLE #Pays;
			DROP TABLE #Pays2;
			DROP TABLE #Pays4;
			DROP TABLE #tResult;
			END
		
		

GO

CREATE PROCEDURE SP_GetDebitsCreditsForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10)
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));
      
	  SELECT SUM(ISNULL(Debit,0)-ISNULL(Credit,0)) Balance,CustNo 
	  INTO #CustDebits FROM tCustAcc
	  GROUP BY CustNo;

	  SELECT SUM(Total-ISNULL(TotalPay,0)) AS Balance
	  INTO #SellDebits FROM tSell
	  LEFT JOIN (SELECT SUM(Amount) TotalPay,SellNo FROM tSellPayments GROUP BY SellNo ) tInvoicePays ON tInvoicePays.SellNo =tSell.Code
	  WHERE [State] NOT IN(3,4,10) AND tSell.total>ISNULL(TotalPay,0);


	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'طلب کار:'+dbo.FormatMoney(SUM(Balance)))  FROM #CustDebits
	  WHERE Balance>0;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'طلب شما:'+dbo.FormatMoney(SUM(ABS(Balance))))  FROM #CustDebits
	  WHERE Balance<0;

	   INSERT INTO #tResult 
	  SELECT TOP 1 (N'بدهی فاکتور:'+dbo.FormatMoney(SUM(Balance)))  FROM #SellDebits;
	  
	  
	  SELECT [Value] FROM #tResult;

	  DROP TABLE #CustDebits;
	  DROP TABLE #SellDebits;
	  DROP TABLE #tResult;
END

GO
CREATE PROCEDURE SP_GetCustomersForAdminSMS @dateOf AS NVARCHAR(10),@dateThan AS NVARCHAR(10)
AS
BEGIN
      CREATE TABLE #tResult([Value]  NVARCHAR(100));
      
	  SELECT COUNT(*) AS CountRegistered
	  INTO #CustomerRegistered FROM tCustomer
	  WHERE SUBSTRING(DateSave,1,10)>=@dateOf AND SUBSTRING(DateSave,1,10)<=@dateThan; 

	  SELECT COUNT(*) AS CountAll
	  INTO #Customers FROM tCustomer;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'مشتریان جدید:'+dbo.FormatMoney(CountRegistered))  FROM #CustomerRegistered;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'کل مشتریان:'+dbo.FormatMoney(CountAll))  FROM #Customers;

	  SELECT [Value] FROM #tResult;

	  DROP TABLE #CustomerRegistered;
	  DROP TABLE #Customers;
	  DROP TABLE #tResult;
END
GO
CREATE TABLE [dbo].[tPeopleRfidCards](
	[RFIDSerialCard] [nvarchar](50) NOT NULL,
	[PersonId] [nvarchar](50) NOT NULL,
	[PersonType] [int] NOT NULL,
	[IsPrintReceipt] [bit] NULL,
	[IsSendSMS] [bit] NULL,
	[IsSendSMSInEnter] [bit] NULL,
	[IsSendSMSInLeave] [bit] NULL,
	[IsSendSMSToAdmin] [bit] NULL,
	IsHiredByVaede [bit] NULL,
	[Mobile] [nvarchar](50) NULL,
	[Name] [nvarchar](50) NULL,
	[Position] [nvarchar](50) NULL,
 CONSTRAINT [PK_tPeopleRfidCards] PRIMARY KEY CLUSTERED 
(
	[RFIDSerialCard] ASC
))
GO

CREATE PROCEDURE SP_BanksCashForAdminSMS @DateOf AS NVARCHAR(10),@DateThan AS NVARCHAR(10)
AS
BEGIN
       SELECT SUM(Credit-Debit) AS Balance,AccNo INTO #Balances FROM tBankAcc
	   GROUP BY AccNo;

	   SELECT Balance,(tBank.Name+' '+tBank.Branch) BankName INTO #BanksCash FROM #Balances
	   INNER JOIN tBank ON tBank.AccNo=#Balances.AccNo
	   WHERE Balance>=0;

	  CREATE TABLE #tResult([Value]  NVARCHAR(100));

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'موجودی بانک '+BankName+':'+dbo.FormatMoney(Balance))  FROM #BanksCash;

	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Balances;
	  DROP TABLE #BanksCash;
	  DROP TABLE #tResult;
END
GO
CREATE PROCEDURE SP_ExpensesForAdminSMS @DateOf AS NVARCHAR(10),@DateThan AS NVARCHAR(10)
AS
BEGIN
       SELECT SUM(Amount) Total INTO #Expenses FROM tExpenses
	   WHERE SUBSTRING(Date,1,10)>=@DateOf AND SUBSTRING(Date,1,10)<=@DateThan;
	    SELECT  distinct STUFF((
		SELECT ', ' + t2.TypeName+':'+t2.Des  
		FROM tExpenses t2
		WHERE t2.TypeNo = t1.TypeNo
		FOR XML PATH (''))
		,1,2,'') AS Names

  INTO #ExpenseTitles
FROM tExpenses t1
  WHERE SUBSTRING(Date,1,10)>=@DateOf AND SUBSTRING(Date,1,10)<=@DateThan;

	  CREATE TABLE #tResult([Value]  NVARCHAR(100));

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'جمع هزینه ها:'+dbo.FormatMoney(Total))  FROM #Expenses;

	 
      INSERT INTO #tResult 
	  SELECT TOP 1 (N'لیست هزینه ها:'+Names)  FROM #ExpenseTitles;
	  SELECT [Value] FROM #tResult;

	  DROP TABLE #Expenses;
	  DROP TABLE #ExpenseTitles;
	  DROP TABLE #tResult;
END
GO
CREATE	PROCEDURE SP_GetSessionRFIDInf
			@SessionId AS BIGINT,
			@PersonId NVARCHAR(50),
			@PersonType AS INT,
			@DayOfWeekNumber AS INT,
			@StartEnterHour AS INT,
			@StartEnterMinute AS INT,
			@CurrentMonthAndYear AS NVARCHAR(7),
			@Today AS NVARCHAR(10)
			AS
			BEGIN
			DECLARE @TimeNumber INT;
			SET @TimeNumber =@StartEnterHour*100+@StartEnterMinute;

			SELECT * INTO #Vacations FROM tVacation
			WHERE EmNo=@PersonId AND PersonType=@PersonType AND
			SUBSTRING([Date],1,6)=@CurrentMonthAndYear AND
			[Date]<=@Today;

			SELECT
			tTeachers.Name AS Teacher,
			tSessions.Id AS SessionId,
			tSessions.TotalSession,
			ISNULL(Presents.PresentSession,0) PresentSession,
			ISNULL(Absents.AbsentSession,0) AbsentSession,
			(tSessions.TotalSession-ISNULL(Absents.AbsentSession,0)-ISNULL(Presents.PresentSession,0) ) RemindSession,
			(@StartEnterMinute-tSessionSchedule.StartMinute) DelayPresentByMinute
			FROM tSessions
			INNER JOIN tCourses ON tCourses.Id=tSessions.CourseId
			INNER JOIN tEmployee tTeachers ON tTeachers.Code=tSessions.TeacherId
			LEFT JOIN (SELECT COUNT(*) AS PresentSession,PersonId FROM #Vacations WHERE StartTime<>'' GROUP BY EmNo) Presents ON Presents.EmNo=tSessions.PersonId
			LEFT JOIN (SELECT COUNT(*) AS AbsentSession,PersonId FROM #Vacations WHERE StartTime='' GROUP BY EmNo) Absents ON Absents.EmNo=tSessions.PersonId
			LEFT JOIN tSessionSchedule ON tSessionSchedule.SessionId=tSessions.Id
			WHERE tSessions.Id=@SessionId AND
			tSessionSchedule.[DayOfWeek]=@DayOfWeekNumber AND
			@TimeNumber>=(tSessionSchedule.StartHour*100+tSessionSchedule.StartMinute)  AND
			@TimeNumber<=(tSessionSchedule.EndHour*100+tSessionSchedule.EndMinute);

			DROP TABLE #Vacations;
			END
			GO

			CREATE TABLE [dbo].[tStudents](
			[Code] [bigint] IDENTITY(1,1) NOT NULL,
			[Name] [nvarchar](80) NULL,
			[NationalId] [nvarchar](10) NULL,
			[Mobile] [nvarchar](11) NULL,
			[ParentName] [nvarchar](80) NULL,
			[ParentMobile] [nvarchar](11) NULL,
			[Address] [nvarchar](500) NULL,
			[Birthday] [nvarchar](10) NULL,
			[DateRegister] [nvarchar](25) NULL,
			CONSTRAINT [PK_tStudents] PRIMARY KEY CLUSTERED
			(
			[Code] ASC
			));
	GO

			CREATE TABLE [dbo].[tCourses](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[CatId] [int] NOT NULL,
	[Name] [nvarchar](100) NULL,
	[TotalSessionsPerMonth] [int] NULL,
	[HundredOfTeacher] [int] NULL,
	[Amount] [money] NULL,
 CONSTRAINT [PK_tCourses] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
));
			GO
			CREATE TABLE [dbo].[tCourseCategories](
			[Code] [int] IDENTITY(1,1) NOT NULL,
			[Name] [nvarchar](80) NULL,
			CONSTRAINT [PK_tCourseCategories] PRIMARY KEY CLUSTERED
			(
			[Code] ASC
			));
			GO

			CREATE TABLE tPansionHeader
(Code BIGINT PRIMARY KEY IDENTITY,CustNo BIGINT NOT NULL,DateEntered NVARCHAR(10) NOT NULL,
IsReminder BIT,MobileOfReminder NVARCHAR(11),NumDayReminder INT,CostPerDay MONEY,[Des] NVARCHAR(MAX),DateSave NVARCHAR(20),Title NVARCHAR(100),
			[NumDayTasviyeInStart] [INT] NULL,
			isClosed BIT NULL,
			DateClosed NVARCHAR(10) NULL);

GO

	CREATE TABLE [dbo].[tPansionAccount](
			[Row] [bigint] IDENTITY(1,1) NOT NULL,
			[PansionCode] [bigint] NOT NULL,
			[DateSave] [nvarchar](20) NULL,
			[Des] [nvarchar](max) NULL,
			[Debit] [money] NULL,
			[Credit] [money] NULL,
			[Exp] [nvarchar](max) NULL,
			[TypeOp] [smallint] NULL,
			[TypeOpDes] [nvarchar](100) NULL,
			[DocNo] [BIGINT] NULL,
			StartDate NVARCHAR(10) NULL,
			EndDate NVARCHAR(10) NULL,
			CONSTRAINT [PK_tPansionAccount] PRIMARY KEY CLUSTERED
			(
			[Row] ASC,
			[PansionCode] ASC
			))

			GO

			CREATE PROCEDURE [dbo].[SP_ListPansions]
			@Today AS NVARCHAR(10),
			@Filter AS NVARCHAR(100),
			@DateEnteredOf AS NVARCHAR(10),
			@DateEnteredThan AS NVARCHAR(10),
			@IsDebits AS BIT
			AS
			BEGIN
			SELECT Code,Name CustName,Mobile1 CustomerMobile INTO #Customers FROM tCustomer;

			SELECT tPansionHeader.Code,
			tPansionHeader.Title,
			tPansionHeader.DateEntered,
			LastEndDatePansion, LastStartDatePansion,
			CASE WHEN LastReminderPassedDays IS NULL THEN dbo.[CalcRemind](@Today,tPansionHeader.DateEntered,0)
			ELSE LastReminderPassedDays END NumDayPassedFromDateEntered,
			tPansionHeader.CustNo,
			#Customers.CustName,
			tPansionAcc.PansionBalance,
			(CostPerDay*CASE WHEN LastReminderPassedDays IS NULL THEN dbo.[CalcRemind](tPansionHeader.DateEntered,@Today,1)
			ELSE LastReminderPassedDays END) TotalDebitSoFar,
			#Customers.CustomerMobile,
			IsReminder,
			MobileOfReminder,
			NumDayReminder,
			CostPerDay,
			[Des],
			tPansionHeader.DateSave,
			isClosed,
			DateClosed
			INTO #list
			FROM
			tPansionHeader
			INNER JOIN #Customers ON #Customers.Code=tPansionHeader.CustNo
			LEFT JOIN (SELECT SUM(Debit-Credit) AS PansionBalance,PansionCode FROM tPansionAccount GROUP BY PansionCode) tPansionAcc ON tPansionAcc.PansionCode=tPansionHeader.Code
			LEFT JOIN (SELECT  PansionCode,(dbo.[CalcRemind](StartDate,@Today,1)+1) AS LastReminderPassedDays,EndDate AS LastEndDatePansion,StartDate AS LastStartDatePansion 
						FROM tPansionAccount WHERE TypeOp=3 
						AND  [Row] IN (SELECT Max(Row) [Row] FROM tPansionAccount WHERE TypeOp=3  GROUP BY PansionCode)
			) tSent ON tSent.PansionCode=tPansionHeader.Code
			WHERE
			(@Filter='' OR (@Filter<>'' AND (#Customers.Code=@Filter OR tPansionHeader.Title LIKE N'%'+@Filter+'%' OR  #Customers.CustName LIKE '%'+@Filter+'%' OR #Customers.CustomerMobile LIKE '%'+@Filter+'%' OR MobileOfReminder LIKE '%'+@Filter+'%'))) AND
			(@DateEnteredOf='' OR (@DateEnteredOf<>'' AND DateEntered>=@DateEnteredOf AND DateEntered<=@DateEnteredThan));

			SELECT Code,
			Title,
			DateEntered,
			LastEndDatePansion, LastStartDatePansion,
			NumDayPassedFromDateEntered,
			CustNo,
			CustName,
			PansionBalance,
			TotalDebitSoFar,
			(ISNULL(PansionBalance,0)+ISNULL(TotalDebitSoFar,0)) TotalDebit,
			CustomerMobile,
			IsReminder,
			MobileOfReminder,
			NumDayReminder,
			CostPerDay,
			[Des],
			DateSave,
			isClosed,
			DateClosed
			FROM #list
			WHERE (@IsDebits=0 OR (@IsDebits=1 AND (PansionBalance>0 OR TotalDebitSoFar>0)));

			DELETE FROM #Customers;
			DELETE FROM #list;

			END
		
		
		
		
		
		
		
		

GO
CREATE PROCEDURE SP_Delete_Pansion @PansionCode AS BIGINT,@IsDeleteInvoices AS BIT,@IsDeleteRecMoney AS BIT 
AS
BEGIN
	   IF(@IsDeleteInvoices=1)
	   BEGIN
	         DELETE w FROM tSell w
	         INNER JOIN tPansionAccount ON tPansionAccount.DocNo=w.Code
	         WHERE tPansionAccount.TypeOp=0;

			 DELETE w FROM tSellItems w
	         INNER JOIN tPansionAccount ON tPansionAccount.DocNo=w.SellNo
	         WHERE tPansionAccount.TypeOp=0;
	   END

       DELETE FROM tPansionAccount WHERE PansionCode=@PansionCode;
	   DELETE FROM tPansionHeader WHERE Code=@PansionCode;
    
END
GO
CREATE TABLE [dbo].[tPansionSentReminder](
	[Row] [bigint] IDENTITY(1,1) NOT NULL,
	[PansionCode] [bigint] NOT NULL,
	[DateSent] [nvarchar](25) NULL,
	[UserName] [nvarchar](50) NULL,
	[Mobile] [nvarchar](11) NULL,
	[ResponseLog] [nvarchar](500) NULL,
	[IsSentSuccessed] [bit] NULL,
 CONSTRAINT [PK_tPansionSentReminder] PRIMARY KEY CLUSTERED 
(
	[Row] ASC,
	[PansionCode] ASC
))

GO
CREATE PROCEDURE [dbo].[SP_PansionForAdminSMS] @Today AS NVARCHAR(10)
			AS
			BEGIN
			SELECT tAcc.Debit,tPansionHeader.Code,
			CASE WHEN LastReminderPassedDays IS NULL THEN dbo.[CalcRemind](tPansionHeader.DateEntered,@Today,1)
			ELSE LastReminderPassedDays
			END NumDayPassedFromDateEntered,
			CostPerDay
			INTO #Pansions
			FROM tPansionHeader
			LEFT JOIN (SELECT SUM(ISNULL(Debit,0)-ISNULL(Credit,0)) AS Debit,PansionCode FROM tPansionAccount GROUP BY PansionCode) tAcc ON tAcc.PansionCode=tPansionHeader.Code
			LEFT JOIN (SELECT  PansionCode,(dbo.[CalcRemind](StartDate,@Today,1)+1) AS LastReminderPassedDays,EndDate AS LastEndDatePansion,StartDate AS LastStartDatePansion 
						FROM tPansionAccount WHERE TypeOp=3 
						AND  [Row] IN (SELECT Max(Row) [Row] FROM tPansionAccount WHERE TypeOp=3  GROUP BY PansionCode)
			) tSent ON tSent.PansionCode=tPansionHeader.Code

			WHERE
			ISNULL(tPansionHeader.isClosed,0)=0 AND
			tPansionHeader.IsReminder=1 AND
			(ISNULL(tSent.LastReminderPassedDays,0)>=tPansionHeader.NumDayReminder OR
			(tSent.LastReminderPassedDays IS NULL AND dbo.[CalcRemind](DateEntered,@Today,1)>=tPansionHeader.NumDayReminder)) AND
			LEN(tPansionHeader.MobileOfReminder)=11;

			SELECT COUNT(*) AS TotalCount,SUM((ISNULL(#Pansions.Debit,0)+ISNULL(NumDayPassedFromDateEntered,0)*ISNULL(CostPerDay,0))) AS TotalDebit
			INTO #PansionsAll
			FROM #Pansions
			WHERE (ISNULL(#Pansions.Debit,0)+ISNULL(NumDayPassedFromDateEntered,0)*ISNULL(CostPerDay,0))>0 ;

			SELECT COUNT(*) AS TotalCount
			INTO #PansionsNew
			FROM #Pansions
			WHERE NumDayPassedFromDateEntered<=1;

	  CREATE TABLE #tResult([Value]  NVARCHAR(100));
	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'پانسیون جدید:'+dbo.FormatMoney(TotalCount))  FROM #PansionsNew
	  WHERE TotalCount>0;

	  INSERT INTO #tResult 
	  SELECT TOP 1 (N'تعداد پانسیون:'+dbo.FormatMoney(TotalCount)+N' به مبلغ: '+dbo.FormatMoney(TotalDebit))  FROM #PansionsAll;

	  SELECT [Value] FROM #tResult;


	   DROP TABLE #Pansions;
	   DROP TABLE #PansionsAll;
	   DROP TABLE #PansionsNew;
END
GO

CREATE PROCEDURE [dbo].[SP_GetPansionsDebitForReminder] @Today AS NVARCHAR(10)
			,@JustPansionPeriod AS BIT
			AS
			BEGIN

			SELECT MobileOfReminder Mobile,CustNo,tPansionHeader.Title,
			tAcc.Debit,tPansionHeader.Code,
			tPansionHeader.CostPerDay,
			CASE WHEN tAdded.LastAddedDays IS NOT NULL THEN tAdded.LastAddedDays
			ELSE dbo.[CalcRemind](DateEntered,@Today,1)
			END AS TotalStayDays,NumDayReminder,LastReminderSentPassedDays
			INTO #Pansions 
			FROM tPansionHeader
			LEFT JOIN (SELECT SUM(Debit-Credit) AS Debit,PansionCode FROM tPansionAccount GROUP BY PansionCode) tAcc ON tAcc.PansionCode=tPansionHeader.Code
			LEFT JOIN (SELECT  PansionCode,dbo.[CalcRemind](SUBSTRING(DateSent,1,10),@Today,0) AS LastReminderSentPassedDays 
								FROM tPansionSentReminder
								WHERE IsSentSuccessed=1 AND 
								      [Row] IN (SELECT Max(Row) [Row] FROM tPansionSentReminder WHERE IsSentSuccessed=1  GROUP BY PansionCode)
			          )
			tSent ON tSent.PansionCode=tPansionHeader.Code
			LEFT JOIN (SELECT  PansionCode,(dbo.[CalcRemind](StartDate,@Today,1)+1) AS LastAddedDays,EndDate AS LastEndDatePansion,StartDate AS LastStartDatePansion 
						FROM tPansionAccount WHERE TypeOp=3 
						AND  [Row] IN (SELECT Max(Row) [Row] FROM tPansionAccount WHERE TypeOp=3  GROUP BY PansionCode)
			) tAdded ON tAdded.PansionCode=tPansionHeader.Code

			WHERE
			ISNULL(tPansionHeader.isClosed,0)=0 AND
			tPansionHeader.IsReminder=1 AND
			(LastReminderSentPassedDays IS NULL OR ISNULL(LastReminderSentPassedDays,0)>=tPansionHeader.NumDayReminder) AND
			
			LEN(tPansionHeader.MobileOfReminder)=11;

			select * from #Pansions


			SELECT CASE WHEN LEN(ISNULL(#Pansions.Mobile,''))=0 THEN tCustomer.Mobile1 ELSE #Pansions.Mobile END Mobile,
			#Pansions.CustNo,
			#Pansions.Title,
			CASE WHEN @JustPansionPeriod=1 THEN ISNULL(NumDayReminder,0)*ISNULL(CostPerDay,0)
			ELSE
			(ISNULL(#Pansions.Debit,0)+ISNULL(NumDayReminder,0)*ISNULL(CostPerDay,0))
			END Debit,
			tCustomer.[Name] CustName,#Pansions.Code,TotalStayDays
			FROM #Pansions
			INNER JOIN tCustomer ON tCustomer.Code=#Pansions.CustNo
			WHERE (ISNULL(#Pansions.Debit,0)+ISNULL(NumDayReminder,0)*ISNULL(CostPerDay,0))>0

			DROP TABLE #Pansions;
			END
GO


CREATE TABLE [dbo].[tStudentRegistersHeader](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[CourseId] [bigint] NOT NULL,
	[TeacherId] [bigint] NOT NULL,
	[StudentId] [bigint] NOT NULL,
	[DateRegistered] [nvarchar](10) NULL,
	[DateWillStart] [nvarchar](10) NULL,
	[Discount] [money] NULL,
	[TotalAmount] [money] NULL,
	[Exp] [nvarchar](max) NULL,
	[Username] [nvarchar](70) NULL,
 CONSTRAINT [PK_tStudentRegistersHeader] PRIMARY KEY CLUSTERED 
(
	[CourseId] ASC,
	[TeacherId] ASC,
	[StudentId] ASC
));
GO
CREATE TABLE [dbo].[tStudentRegistersSession](
	[RegisterId] [bigint] NOT NULL,
	[Date] [nvarchar](10) NOT NULL,
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[DayNo] [int] NOT NULL,
	[DayName] [nvarchar](25) NOT NULL,
	[TimeOf] [nchar](5) NOT NULL,
	[TimeThan] [nchar](5) NOT NULL,
	[IsParticipated] [bit] NOT NULL,
	[TimeEnter] [nchar](5) NULL,
	[TimeLeave] [nchar](5) NULL,
 CONSTRAINT [PK_tStudentRegistersSession] PRIMARY KEY CLUSTERED 
(
	[RegisterId] ASC,
	[Date] ASC
))

GO

CREATE PROCEDURE SP_Get_TeacherFreeTime @TeacherID BIGINT
AS
BEGIN
    SELECT Date,DayNo,DayName,TimeOf,TimeThan FROM tStudentRegistersSession
	INNER JOIN tStudentRegistersHeader Header ON Header.Id=tStudentRegistersSession.RegisterId
	WHERE Header.TeacherId=@TeacherID; 
END

GO

    delete from tStorage;INSERT INTO [tStorage] ([Code],[Name]) VALUES('A001',N'انبار مرکزی');
	delete from tUsers;INSERT INTO [tUsers] ([UserName],[Password],[BoxingNo],[img],[isKeepScreenOn],[screenLightValue],[isShowMessageSendToKitchen],[isOnline],[themeNo],[numItemInRow],[isTablet],[DiscountLimitOf],DiscountLimitThan ,DiscountLimitAmountOf ,[DiscountLimitAmountThan],[EditInvoicLimit],IsOnlySell) VALUES('admin','19ceb7d14ae53521c06ed054d60a8018]xSpPNob8Qpu_6lTC]ZfOdNOW0TTwtAsi8LClcCA==',1,null,1,255,1,0,1,4,0,-1,-1,-1,-1,-1,0);
	delete from tBoxing;INSERT INTO [tBoxing] ([Name]) VALUES(N'مدیریت');
	delete from tSellEmployeeNo;INSERT INTO [tSellEmployeeNo] ([Code]) VALUES('1');
	delete from tKhedmat;INSERT INTO [tKhedmat] ([Name]) VALUES(N'صندوق');INSERT INTO [tKhedmat] ([Name]) VALUES(N'آشپزخانه');INSERT INTO [tKhedmat] ([Name]) VALUES(N'انبار');INSERT INTO [tKhedmat] ([Name]) VALUES(N'سالن');INSERT INTO [tKhedmat] ([Name]) VALUES(N'پارکینگ');INSERT INTO [tKhedmat] ([Name]) VALUES(N'رستوران');
	delete from tTitleShogl;INSERT INTO [tTitleShogl] ([Name]) VALUES(N'شف');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'آشپز');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'سر آشپز');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'کمک آشپز');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'گارسون');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'صندوق دار');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'حسابدار');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'مسئول خرید');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'مدیر خرید');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'انباردار');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'نگهبان');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'نظافت چی');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'پاک بان');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'مدیر سالن');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'مدیر آشپزخانه');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'فیش جمع کن');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'کارگر ساده');INSERT INTO [tTitleShogl] ([Name]) VALUES(N'پیتزا پز');
	delete from tSettBackup;INSERT INTO [tSettBackup] ([BkPath],[FileBackName],[isBackupAutomat],[isAlterBKOnExit]) VALUES('C:\\','ShatootBK',0,1)
	delete from tSettBallot;INSERT INTO [tSettBallot] ([isBallotWithJeton],[isBallotWithMoney],[BallotJetonAmount],[BallotMoneyAmount],[BallotSelectFromListSell],[BallotSelectFromtCust],[isSendSMSBallot],[NumPersonToBallot]) VALUES(0,0,0,0,0,0,0,0);
	delete from tSettPrint;INSERT INTO [tSettPrint] ([isPrintFishBox],[isPrintFishKitchen],[isPrintFishFish],[isPrintFishCust],[NumFishBox],[NumFishKitchen],[NumFishFish],[NumFishCust],[isShowTimeReadyFood],[isShowFamusTerm],[isPrintSplitFish],[isShowAddressTel],[isShowScot],[isShowDiscount],[isShowRent],[isShowService],[isShowPriceColumn],[isShowBirthdayOnFish],[isFishKitchen_Smimilar_Box],[isReprintFishInChangeTablet],[isShowFooterMSG_Order],[DefaultPrinterKitchen],[DefaultPrinterCashier],[DefaultPrinterFishFish],[DefaultPrinterCustomer],[DefaultPrinterReport],[DefaultPrinterKitchenName],[DefaultPrinterCashierName],[DefaultPrinterFishFishName],[DefaultPrinterCustomerName],[DefaultPrinterReportName],[LanguagePrint],[LanguageDate],[isShowReprintAlert],[IsPrintFishBoxInSalon],[IsPrintFishAfterTasviye],[IsPrintFishSeatNo],[isPrintFishPayk],[DefaultPrinterPayk],[isShowOtherFishInformation],BarcodeType,BarcodeWidth,BarcodeHeight,TypeFish,isShowDiffrenceTotal,isShowBarcode,OtherDes,isPrintFishInSaveTablet,DefaultLabelPrinterName,isPreviewInvoicInSell,DefaultTypeFish,DefaultPrintSize) VALUES(1,1,0,0,1,1,0,0,0,1,0,1,1,1,1,1,0,0,0,1,1,'','','','','','','','','','','fa-ir','fa-ir',1,0,0,1,0,'',0,0,900,400,1,1,1,N'    *** با تشکر از خرید شما  ***   ',1,'',0,'','');
	delete from tSettPublic;INSERT INTO [tSettPublic] ([Title],[ShortTitle],[StartCustNo],[Tels],[Address],[Unit],[ScotNum],[Rent],[LevelTitle1],[LevelTitle2],[LevelTitle3],[LevelTitle4],[LevelTitle5],[Logo],[isShowLogoOnPrint],[AreaCode],[CallLogWait],[NumLines],[isAlertEndNumFoods],[isAlertEndNumGoods],[isSendSMSAfterOrder],[LimitNum],[isSendSMSAfterSaveCust],[isResetOrderRow],[DefaultTypeDelivery],[isShowFavFoods],[FavFoodsNum],[isSendSMSBirthday],[isRoundAmount],[isShowBalanceInInvoic],[isTimeExpireForEditInvoic],[TimeExpireForEditInvoic],[CornoTabletOrder],[isReminderCeremony],[isReminderBirthday],[isReminderCheque],[isShowCallLogInMainForm],[SkinName],[CurrLanguage],[DefaultService],[isShowDailySummary],[isTasviyeAfterSaveSalon],[IsReceiveOnlineOrder],[isAlertTypePay],[isAutoSizeProdButton],[isShowSelectCourier],[StartOfNoInv],[HourChangeVaede] ,[EghtesadNo],[DefaultDiscountOut],[StartOfNoInvOut],[RoundAmount],[DefaultDiscountSalon],[RoundType],[isSaveCallLog],[isShowFoodByList],[TopToBottomAddToListOrder],[IsMergeSalonAndOutNo],[isCloseFirstAccount],[OverToRent],[StartDateProgram],[isFilterByVaede],[isTasviyeAfterSendinTablet],[isLockOtherUsers],[IsShowSeatNoOnTop],[isDefaultInCallerID],[UpdateProductsAllClient],[DefaultDecimalPlace],isOutWithDelivery,isOutWithDeliveryTxt,isOutOnly,isOutOnlyTxt,isSalon,isSalonTxt,isCalcServiceByMinute,ServiceCeilingofTime,ServiceByMinute,isOnline,Options,Polysm,isShowOrderNumPayk) VALUES(N'شاتوت',N'Shatoot Software En','1','','',N'تومان',0,0,N'بیرون بر',N'سالن',N'کیوسک',N'آنلاین',N'مراسمات',null,1,'',0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,10,30,1,1,1,1,'Black','fa-ir',0,1,0,0,1,0,1,1,23,'',0,1,0,0,1,0,0,1,0,0,0,'',0,0,1,0,0,0,0,1,N'بیرون بر پیک',1,N'بیرون بر حضوری',1,N'سالن',0,0,0,0,'','',0);
	delete from tSettSMSPanel;INSERT INTO [tSettSMSPanel] ([SMSAPI],[SMSNumber],[SMSUID],[SMSPWD],[SMSReceiveNazar],[SMSReceiveOrder],[PrefixMobile],SMSSite,SMSInstagram,SMSTelegram,SMSAddress,SMSTel,SendSMSRemanderCustAccPeriod,isSendSMSRemanderCustAcc) VALUES('https://rest.payamak-panel.com/api/SendSMS/BaseServiceNumber','','','',0,0,'','','','','','',0,0);
	delete from tGhanoneKar;INSERT INTO [tGhanoneKar]([Year],[TotalDayWorkInMonthVezaratKar],[DarsadBime],[SahmeKarfarma],[SahmeEmployee],[SahmeDowlat]) VALUES(1397,220,30,20,7,3);
	delete from tUnits;INSERT INTO [tUnits] ([Name]) VALUES(N'عدد');INSERT INTO [tUnits] ([Name]) VALUES(N'پرس');INSERT INTO [tUnits] ([Name]) VALUES(N'کیلوگرم');INSERT INTO [tUnits] ([Name]) VALUES(N'گرم');INSERT INTO [tUnits] ([Name]) VALUES(N'بسته');INSERT INTO [tUnits] ([Name]) VALUES(N'متر');INSERT INTO [tUnits] ([Name]) VALUES(N'سانتی متر');INSERT INTO [tUnits] ([Name]) VALUES(N'اینچ');
	delete from tExplication;INSERT INTO tExplication VALUES(N'ران باشد','0001',0);INSERT INTO tExplication VALUES(N'سینه باشد','0001',0);INSERT INTO tExplication VALUES(N'برشته باشد','0001',0);INSERT INTO tExplication VALUES(N'بدون فلفل','0001',0);INSERT INTO tExplication VALUES(N'با فلفل','0001',0);INSERT INTO tExplication VALUES(N'بدون سس','0001',0);INSERT INTO tExplication VALUES(N'بدون سرویس','0001',0);INSERT INTO tExplication VALUES(N'نان اضافی','0001',0);INSERT INTO tExplication VALUES(N'بدون مخلفات','0001',0);INSERT INTO tExplication VALUES(N'بدون ادویه','0001',0);INSERT INTO tExplication VALUES(N'بدون قارچ','0001',0);INSERT INTO tExplication VALUES(N'بدون پیاز داغ','0001',0);INSERT INTO tExplication VALUES(N'با کشک','0001',0);INSERT INTO tExplication VALUES(N'بدون کشک','0001',0);INSERT INTO tExplication VALUES(N'پیاز داغ داشته باشد','0001',0);INSERT INTO tExplication VALUES(N'بدون کره','0001',0);INSERT INTO tExplication VALUES(N'سس تند','0001',0);INSERT INTO tExplication VALUES(N'سس سفید','0001',0);INSERT INTO tExplication VALUES(N'سس قرمز','0001',0);INSERT INTO tExplication VALUES(N'سس خردل','0001',0);INSERT INTO tExplication VALUES(N'سس مایونز','0001',0);INSERT INTO tExplication VALUES(N'سس کچاپ','0001',0);INSERT INTO tExplication VALUES(N'سس انار','0001',0);INSERT INTO tExplication VALUES(N'سس فرانسوی','0001',0);
	delete from tAshnayee;INSERT INTO [tAshnayee] VALUES(N'پیشنهاد دوستان');INSERT INTO [tAshnayee] VALUES(N'جستجوی اینترنتی');INSERT INTO [tAshnayee] VALUES(N'جستجوی فردی');INSERT INTO [tAshnayee] VALUES(N'اتفاقی');INSERT INTO [tAshnayee] VALUES(N'تبلیغات اینترنتی');INSERT INTO [tAshnayee] VALUES(N'تبلیغات خیابانی');INSERT INTO [tAshnayee] VALUES(N'تبلیغات محیطی');INSERT INTO [tAshnayee] VALUES(N'تبلیغات پیامکی');INSERT INTO [tAshnayee] VALUES(N'تبلیغات در شبکه های اجتماعی');
	 INSERT INTO tVaede(Code,Title) VALUES(1,N'صبحانه'),(2,N'نهار'),(3,N'شام');

                 INSERT INTO [tSeatGroup](Code,Name,Num,NumThan) VALUES(1,N'Seats',1,30);
		 
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(0,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(0,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(0,'16:01','02:00',3);
	 
	  INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(1,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(1,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(1,'16:01','02:00',3);
	 
	  INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(2,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(2,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(2,'16:01','02:00',3);
	 
 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(3,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(3,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(3,'16:01','02:00',3);
	 
 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(4,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(4,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(4,'16:01','02:00',3);
	 
 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(5,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(5,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(5,'16:01','02:00',3);
	 
 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(6,'02:01','10:00',1);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(6,'10:01','16:00',2);
	 INSERT INTO tVaedeSchedules(DayNo,TimeOf,TimeThan,VaedeCode) VALUES(6,'16:01','02:00',3);

	delete from tYear;
	INSERT INTO [tYear] ([Year],[isCurrent],[isBlocked]) VALUES(1403,1,0);
	delete from tCategoryCust;
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'عمومی');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'ادارات');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'کارمندان');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'پزشکان');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'مهندسین');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'پیمانکاران');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'دانشجویان');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'دانش آموزان');
	INSERT INTO [tCategoryCust]([Name]) VALUES(N'دبیران');
	delete from tTitleCustomer;
	INSERT INTO [tTitleCustomer]([Name]) VALUES(N'آقای');
	INSERT INTO [tTitleCustomer]([Name]) VALUES(N'خانم');
	INSERT INTO [tTitleCustomer]([Name]) VALUES(N'مهندس');
	INSERT INTO [tTitleCustomer]([Name]) VALUES(N'دکتر');INSERT INTO [tTitleCustomer]([Name]) VALUES(N'جناب آقای');INSERT INTO [tTitleCustomer]([Name]) VALUES(N'سرکار خانم');