-- =============================================
-- Author:      Vitacore (с) Anatoliy
-- Create date: 2023 11 07
-- Description: Обнуление связи на остатки в закрытом документе инвентаризации
-- =============================================
DROP PROCEDURE IF EXISTS stor.sp_cleaninventorydocumentprocess;

CREATE PROCEDURE stor.sp_cleaninventorydocumentprocess
(
	"Id" uuid
)
    language plpgsql
as
$$
Begin 

	update stor.t_scanned_inventory_elements sie
	set remains = null
	from stor.t_inventory_elements ie
	where ie.inventoryelementsid = sie.inventoryelements and ie.inventorydocument = "Id";

	update stor.t_inventory_elements_remains ier
	set remains = null
	from stor.t_inventory_elements ie
	where ie.inventoryelementsid = ier.inventoryelements and ie.inventorydocument = "Id";
End;
$$;