sozsoft-platform/configs/seeds/sql/object/Inv_P_TransferImportItem.sql
2026-10-13 00:43:05 +03:00

23 lines
1.4 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.

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