sozsoft-platform/configs/seeds/sql/object/Stk_TR_TransferLock.sql
2026-10-19 17:35:08 +03:00

22 lines
1.6 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.

-- Tamamlanmış hareket belgesinin stoğu belirleyen başlık alanları değiştirilemez (Alımlar, Teslimatlar, İç Transferler ve ortak sekmeleri):
-- stok eski konumda kalır, İade Et yeni konumdan düşmeye çalışırdı. Kural ekranın UpdateBeforeCommand'ında değil burada, çünkü durum
-- butonları yalnız PendingAction ile aynı güncelleme yolundan yazar. Açıklama, nakliye ve not alanları serbesttir;
-- satırların kuralı Transfer Satırları'nın Update/DeleteBeforeCommand'ındadır (50313).
CREATE OR ALTER TRIGGER [dbo].[Stk_TR_TransferLock] ON [dbo].[Stk_T_Transfer]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT 1
FROM inserted i
INNER JOIN deleted d ON d.Id = i.Id
WHERE d.Status = 'Done'
AND (i.Status <> d.Status OR i.BranchId <> d.BranchId OR i.WarehouseId <> d.WarehouseId
OR i.OperationTypeId <> d.OperationTypeId OR i.OperationKind <> d.OperationKind
OR ISNULL(i.SourceLocationId, '00000000-0000-0000-0000-000000000000') <> ISNULL(d.SourceLocationId, '00000000-0000-0000-0000-000000000000')
OR ISNULL(i.DestinationLocationId, '00000000-0000-0000-0000-000000000000') <> ISNULL(d.DestinationLocationId, '00000000-0000-0000-0000-000000000000')
OR ISNULL(i.PartnerId, '00000000-0000-0000-0000-000000000000') <> ISNULL(d.PartnerId, '00000000-0000-0000-0000-000000000000')
OR i.IsDeleted <> d.IsDeleted))
THROW 50328, N'Tamamlanmış belgenin konumu, türü ve durumu değiştirilemez; düzeltme için İade Et kullanın.', 1;
END
GO