-- This file is part of the it-crafts software and is subject to copyright protection.
-- (C) 2022, All rights reserved by Steffen Anders, Elsteraue - Germany
-- Visit also https://www.it-crafts.de.
--

IF 0 = (select count(*) from sysindexes si inner join sysobjects so 
   on  so.[xtype] = 'U'  and so.[name] = 'ut_WebLohnart' 
   and so.[id] = si.[id] and si.[name] = 'Ik_Optimize_Knr_StatusNum')
CREATE INDEX [Ik_Optimize_Knr_StatusNum] ON [dbo].[ut_WebLohnart] 
(
   [Knr],[StatusNum]
)
GO

--- ------------------------------------------------------------ Lohnarten abrufen
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'itcproc_WebLohnart_Abruf')
  DROP PROCEDURE [dbo].[itcproc_WebLohnart_Abruf]
GO
CREATE PROCEDURE [dbo].[itcproc_WebLohnart_Abruf]
  @Parm_Knr varchar(20)
 ,@Parm_Uid varchar(30)
 ,@Parm_StatusNum varchar(10) = -1
AS
	DECLARE @m_StatusNum integer
	SET     @m_StatusNum = CONVERT(integer,@Parm_StatusNum)

	IF @m_StatusNum >= 0 BEGIN
	  SELECT StatusNum, Lohnart, Comment FROM [dbo].[ut_WebLohnart]
	    WHERE Knr = @Parm_Knr AND StatusNum = @m_StatusNum
	END ELSE BEGIN
	  SELECT StatusNum, Lohnart, Comment FROM [dbo].[ut_WebLohnart]
	    WHERE Knr = @Parm_Knr
  	    ORDER BY StatusNum
	END
GO

---------------------------------------------------------------- Lohnart aktualisieren
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'itcproc_WebLohnart_Update')
  DROP PROCEDURE [dbo].[itcproc_WebLohnart_Update]
GO
CREATE PROCEDURE [dbo].[itcproc_WebLohnart_Update]
  @Parm_Knr varchar(20)
 ,@Parm_Uid varchar(30)
 ,@Parm_StatusNum varchar(10)
 ,@Parm_Lohnart varchar(20)
 ,@Parm_Comment varchar(50)
AS
	DECLARE @m_StatusNum integer
	SET     @m_StatusNum = CONVERT(integer,@Parm_StatusNum)

	UPDATE [dbo].[ut_WebLohnart] SET Lohnart = @Parm_Lohnart, Comment = @Parm_Comment
	    WHERE Knr = @Parm_Knr AND StatusNum = @m_StatusNum
GO
