﻿-- =============================================
-- Author:		Steamware - S.E.L.
-- Create date: 2014.05.20
-- Description:	update di un record in QL (Full) TIPO SIMULAZIONE e poi aggiorna a cascata
-- =============================================
CREATE PROCEDURE [dbo].[stp_QLS_UpdPackPar]
(
    @Original_QuoteType CHAR(1) = 'S',
    @Original_CodQuote	BIGINT = 0,
    @Original_QuoteRev	INT = 0,
    @CodPackag	        NVARCHAR(50),
    @DSR_sim            DECIMAL(9, 8),
	@NetProd04_sim      DECIMAL(9, 3)
)
AS

SET XACT_ABORT ON;
BEGIN TRAN

    -- @CodPackag
    EXEC stp_QSP_upsert @Original_QuoteType, @Original_CodQuote, @Original_QuoteRev, 'CodPackag', @CodPackag
    
    -- @DSR_sim
    EXEC stp_QSP_upsert @Original_QuoteType, @Original_CodQuote, @Original_QuoteRev, 'DSR_sim', @DSR_sim
    
	-- @NetProd04_sim
	EXEC stp_QSP_upsert @Original_QuoteType, @Original_CodQuote, @Original_QuoteRev, 'NetProd04_sim', @NetProd04_sim

    -- update dei valori calcolati!
    EXEC stp_QL_fullDataUpdate @Original_QuoteType
        ,@Original_CodQuote
        ,@Original_QuoteRev
        ,'Y'
        
	-- la chiamo 2 volte perché è simulazione e i valori _sim sono salvati alla fine ed usati all'inizio...
    EXEC stp_QL_fullDataUpdate @Original_QuoteType
        ,@Original_CodQuote
        ,@Original_QuoteRev
        ,'Y'
        

COMMIT TRAN


-- seleziono intera riga!
    
SELECT	* 
FROM	v_QuoteFull_Q
WHERE	QuoteType = @Original_QuoteType
    AND CodQuote = @Original_CodQuote
    AND QuoteRev = @Original_QuoteRev


RETURN