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

--------------------------------------------------------------------------------------------------------
-- Zeitbuchblätter abrufen
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P' and [name] = 'itcproc_ZeitKladdenKopf_get')
  DROP PROCEDURE [dbo].[itcproc_ZeitKladdenKopf_get]
GO
CREATE PROCEDURE [dbo].[itcproc_ZeitKladdenKopf_get]
  @Parm_Knr varchar(20)
 ,@Parm_Uid varchar(30)
 ,@Parm_Code varchar(20) = ''
 ,@Parm_DisableAll varchar(10) = '0'
AS
  DECLARE @m_Annr varchar(4) = ''
  DECLARE @m_AlleAnnr integer = 0
  SELECT @m_Annr = Annr, @m_AlleAnnr = AlleAnnr FROM ut_WebUser WITH(INDEX(Ik_Key00)) WHERE Knr = @Parm_Knr AND [Uid] = @Parm_Uid

  IF dbo.itcfunc_integer(@Parm_DisableAll) <> 0
    SET @m_AlleAnnr = 0

  SELECT k.RecId,k.Code, k.Bez, k.Annr, k.CpyAnnr, k.EnAnnr, k.EnStunden, k.EnBetrag, k.DupBuchDat, k.DupErfDat, k.CpyBuchDat, k.CpyErfDat, k.CpyLoa, k.Layout, 
         k.ShowAll, k.CpyBelNr, k.CpyKst, k.CpyKtr, k.CpyExtBelN, k.CpyVorgang, k.LogName, a.Name1
    FROM ut_ZeitKladdenKopf k
	LEFT JOIN ut_Adressen a ON a.DESTTYP = ' 4' AND a.Annr = k.Annr 
    WHERE (Code = @Parm_Code OR @Parm_Code = '') AND (k.Annr = @m_Annr OR @m_Annr = '' OR @m_AlleAnnr = 1)
    ORDER BY Code
GO
