-- =============================================
-- Author:        (C) Vitacard
-- Create date: 2015-12-17
-- Description:   Удаление загруженных гос. контрактов
-- =============================================
DROP PROCEDURE IF EXISTS stor.sp_DeleteImportContract;

CREATE PROCEDURE stor.sp_DeleteImportContract
(
	"UserID" uuid
)
    language plpgsql
as
$$
Begin 

	delete from STOR.T_IMPORT_CONTRACT ic
		using STOR.T_IMPORT_ELEMENTS ie
	where ie.ImportElementsID = ic.ImportElementsID and ie.Users = "UserID";

	delete from STOR.T_IMPORT_ELEMENTS where Users = "UserID" and type_ = (select e.EntityID from VCLib.T_ENTITIES e where e.EntName = 'IMPORT_CONTRACT' limit 1);

End;
$$;