
-- update transizioni...
alter table TabTranPosizEventi add
  constraint FK_TabTranPosizEventi_Blocchi foreign key(IdxBloccoTo) references Blocchi(IdxBlocco) on update cascade
go


-- update celle...
set xact_abort on
go

begin transaction
go

alter table Celle drop
  constraint FK_Celle_TipoCella 
go


alter table Celle add
  constraint FK_Celle_Blocchi foreign key(IdxBlocco) references Blocchi(IdxBlocco) on update cascade
go

alter table Celle add
  constraint FK_Celle_TipoCella foreign key(IdxTipoCella) references TipoCella(IdxTipoCella)
go

commit
go

-- update insert blocchi!
set xact_abort on
go

begin transaction
go

set ANSI_NULLS on
go

/***************************************
* STORED stp_Blocchi_Insert
*
* crea nuovo record blocchi magazzino
*
* Steamware, S.E.L.
* mod: 2012.05.21
*
****************************************/
alter PROCEDURE stp_Blocchi_Insert
(
	@CodMag NVARCHAR(50),
	@CodCS NVARCHAR(2),
	@CodBlocco NVARCHAR(3),
	@DescBlocco NVARCHAR(50),
	@NumX INT,
	@NumY INT,
	@NumZ INT
)
AS

BEGIN TRAN
	-- inizio calcolando il primo blocco libero x chiave (non è + autoincrement)...
	DECLARE @idxBlocco	INT
	SET		@idxBlocco	= ( SELECT ISNULL(MAX(idxBlocco),0)+1 AS nextIdxBlocco FROM Blocchi )
	
	INSERT INTO Blocchi (idxBlocco, CodMag, CodCS, CodBlocco, DescBlocco, NumX, NumY, NumZ) 
	VALUES (@idxBlocco, @CodMag, @CodCS, @CodBlocco, @DescBlocco, @NumX, @NumY, @NumZ)
	
	
COMMIT TRAN


RETURN
go

commit
go

-- =============  AGGIUNTE =============

ALTER TABLE [dbo].[Soggetti2Utente] ADD  CONSTRAINT [CK_CodSoggetto_Unique] UNIQUE NONCLUSTERED 
(
	[CodSoggetto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO



/****** Object:  StoredProcedure [dbo].[stp_prtCartMatPrimaByUDC]    Script Date: 05/22/2012 16:52:47 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



-- =================================================================================================
-- =================================================================================================




/***************************************
* STORED stp_prtCartMatPrimaByUDC
*
* ottiene il record del Cartellino Materia Prima dato l'UDC richiesto x la stampa
*
****************************************/
ALTER PROCEDURE [dbo].[stp_prtCartMatPrimaByUDC]
(
      @UDC VARCHAR(50)
)
AS
SELECT
        RQ.nRapQual,
        RQ.DataRapQual,
        RQ.ProgUDC,
        RQ.CodFor,
        RQ.DestTerz,
        ec.Particolare AS CodLega,
        RQ.DataPrelFus,
        RQ.TurnoPrelFus,
        ec.Qta,
        RQ.DestLega,
        RQ.LegaScaric,
        RQ.BenesQual,
        ec.UDC,
        Fo.DescFornitore,
        Fo.DescFornitore2,
        Le.CodLega AS CodLega2,
        Le.DescLega,
        Le.DescLega2,
        ISNULL(ec.Note,'') AS Note
FROM ElencoCartellini ec
LEFT JOIN RilPro.RapQual AS RQ
  ON ec.UDC = RQ.UDC
LEFT JOIN RilPro.AnagFornitori AS Fo
  ON RQ.CodFor = Fo.CodFornitore
LEFT JOIN RilPro.AnagLeghe Le
  ON RQ.CodLega = 'L' + Le.CodLega
WHERE ec.UDC = RTRIM(@UDC)                  -- 'UB31000000001'

RETURN


GO

-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(437, GETDATE())
GO
