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

26 lines
1.1 KiB
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 PROCEDURE public."Hr_S_LeaveDaysRefresh"(
p_TenantId uuid,
p_EmployeeId uuid
)
LANGUAGE plpgsql
AS $$
BEGIN
-- Rapor eklenince, tarihi değişince ya da silinince çalışanın diğer izin taleplerinin gün sayısı
-- yeniden hesaplanır (Hr_F_LeaveNetDays): rapora denk gelen yıllık izin günü bakiyeye geri döner.
-- Rapor türündeki talep kendi günlerini sayar; onun gün sayısına dokunulmaz.
UPDATE public."Hr_T_LeaveRequest" AS r
SET "Days" = s."NewDays"
FROM (
SELECT x."Id",
CASE WHEN x."IsHalfDay" = TRUE AND n."Days" > 0.5 THEN 0.5 ELSE n."Days" END AS "NewDays"
FROM public."Hr_T_LeaveRequest" x
INNER JOIN public."Hr_T_LeaveType" t ON t."Id" = x."LeaveTypeId"
CROSS JOIN LATERAL (
SELECT public."Hr_F_LeaveNetDays"(p_TenantId, x."EmployeeId", x."StartDate"::date, x."EndDate"::date) AS "Days"
) n
WHERE x."EmployeeId" = p_EmployeeId AND x."IsDeleted" = FALSE AND t."Code" <> 'Sick'
) s
WHERE r."Id" = s."Id"
AND r."Days" <> s."NewDays";
END
$$;