IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_ReportPrintBarcode]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Op_Paye_NameKala_ReportPrintBarcode]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_PrintBarcodeLabel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Op_Paye_NameKala_PrintBarcodeLabel]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_PrintBarcodeLabel_Updateinfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Op_Paye_NameKala_PrintBarcodeLabel_Updateinfo]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_PrintBarcodeLabel_Updateinfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[Op_Paye_NameKala_PrintBarcodeLabel_Updateinfo]
	@UserID INT,
	@GoKID NVARCHAR(MAX),
	@AID NVARCHAR(MAX),
	@KalaID NVARCHAR(MAX) ,
	@BarCode NVARCHAR(255),
	@Zarib DECIMAL(19 ,4),
	@type INT,
	@CurRound BIT,
	@CheckAllItem BIT
AS
BEGIN
    DECLARE @SQLQuery AS NVARCHAR(MAX)         	
    DECLARE @ParamDefinition AS NVARCHAR(MAX)          	
    DECLARE @OrderBy AS NVARCHAR(MAX)         	
    DECLARE @GROUPBy AS NVARCHAR(MAX)					   	
    
    
    IF (@type=1)
        SET @SQLQuery = '' update  T_NameKala Set [Flag1]= @CheckAllItem ''+CHAR(10)
    
    IF (@type=2)
        SET @SQLQuery = ''update  T_NameKala Set [FieldN1]= (ISNULL(@Zarib,0))  ''+CHAR(10) 
    
    SET @SQLQuery = @SQLQuery+'' WHERE  (1 = 1)   ''    	    	   
        
    IF (@GoKID IS NOT NULL)
        SET @SQLQuery = @SQLQuery+
            '' And (T_NameKala.ID IN(SELECT  T_NameKala.ID 	FROM     T_NameKala INNER JOIN 		T_Kala ON T_NameKala.ID = T_Kala.NameKalaID WHERE (T_Kala.GoKID IN ('' 
           +@GoKID+''))))''
    
    IF (@AID IS NOT NULL)
        SET @SQLQuery = @SQLQuery+
            '' And (T_NameKala.ID IN(SELECT  T_NameKala.ID 	FROM     T_NameKala INNER JOIN 		T_Kala ON T_NameKala.ID = T_Kala.NameKalaID WHERE (T_Kala.AID IN ('' 
           +@AID+''))))''
    
    IF (@KalaID IS NOT NULL)
    BEGIN
        SET @KalaID = ''%''+@KalaID+''%'' 			  			     	    
        SET @SQLQuery = @SQLQuery+'' And (NameKala1 LIKE  @KalaID )''
    END
    
    IF (@BarCode IS NOT NULL)
    BEGIN
        SET @SQLQuery = @SQLQuery+'' And (BarCode = @BarCode )''
    END
    
    IF (ISNULL(@CurRound ,0)=1)
    BEGIN
        SET @SQLQuery = @SQLQuery+'' And (Flag1 = @CurRound )''
    END
    
    
    
    
    SET @ParamDefinition = 
        ''@UserID INT,    	    @GOKID NVARCHAR(Max),    	    @AID  NVARCHAR(Max),    	    @KalaID NVARCHAR(Max),    	    @BarCode NVARCHAR(255),    	    @Zarib DECIMAL(19,4),     	    @CurRound BIT,    	    @CheckAllItem BIT''
    
    EXECUTE sp_Executesql @SQLQuery,
         @ParamDefinition,
         @UserID,
         @GOKID,
         @AID,
         @KalaID,
         @BarCode,
         @Zarib,
         @CurRound,
         @CheckAllItem
         
END 

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Op_Paye_NameKala_PrintBarcodeLabel]    Script Date: 05/03/2025 09:38:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_PrintBarcodeLabel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Op_Paye_NameKala_PrintBarcodeLabel]
	@UserID INT,
	@GoKID NVARCHAR(MAX),
	@AID NVARCHAR(MAX),
	@KalaID NVARCHAR(MAX),
	@CurRound BIT,
	@BarCode NVARCHAR(255)
	
AS
BEGIN
    DECLARE @SQLQuery AS NVARCHAR(MAX)     
    DECLARE @ParamDefinition AS NVARCHAR(MAX)      
    DECLARE @OrderBy AS NVARCHAR(MAX)     
    DECLARE @GROUPBy AS NVARCHAR(MAX)      	
    SET @SQLQuery = 
        ''SELECT  T_NameKala.*, CONVERT(money, ISNULL(vaznKala, 0) * (ISNULL(UnitPriceKharid, 0) + ISNULL(HazineKala, 0)) + (ISNULL(DarsadSoodKala, 0) * ISNULL(vaznKala, 0)) * (ISNULL(UnitPriceKharid, 0)                 + ISNULL(HazineKala, 0))) AS GhifoFinal FROM     T_NameKala WHERE  (1 = 1)   ''
    
    IF (@GoKID IS NOT NULL)
        SET @SQLQuery = @SQLQuery+
            '' And (T_NameKala.ID IN(SELECT  T_NameKala.ID 												FROM     T_NameKala INNER JOIN 												T_Kala ON T_NameKala.ID = T_Kala.NameKalaID WHERE (T_Kala.GoKID IN (''
           +@GoKID+''))))''
    
    IF (@AID IS NOT NULL)
        SET @SQLQuery = @SQLQuery+
            '' And (T_NameKala.ID IN(SELECT  T_NameKala.ID 						FROM     T_NameKala INNER JOIN 						T_Kala ON T_NameKala.ID = T_Kala.NameKalaID WHERE (T_Kala.AID IN (''
           +@AID+''))))''
    
    IF (@KalaID IS NOT NULL)
    BEGIN
        SET @KalaID = ''%''+@KalaID+''%'' 			  			 
        SET @SQLQuery = @SQLQuery+'' And (NameKala1 LIKE  @KalaID )''
    END
    
    IF (@BarCode IS NOT NULL)
    BEGIN
        SET @SQLQuery = @SQLQuery+'' And (BarCode = @BarCode )''
    END

    
    IF (ISNULL(@CurRound,0)=1)
    BEGIN
        SET @SQLQuery = @SQLQuery+'' And (Flag1 = @CurRound )''
    END
  
    
    SET @ParamDefinition = 
        ''@UserID INT, 								@GOKID NVARCHAR(Max), 								@AID  NVARCHAR(Max), 								@KalaID NVARCHAR(Max), 								@BarCode NVARCHAR(255), 								@CurRound BIT''
    
    SET @SQLQuery = @SQLQuery+'' ORDER BY NameKala1''     								   		    
    EXECUTE sp_Executesql @SQLQuery,
         @ParamDefinition,
         @UserID,
         @GOKID,
         @AID,
         @KalaID,
         @BarCode,
         @CurRound
         
END    ' 
END
GO
/****** Object:  StoredProcedure [dbo].[Op_Paye_NameKala_ReportPrintBarcode]    Script Date: 05/03/2025 09:38:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Op_Paye_NameKala_ReportPrintBarcode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[Op_Paye_NameKala_ReportPrintBarcode](@Aid INT, @OperType INT, @LinkMasterID NVARCHAR(50))
AS

-- مرحله ۱: حذف جدول موقت قبلی (در صورت وجود)
IF OBJECT_ID(''tempdb..#Numbers'') IS NOT NULL
BEGIN
    DROP TABLE #Numbers;
END


-- مرحله ۲: ایجاد جدول موقت
CREATE TABLE #Numbers (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    RowNum INT NOT NULL
);

-- مرحله ۳: وارد کردن ۱۰۰ عدد به جدول
DECLARE @Counter INT = 1;

SELECT    @Counter=MAX(FieldN1) 
FROM         T_NameKala
WHERE     (Flag1 = 1)


SET @Counter=ISNULL(@Counter,0)

WHILE @Counter > 0
BEGIN
    INSERT INTO #Numbers (RowNum)
    VALUES (@Counter);

    SET @Counter = @Counter - 1;
END

SELECT      T_NameKala.KalaNumber AS [كد كالا], T_NameKala.NameKala1 AS [نام كالا], T_NameVahed.NameVahed AS [واحد ], 
                      T_NameKala.BarCode AS [باركد كالا], T_NameKala.UnitPrice1 AS [قيمت فروش], T_NameKala.UnitPrice2 AS [قيمت فروش2], T_NameKala.UnitPrice3 AS [قيمت فروش3], 
                      T_NameKala.UnitPrice4 AS [قيمت فروش4], T_NameKala.UnitPrice5 AS [قيمت فروش5], T_NameKala.UnitPrice6 AS [قيمت فروش6], T_NameKala.VaznKala AS [وزن کالا], 
                      T_NameKala.HazineKala AS [ هزینه]
FROM         T_NameKala INNER JOIN
                      T_NameVahed ON T_NameKala.VAHED1 = T_NameVahed.VAHED1 CROSS JOIN
                      [#Numbers] AS n
WHERE     (NOT (T_NameKala.BarCode IS NULL)) AND (n.RowNum <= T_NameKala.FieldN1) AND (T_NameKala.Flag1 = 1)
ORDER BY T_NameKala.NameKala1' 
END
GO
