sozsoft-platform/configs/seeds/sql/object/Hr_F_TimesheetPeriodClosed.sql
2026-10-05 15:58:59 +03:00

25 lines
842 B
Transact-SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE OR ALTER FUNCTION [dbo].[Hr_F_TimesheetPeriodClosed]
(
@TenantId uniqueidentifier,
@StartDate date,
@EndDate date
)
RETURNS bit
AS
BEGIN
-- Aralığın değdiği aylardan biri kapalı puantaj dönemiyse 1. Puantajı değiştiren kayıtlar
-- (izin, rapor, puantaj günü) kapalı aya yazılamaz; dönemi İK açar, açılış ayı yeniden hesaplar.
IF @StartDate IS NULL OR @EndDate IS NULL
RETURN 0;
IF EXISTS (
SELECT 1 FROM Hr_T_TimesheetPeriod p
WHERE p.IsDeleted = 0 AND p.[Status] = N'Closed'
AND (p.TenantId = @TenantId OR (p.TenantId IS NULL AND @TenantId IS NULL))
AND p.PeriodYear * 100 + p.PeriodMonth
BETWEEN YEAR(@StartDate) * 100 + MONTH(@StartDate) AND YEAR(@EndDate) * 100 + MONTH(@EndDate))
RETURN 1;
RETURN 0;
END
GO