﻿
-- =============================================
-- Author:		Steamware
-- Mod. date:   2014.05.29
-- Description:	creazione dati base per Cost List per data odierna
-- =============================================
CREATE PROCEDURE [dbo].[stp_SC2C_insertForDate]
	@RawMatCost DECIMAL(18,6)   = 2,
	@BatchQty   INT             = 1000
AS
BEGIN

DECLARE @Date AS SMALLDATETIME = CONVERT( SMALLDATETIME,CONVERT(CHAR(8), GETDATE(), 112) ) ;

-- ===========================================================
-- se non esiste, CREO DATI LISTINO COSTI per il giorno
-- ===========================================================
IF NOT EXISTS( SELECT * FROM dbo.CostList WHERE QuoteType = 'C' AND DateList = @Date )
	BEGIN
		INSERT INTO dbo.CostList WITH (TABLOCK) ( DateList,CodItem,RawMat,RawMatCost,RawMatExtraCost,batchQty,CodInco )
		EXEC dbo.stp_QFC_creaListino @RawmatCost , @BatchQty

        -- aggiorno statistiche tabella
        UPDATE STATISTICS dbo.CostList WITH FULLSCAN;
	END

RETURN

END