-- =============================================
-- Author:      Vitacore   Anatoliy
-- Create date: 2022-03-10
-- =============================================
DROP PROCEDURE IF EXISTS stor.sp_DeleteSgtinsProcess;

CREATE PROCEDURE stor.sp_DeleteSgtinsProcess
(
	"InvoiceId" uuid
)
    language plpgsql
as
$$
Begin
	if exists(select * from STOR.T_STORAGE_INVOICE where InvoiceID = "InvoiceId" and State = 0)
	then
		delete from STOR.T_SGTINS where StorageInvoice = "InvoiceId";
	end if;
End;
$$;