IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[stor].[sp_CleanInventoryDocumentProcess]') AND type in (N'P', N'PC'))
	DROP PROCEDURE stor.[sp_CleanInventoryDocumentProcess]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_CleanInventoryDocumentProcess]') AND type in (N'P', N'PC'))
	DROP PROCEDURE dbo.[sp_CleanInventoryDocumentProcess]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Vitacore (с) Anatoliy
-- Create date: 2023 11 07
-- Description: Обнуление связи на остатки в закрытом документе инвентаризации
-- =============================================
CREATE PROCEDURE stor.[sp_CleanInventoryDocumentProcess]
    @Id uniqueidentifier
AS
BEGIN
	update sie
	set sie.Remains = null
	from STOR.T_SCANNED_INVENTORY_ELEMENTS sie
	join STOR.T_INVENTORY_ELEMENTS ie on ie.InventoryElementsID = sie.InventoryElements
	where ie.InventoryDocument = @Id

	update ier
	set ier.Remains = null
	from STOR.T_INVENTORY_ELEMENTS_REMAINS ier
	join STOR.T_INVENTORY_ELEMENTS ie on ie.InventoryElementsID = ier.InventoryElements
	where ie.InventoryDocument = @Id
END				
				