set xact_abort on
go

begin transaction
go

UPDATE dbo.TipoListaPrelievo SET 
  enabled=0
  WHERE CodTipoLista=N'00-Smart'
go

commit transaction
go


set xact_abort on;
go

begin transaction;
go

set ANSI_NULLS on;
go

/***************************************
* STORED stp_selDestListePrelByConditio
*
* Ottiene i destinatari delle liste di prelievo data la condizione indicata
*
* Steamware, S.E.L.
* mod: 2010.11.02
*
****************************************/
alter PROCEDURE stp_selDestListePrelByConditio
(
	@conditio NVARCHAR(20)
)
AS

IF (@conditio='01-PreFus')
BEGIN
	SELECT        CAST('*' AS NVARCHAR(6)) AS value, CAST('*' AS NVARCHAR(50)) AS label, '01-PreFus' AS conditio
END

ELSE IF (@conditio='01-PreAnim')
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '01-PreAnim' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE IF (@conditio='02-PreCli') 
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '02-PreCli' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE IF (@conditio='04-OdetSP') 
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '04-OdetSP' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE
BEGIN
	SELECT        CAST(CodTerzista AS NVARCHAR(6)) AS value, CAST(CodTerzista AS NVARCHAR(6))+ '- '+CAST(DescTerzista AS NVARCHAR(50)) AS label, '03-TerWip' AS conditio
	FROM            RilPro.AnagDepositi
	ORDER BY label
END

RETURN
go

commit;
go


set xact_abort on;
go

begin transaction;
go

set ANSI_NULLS on;
go

/***************************************
* STORED stp_ParticolariOverviewPerListaPrelievo
*
* elenco di overview sull'impiego dei particolari (dettaglio a "maglie larghe") x una possibile lista di prelievo
*
* Steamware, S.E.L.
* mod: 2010.05.31
*
****************************************/
alter PROCEDURE stp_ParticolariOverviewPerListaPrelievo
(
	@Particolare VARCHAR(50),
	@CodCS VARCHAR(2),
	@Esponente NVARCHAR(6),
	@Figura NVARCHAR(4),
	@CodImballo NVARCHAR(15),
	@CodTipoLista NVARCHAR (10)
)
AS
	SELECT      RilPro.AnagParticolari.Particolare, RilPro.AnagParticolari.DescParticolare, ISNULL(COUNT(dbo.ElencoCartellini.UDC), 0) AS NumUDC, 
				ISNULL(SUM(dbo.ElencoCartellini.Qta), 0) AS TotQta, ISNULL(COUNT(dbo.PosizioneUdcCorrente.IdxCella), 0) AS NumInMag
	FROM        RilPro.AnagParticolari LEFT OUTER JOIN
				dbo.ElencoCartellini ON RilPro.AnagParticolari.Particolare = dbo.ElencoCartellini.Particolare LEFT OUTER JOIN
				dbo.PosizioneUdcCorrente ON dbo.ElencoCartellini.UDC = dbo.PosizioneUdcCorrente.UDC
	WHERE		RilPro.AnagParticolari.CodCS = @CodCS AND 
				RilPro.AnagParticolari.Particolare = @Particolare AND 
				(IdxPosizione IN (SELECT	tt.IdxPosizione
	                 	   FROM     TipoListaPrelievo tlp INNER JOIN TabTranPosizEventi tt ON tlp.CodEvento = tt.CodEvento
	                 	   WHERE	(tlp.CodTipoLista = @CodTipoLista))) AND 
				(dbo.ElencoCartellini.Figura		= CASE WHEN @Figura		= '*' THEN dbo.ElencoCartellini.Figura		ELSE @Figura	END) AND
				(dbo.ElencoCartellini.Esponente		= CASE WHEN @Esponente  = '*' THEN dbo.ElencoCartellini.Esponente	ELSE @Esponente END) AND
				(dbo.ElencoCartellini.CodImballo	= CASE WHEN @CodImballo	= '*' THEN dbo.ElencoCartellini.CodImballo	ELSE @CodImballo END)
				
				AND ElencoCartellini.UDC NOT IN (
					SELECT DISTINCT UDC 
					FROM RigheListePrelievo INNER JOIN ElencoListePrelievo
					ON	RigheListePrelievo.CodLista = ElencoListePrelievo.CodLista
					WHERE (CodStatoLista > 1 AND Prelevato = 1)
					)
				
	GROUP BY	RilPro.AnagParticolari.Particolare, RilPro.AnagParticolari.DescParticolare

RETURN
go

commit;
go



set xact_abort on;
go

begin transaction;
go

set ANSI_NULLS on;
go

alter VIEW V_ParticolariOverview
AS
SELECT        RilPro.AnagParticolari.Particolare, RilPro.AnagParticolari.DescParticolare, ISNULL(COUNT(dbo.ElencoCartellini.UDC), 0) AS NumUDC, 
                         ISNULL(SUM(dbo.ElencoCartellini.Qta), 0) AS TotQta, ISNULL(COUNT(dbo.PosizioneUdcCorrente.IdxCella), 0) AS NumInMag
FROM            RilPro.AnagParticolari LEFT OUTER JOIN
                         dbo.ElencoCartellini ON RilPro.AnagParticolari.Particolare = dbo.ElencoCartellini.Particolare LEFT OUTER JOIN
                         dbo.PosizioneUdcCorrente ON dbo.ElencoCartellini.UDC = dbo.PosizioneUdcCorrente.UDC
GROUP BY RilPro.AnagParticolari.Particolare, RilPro.AnagParticolari.DescParticolare
go

exec sp_updateextendedproperty 'MS_DiagramPane1', '[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[13] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "AnagParticolari (RilPro)"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 191
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "ElencoCartellini"
            Begin Extent = 
               Top = 6
               Left = 277
               Bottom = 270
               Right = 447
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "PosizioneUdcCorrente"
            Begin Extent = 
               Top = 7
               Left = 533
               Bottom = 136
               Right = 703
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 2580
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
', 'SCHEMA', 'dbo', 'VIEW', 'V_ParticolariOverview';
go

commit;
go


set xact_abort on
go

begin transaction
go

INSERT INTO dbo.TabTranPosizEventi
  VALUES (N'MagPreAnim', -2, 2, 1)
go

commit transaction
go






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