-- Talepten Aktar: seçilen malzeme talebi kalemini (@Key = belge|kalem) taslak iç transfere satır olarak ekler; kalanı (talep − teslim) aktarılır. -- Belgenin hedef konumu boşsa talebin konumu yazılır. CREATE OR ALTER PROCEDURE [dbo].[Inv_P_TransferImportItem] @Key nvarchar(80) AS BEGIN SET NOCOUNT ON; DECLARE @Doc uniqueidentifier, @Tenant uniqueidentifier, @Item uniqueidentifier, @ProductId uniqueidentifier, @Description nvarchar(256), @Quantity decimal(18, 4), @UomId nvarchar(64), @LocationId uniqueidentifier; SELECT @Doc = BaseId, @Tenant = TenantId, @Item = MaterialRequestItemId, @ProductId = ProductId, @Description = RequestReason, @Quantity = Quantity, @UomId = UomId, @LocationId = LocationId FROM Prc_V_MaterialRequestTransferItem WHERE Id = @Key; IF @Doc IS NULL THROW 50319, N'Talep kalemi artık aktarılamaz: belge taslak değil, kalem başka bir transfere aktarılmış ya da talep değişmiş.', 1; INSERT INTO Inv_T_TransferLine (Id, TenantId, TransferId, ProductId, Description, DemandQuantity, Quantity, UomId, MaterialRequestItemId, CreationTime, IsDeleted) VALUES (NEWID(), @Tenant, @Doc, @ProductId, @Description, @Quantity, 0, @UomId, @Item, GETUTCDATE(), 0); UPDATE Inv_T_Transfer SET DestinationLocationId = COALESCE(DestinationLocationId, @LocationId) WHERE Id = @Doc; EXEC Inv_P_TransferRecalc @Doc; END