USE [CDN_VIP_08]
GO
/****** Object:  StoredProcedure [dbo].[s4rNaleznosc]    Script Date: 2013-10-18 14:06:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[s4rRozliczenie] @FakturaExid INT
AS
BEGIN
	SET NOCOUNT ON;

	declare @Name nvarchar(40);
	declare @PayerGuid uniqueidentifier;
	declare @SellerGuid uniqueidentifier;
	declare @CreateDate datetime;
	declare @DueDate datetime;
	declare @Amount money;
	declare @AmountToPay money;
	declare @Note nvarchar(500);

	declare @SumaKorekt money;
	declare @KlientEXID int;
	declare @DueGuid uniqueidentifier;

	-- detail
	SELECT 
		@Name = TrN_NumerPelny
	FROM CDN.TraNag WHERE Trn_TrnId = @FakturaExid

	-- is exist
	select @DueGuid=DUE_GUID from sales4rent_vip_prod.dbo.DUE   		
		where DUE_NAME = @Name;

	if not @DueGuid is null
    begin
		-- update
		update sales4rent_vip_prod.dbo.DUE
		set
		  [DUE_AMOUNT_TO_PAY] = [DUE_AMOUNT]
		  where DUE_GUID = @DueGuid;
	end;

END
