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

41 lines
1.4 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_TrainingSync"(
p_TrainingId uuid,
p_UserId uuid DEFAULT NULL,
p_ActorId uuid DEFAULT NULL
)
LANGUAGE plpgsql
AS $$
DECLARE
v_TenantId uuid;
v_StartDate date;
v_EndDate date;
v_Participant uuid;
v_PlanId uuid;
BEGIN
-- Eğitim ya da katılımcı kaydından sonra çalışır (p_UserId boşsa eğitimin bütün katılımcıları):
-- "Katıldı" işaretli katılımcının eğitim günleri puantajda Eğitim olur (devamsız yazılmaz), bağlı
-- gelişim aksiyonu tamamlanır. Silinen katılımcı/eğitim ve değişen tarih için eski günleri
-- puantaj hesabı kendisi düzeltir.
SELECT "TenantId", "StartDate", "EndDate" INTO v_TenantId, v_StartDate, v_EndDate
FROM "Hr_T_Training"
WHERE "Id" = p_TrainingId;
IF v_StartDate IS NULL THEN
RETURN;
END IF;
FOR v_Participant IN
SELECT DISTINCT "UserId" FROM "Hr_T_TrainingParticipant"
WHERE "TrainingId" = p_TrainingId AND (p_UserId IS NULL OR "UserId" = p_UserId)
LOOP
CALL public."Hr_S_TimesheetCalculate"(v_TenantId, v_Participant, v_StartDate, v_EndDate, p_ActorId);
END LOOP;
FOR v_PlanId IN
SELECT "Id" FROM "Hr_T_DevelopmentPlan"
WHERE "TrainingId" = p_TrainingId AND "IsDeleted" = FALSE AND (p_UserId IS NULL OR "EmployeeId" = p_UserId)
LOOP
CALL public."Hr_S_DevelopmentPlanSync"(v_PlanId);
END LOOP;
END
$$;