DROP FUNCTION IF EXISTS fnGetOrahossz
GO

CREATE FUNCTION fnGetOrahossz (@csengetesiRendOraId int, @oraKezdete datetime, @oraVege datetime, @feladatKategoriaId int, @csoportId int, @oktatasiNevelesiFeladatTipus int, @csoportTipusOraperc int)
  RETURNS FLOAT
AS BEGIN
  
  DECLARE @result float;

  SET @result = 
    IIF(@csengetesiRendOraId IS NOT NULL
      ,1
      ,CONVERT(FLOAT,
        (
          DATEDIFF(minute, @oraKezdete, @oraVege)
          + IIF(@feladatKategoriaId = 7556 AND DATEPART(hour, @oraVege) = 23 AND DATEPART(minute, @oraVege) = 59
            ,1
            ,0)
        )
       )
       /
       IIF(@csoportId IS NULL
         ,IIF(@feladatKategoriaId = 7556 OR (@oktatasiNevelesiFeladatTipus IN (1157, 1166, 1177, 6570, 7762))
            ,60
            ,45)
         ,@csoportTipusOraperc)
    )

  RETURN @result;

END
GO