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

31 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.

-- Transfer belgesi kaydı sonrası: tür, şube, depo ve boş konumlar operasyon türünden gelir (formda olmayan alımın
-- kaynağı ve teslimatın hedefi her zaman, iade belgesi hariç); teslimat politikası yalnız teslimatta tutulur. Tamamlanmış belgenin başlığı
-- yeniden türetilmez: stoğu belirleyen alanlar kilitlidir (Stk_TR_TransferLock) ve sonradan değişen operasyon türü İade Et'i 50328'e düşürürdü.
-- Numara, özet ve durum butonunun işlemi (PendingAction) buradan çalışır.
CREATE OR ALTER PROCEDURE [dbo].[Stk_P_TransferAfterSave]
@Id uniqueidentifier,
@UserId uniqueidentifier = NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Act nvarchar(16) = (SELECT PendingAction FROM Stk_T_Transfer WHERE Id = @Id);
UPDATE t SET
OperationKind = ot.OperationKind,
BranchId = ot.BranchId,
WarehouseId = ot.WarehouseId,
SourceLocationId = CASE WHEN t.ReturnOfId IS NULL AND (ot.OperationKind = 'Receipt' OR t.SourceLocationId IS NULL)
THEN COALESCE(ot.SourceLocationId, t.SourceLocationId) ELSE t.SourceLocationId END,
DestinationLocationId = CASE WHEN t.ReturnOfId IS NULL AND (ot.OperationKind = 'Delivery' OR t.DestinationLocationId IS NULL)
THEN COALESCE(ot.DestinationLocationId, t.DestinationLocationId) ELSE t.DestinationLocationId END,
DeliveryPolicy = CASE WHEN ot.OperationKind = 'Delivery' THEN COALESCE(t.DeliveryPolicy, 'Direct') END
FROM Stk_T_Transfer t
INNER JOIN Stk_T_OperationType ot ON ot.Id = t.OperationTypeId
WHERE t.Id = @Id AND t.Status <> 'Done';
EXEC Stk_P_TransferNumber @Id;
EXEC Stk_P_TransferRecalc @Id;
-- Durum butonları işlemi PendingAction alanına yazıp ekranın güncelleme ucuyla kaydeder.
IF @Act IS NOT NULL
EXEC Stk_P_TransferSetStatus @Id, @Act, @UserId;
END