sozsoft-platform/configs/seeds/postgres/object/Hr_F_TimesheetPeriodClosed.sql
2026-10-06 14:24:30 +03:00

26 lines
946 B
PL/PgSQL
Raw 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 REPLACE FUNCTION public."Hr_F_TimesheetPeriodClosed"
(
p_TenantId uuid,
p_StartDate date,
p_EndDate date
)
RETURNS boolean
LANGUAGE plpgsql
STABLE
AS $$
BEGIN
-- Aralığın değdiği aylardan biri kapalı puantaj dönemiyse TRUE. 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 p_StartDate IS NULL OR p_EndDate IS NULL THEN
RETURN FALSE;
END IF;
RETURN EXISTS (
SELECT 1 FROM "Hr_T_TimesheetPeriod" p
WHERE p."IsDeleted" = FALSE AND p."Status" = 'Closed'
AND p."TenantId" IS NOT DISTINCT FROM p_TenantId
AND p."PeriodYear" * 100 + p."PeriodMonth"
BETWEEN EXTRACT(YEAR FROM p_StartDate)::int * 100 + EXTRACT(MONTH FROM p_StartDate)::int
AND EXTRACT(YEAR FROM p_EndDate)::int * 100 + EXTRACT(MONTH FROM p_EndDate)::int);
END;
$$;