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

19 lines
950 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 PROCEDURE [dbo].[Hr_S_LeaveDaysRefresh]
@TenantId uniqueidentifier,
@EmployeeId uniqueidentifier
AS
BEGIN
SET NOCOUNT ON;
-- 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 r
SET Days = CASE WHEN r.IsHalfDay = 1 AND n.Days > 0.5 THEN 0.5 ELSE n.Days END
FROM Hr_T_LeaveRequest r
INNER JOIN Hr_T_LeaveType t ON t.Id = r.LeaveTypeId
CROSS APPLY (SELECT dbo.Hr_F_LeaveNetDays(@TenantId, r.EmployeeId, CAST(r.StartDate AS date), CAST(r.EndDate AS date)) AS Days) n
WHERE r.EmployeeId = @EmployeeId AND r.IsDeleted = 0 AND t.Code <> N'Sick'
AND r.Days <> CASE WHEN r.IsHalfDay = 1 AND n.Days > 0.5 THEN 0.5 ELSE n.Days END;
END
GO