USE [Hubie]
GO

/****** Object:  StoredProcedure [dbo].[sp_VratiSpremnostiZaFakturisanjeZaOtpremnicu]    Script Date: 02.02.2026 14:24:18 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[sp_VratiSpremnostiZaFakturisanjeZaOtpremnicu] 
	@Sifra_Preduzeca int = 1,
	@Jezik_Id int = 4,
	@fk_Otpremnica bigint
AS
BEGIN
	declare @Dokumenta dbo.tabela_0,
			@Pk_Guid_ZaPresipanje uniqueidentifier,
			@SpremnoZaFakturisanje bit = 0 

	----------------------------------SPREMNOST ZA FAKTURISANJE----------------------------------------------------------
	insert into @Dokumenta(t0_bigint_0)
	Select @fk_Otpremnica
	Set @Pk_Guid_ZaPresipanje = newid()

	exec sp_VratiSpremnostDokumenataZaFakturisanje @Sifra_Preduzeca = @Sifra_Preduzeca,
																		  @Jezik_Id = @Jezik_Id,
																		  @Kor_Id = 1,
																		  @Dokumenta = @Dokumenta,
																		  @DodatniPodatak = null,
																		  @DodatniPodatak1 = null,
																		  @DodatniPodatak2 = null,
																		  @Pk_Guid_ZaPresipanje = @Pk_Guid_ZaPresipanje,
																		  @DaliSelect = 0	

	select @SpremnoZaFakturisanje = case when P.PodatakBigint2 > 0 then 1 else
								case when P.PodatakString1 = '4' then 2 else 0 end
								end 
	from @Dokumenta DD
	inner join z_Presipanje P (nolock) on (DD.t0_bigint_0 = P.PodatakBigint1)
	where P.Pk_Guid = @Pk_Guid_ZaPresipanje
			  
	Delete z_Presipanje where Pk_Guid = @Pk_Guid_ZaPresipanje
	----------------------------------SPREMNOST ZA FAKTURISANJE----------------------------------------------------------

	select @SpremnoZaFakturisanje
END
GO

