sozsoft-platform/configs/seeds/sql/object/Prc_P_MaterialRequestAfterSave.sql
2026-10-12 13:27:54 +03:00

39 lines
1.9 KiB
Transact-SQL
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 ALTER PROCEDURE [dbo].[Prc_P_MaterialRequestAfterSave]
@Id uniqueidentifier
AS
BEGIN
SET NOCOUNT ON;
IF @Id IS NULL RETURN;
-- Departman onaycıları: Onaycılar'da talebin departmanı için Satınalma onay yeri.
-- Satınalma onaycıları: Satınalma Onayı Bekleyenler ekranında karar verebilen (güncelleme yetkisi
-- doğrudan ya da rolüyle verilmiş) aktif kullanıcılar.
UPDATE r SET
DeptApproverUserNames = (
SELECT STRING_AGG(u.UserName, '|')
FROM Adm_T_Approver a
INNER JOIN AbpUsers u ON u.UserName = a.ApprovalUserName AND u.IsDeleted = 0 AND u.IsActive = 1
AND ((u.TenantId IS NULL AND a.TenantId IS NULL) OR u.TenantId = a.TenantId)
WHERE a.IsDeleted = 0 AND a.IsActive = 1 AND a.ApprovalArea = 'Purchase'
AND a.DepartmentId = r.DepartmentId
AND ((a.TenantId IS NULL AND r.TenantId IS NULL) OR a.TenantId = r.TenantId)),
PurchaseApproverUserNames = (
SELECT STRING_AGG(u.UserName, '|')
FROM AbpUsers u
WHERE u.IsDeleted = 0 AND u.IsActive = 1
AND ((u.TenantId IS NULL AND r.TenantId IS NULL) OR u.TenantId = r.TenantId)
AND EXISTS (
SELECT 1
FROM AbpPermissionGrants g
WHERE g.Name = N'App.Prc.MaterialRequestPurchaseApproval.Update'
AND ((g.TenantId IS NULL AND r.TenantId IS NULL) OR g.TenantId = r.TenantId)
AND ((g.ProviderName = N'U' AND g.ProviderKey = CAST(u.Id AS nvarchar(64)))
OR (g.ProviderName = N'R' AND g.ProviderKey IN (
SELECT ro.Name
FROM AbpUserRoles ur
INNER JOIN AbpRoles ro ON ro.Id = ur.RoleId
WHERE ur.UserId = u.Id)))))
FROM Prc_T_MaterialRequest r
WHERE r.Id = @Id;
END
GO