44 lines
2.6 KiB
PL/PgSQL
44 lines
2.6 KiB
PL/PgSQL
CREATE OR REPLACE PROCEDURE public."Hr_S_LeaveNotify"(
|
||
p_RequestId uuid,
|
||
p_RecipientId uuid,
|
||
p_TypeName varchar(64),
|
||
p_SubjectKey varchar(128),
|
||
p_MessageKey varchar(128),
|
||
p_ActorId uuid DEFAULT NULL
|
||
)
|
||
LANGUAGE plpgsql
|
||
AS $$
|
||
BEGIN
|
||
-- Alıcı talepten gelir (müdür, İK onaycısı ya da çalışan); tipin Custom kuralları yalnızca
|
||
-- kanalı belirler. Metin TR dil anahtarından okunur, yer tutucular talepten dolar.
|
||
IF p_RequestId IS NULL OR p_RecipientId IS NULL THEN
|
||
RETURN;
|
||
END IF;
|
||
|
||
INSERT INTO public."Adm_T_Notification" ("Id", "TenantId", "NotificationRuleId", "NotificationChannel", "NotificationTypeId",
|
||
"Identifier", "UserId", "Message", "Subject", "IsSent", "IsRead", "CreationTime", "CreatorId", "IsDeleted")
|
||
SELECT gen_random_uuid(), lr."TenantId", r."Id", r."Channel", t."Id",
|
||
CASE WHEN r."Channel" = 'Mail' THEN u."Email" ELSE u."Id"::text END,
|
||
u."Id",
|
||
left(replace(replace(replace(replace(replace(replace(COALESCE(msg."Value", p_MessageKey),
|
||
'[Employee]', COALESCE(lr."EmployeeName", '')),
|
||
'[LeaveType]', COALESCE(lt."Name", '')),
|
||
'[StartDate]', to_char(lr."StartDate", 'DD.MM.YYYY')),
|
||
'[EndDate]', to_char(lr."EndDate", 'DD.MM.YYYY')),
|
||
'[Days]', rtrim(rtrim(to_char(round(lr."Days", 1), 'FM999999999990.0'), '0'), '.')),
|
||
'[Status]', COALESCE(lr."ApprovalStatus", '')), 2048),
|
||
left(COALESCE(sub."Value", p_SubjectKey), 256),
|
||
(r."Channel" = 'UiActivity'), FALSE, (NOW() AT TIME ZONE 'UTC'), p_ActorId, FALSE
|
||
FROM public."Hr_T_LeaveRequest" lr
|
||
INNER JOIN public."Hr_T_LeaveType" lt ON lt."Id" = lr."LeaveTypeId"
|
||
INNER JOIN public."AbpUsers" u ON u."Id" = p_RecipientId AND u."IsActive" = TRUE
|
||
INNER JOIN public."Adm_T_NotificationType" t ON t."Name" = p_TypeName AND t."IsDeleted" = FALSE
|
||
AND (t."TenantId" = lr."TenantId" OR (t."TenantId" IS NULL AND lr."TenantId" IS NULL))
|
||
INNER JOIN public."Adm_T_NotificationRule" r ON r."NotificationTypeId" = t."Id" AND r."IsActive" = TRUE
|
||
AND r."IsCustomized" = FALSE AND r."IsDeleted" = FALSE AND r."RecipientType" = 'Custom' AND r."RecipientId" IS NULL
|
||
LEFT JOIN public."Sas_H_LanguageText" msg ON msg."ResourceName" = 'Platform' AND msg."Key" = p_MessageKey AND msg."CultureName" = 'tr'
|
||
LEFT JOIN public."Sas_H_LanguageText" sub ON sub."ResourceName" = 'Platform' AND sub."Key" = p_SubjectKey AND sub."CultureName" = 'tr'
|
||
WHERE lr."Id" = p_RequestId
|
||
AND (r."Channel" <> 'Mail' OR u."Email" IS NOT NULL);
|
||
END
|
||
$$;
|