Files
GMW/GMW_data/SqlScripts/V1.1/GMW_00259.sql
T
Samuele E. Locatelli bdd7b413e8 Riaggiunto GMW_data
2016-11-22 17:58:00 +01:00

694 lines
19 KiB
Transact-SQL

-- update tab transizione eventi
update AnagTipoDelibere
set CodEvento='DelWipPost'
where CodTipoDelibera='DelibWipPost'
go
-- aggiunta valori nuovi in AnagTipoEvento e TabTranPosizEventi
set xact_abort on
go
begin transaction
go
INSERT INTO dbo.AnagTipoEvento
VALUES (N'UDC_CONS', N'Consumo UDC')
go
commit transaction
go
set xact_abort on
go
begin transaction
go
INSERT INTO dbo.AnagPosizioni
VALUES (-84, N'AM - WIP consumati')
INSERT INTO dbo.AnagPosizioni
VALUES (-56, N'AM - MP consumati')
go
commit transaction
go
set xact_abort on
go
begin transaction
go
INSERT INTO dbo.TabTranPosizEventi
VALUES (N'UDC_CONS', 56, -56)
INSERT INTO dbo.TabTranPosizEventi
VALUES (N'UDC_CONS', 84, -84)
go
commit transaction
go
--- update tabelle varie: anag mag!
set xact_abort on
go
begin transaction
go
alter table AnagMag add
Nascosto bit constraint DF_AnagMag_Nascosto default (0)
go
update AnagMag set Nascosto=0
go
set ANSI_NULLS on
go
/***************************************
* STORED stp_ParticolariOverview
*
* elenco di overview sullo stato dei magazzini (dettaglio a "maglie larghe")
*
* Steamware, S.E.L.
* mod: 2010.06.02
*
****************************************/
alter PROCEDURE stp_magazzinoOverview
(
@CodCS VARCHAR(2)
)
AS
SELECT AnagMag.CodCS, AnagMag.CodMag, AnagMag.DescMag, Blocchi.IdxBlocco, Blocchi.CodBlocco,
TipoCella.Capienza * Blocchi.NumX * Blocchi.NumY * Blocchi.NumZ AS TotCelle,
TipoCella.Capienza * COUNT(DISTINCT Celle.IdxCella) AS CelleAttive,
COUNT(PosizioneUdcCorrente.UDC) AS CelleOccupate,
TipoCella.Capienza * COUNT(DISTINCT Celle.IdxCella) - COUNT(PosizioneUdcCorrente.UDC) AS CelleLibere,
ISNULL(MIN(PosizioneUdcCorrente.DataRif), GETDATE()) AS Oldest, ISNULL(MAX(PosizioneUdcCorrente.DataRif), GETDATE()) AS Newest
FROM TipoCella INNER JOIN
AnagMag INNER JOIN
Blocchi ON AnagMag.CodMag = Blocchi.CodMag AND AnagMag.CodCS = Blocchi.CodCS ON TipoCella.CodMag = AnagMag.CodMag AND
TipoCella.CodCS = AnagMag.CodCS LEFT OUTER JOIN
Celle ON TipoCella.IdxTipoCella = Celle.IdxTipoCella AND Blocchi.IdxBlocco = Celle.IdxBlocco LEFT OUTER JOIN
PosizioneUdcCorrente ON Celle.IdxCella = PosizioneUdcCorrente.IdxCella
WHERE (Celle.Attiva = 1) AND (AnagMag.CodCS = @CodCS) AND (ISNULL(AnagMag.Nascosto, 0) = 0)
GROUP BY AnagMag.CodCS, AnagMag.CodMag, AnagMag.DescMag, Blocchi.IdxBlocco, Blocchi.CodBlocco, Blocchi.NumX, Blocchi.NumY, Blocchi.NumZ,
TipoCella.Capienza
ORDER BY AnagMag.CodMag, Blocchi.CodBlocco
RETURN
go
/***************************************
* STORED stp_ParticolariOverview
*
* elenco di overview sullo stato dei magazzini LOGICI (dettaglio a "maglie larghe")
*
* Steamware, S.E.L.
* mod: 2010.09.15
*
****************************************/
alter PROCEDURE stp_magazzinoLogicoOverview
(
@CodCS VARCHAR(2)
)
AS
SELECT ElencoCartellini.CodCS, AnagPosizioni.IdxPosizione AS CodMagLogico, AnagPosizioni.DescPosizione AS DescMagLogico, Blocchi.IdxBlocco, AnagMag.CodMag,
Blocchi.CodBlocco, COUNT(ElencoCartellini.UDC) AS CelleOccupate, ISNULL(MIN(PosizioneUdcCorrente.DataRif), GETDATE()) AS Oldest,
ISNULL(MAX(PosizioneUdcCorrente.DataRif), GETDATE()) AS Newest
FROM Celle INNER JOIN
Blocchi INNER JOIN
AnagMag ON Blocchi.CodMag = AnagMag.CodMag AND Blocchi.CodCS = AnagMag.CodCS ON Celle.IdxBlocco = Blocchi.IdxBlocco INNER JOIN
ElencoCartellini INNER JOIN
PosizioneUdcCorrente ON ElencoCartellini.UDC = PosizioneUdcCorrente.UDC INNER JOIN
AnagPosizioni ON ElencoCartellini.IdxPosizione = AnagPosizioni.IdxPosizione ON Celle.IdxCella = PosizioneUdcCorrente.IdxCella
WHERE (ElencoCartellini.CodCS = @CodCS) AND (ISNULL(AnagMag.Nascosto, 0) = 0)
GROUP BY ElencoCartellini.CodCS, AnagPosizioni.IdxPosizione, AnagPosizioni.DescPosizione, Blocchi.IdxBlocco, Blocchi.CodBlocco, AnagMag.CodMag
ORDER BY CodMagLogico, Blocchi.CodBlocco
RETURN
go
commit
go
-- update triggers cartellini
set xact_abort on
go
begin transaction
go
set ANSI_NULLS on
go
-- =============================================
-- Author: Samuele E. Locatelli
-- Create date: 2009-09-20
-- Description: trigger x inserimento movimenti
-- nella coda di trasferimento batch
-- verso AS400 x UPDATE UDC
-- =============================================
alter TRIGGER trg_updMovAS
ON ElencoCartellini
AFTER UPDATE
AS
BEGIN
-- setup variabili e verbosità
SET NOCOUNT ON;
DECLARE @partOk AS BIT
DECLARE @IdxPosFrom AS INT
DECLARE @IdxPosTo AS INT
DECLARE @magFrom AS NVARCHAR(50)
DECLARE @magTo AS NVARCHAR(50)
DECLARE @qta AS DECIMAL(10,2)
-- controllo che CI SIA il particolare (altrimenti non eseguo)
SET @partOk = (SELECT CASE WHEN ISNULL(Particolare,'n.d.') = 'n.d.' THEN 0 ELSE 1 END FROM deleted)
IF(@partOk = 1)
SET @qta = (SELECT Qta FROM inserted)
-- se c'è stata modifica di quantità inizio a rettificare quella
IF UPDATE(Qta)
BEGIN
INSERT INTO AS400_BatchMovimenti(DataIns, CodEvento, Particolare, CodMagAS, Quantita)
(
SELECT GETDATE(), 'UDC_MOD', Particolare, CAST(IdxPosizione AS NVARCHAR(50)), @qta-Qta
FROM deleted
WHERE CAST(IdxPosizione AS NVARCHAR(50)) IN (SELECT CodMagAS FROM AS400_MagCont WHERE Attivo = 1)
)
END
-- controllo poi se sia cambiato il magazzino, altrimenti non lo inserisco
IF UPDATE(IdxPosizione)
BEGIN
-- Prendo le posizioni di magazzino precedente e nuova
SET @IdxPosFrom = (SELECT IdxPosizione FROM deleted)
SET @IdxPosTo = (SELECT IdxPosizione FROM inserted)
-- Le trasformo nelle equivalenti stringhe del codMag SE attive
SET @magFrom = (SELECT ISNULL(CodMagAS,'---') FROM AS400_MagCont WHERE Attivo = 1 AND CodMagAs = CAST(@IdxPosFrom AS NVARCHAR(50)))
SET @magTo = (SELECT ISNULL(CodMagAS,'---') FROM AS400_MagCont WHERE Attivo = 1 AND CodMagAs = CAST(@IdxPosTo AS NVARCHAR(50)))
-- inserisco un movimento di deposito verso mag nuovo (SE attivo)
IF (@magFrom <> '---')
BEGIN
INSERT INTO AS400_BatchMovimenti(DataIns, CodEvento, Particolare, CodMagAS, Quantita)
(
SELECT GETDATE(), 'UDC_MOV', Particolare, CAST(IdxPosizione AS NVARCHAR(50)), -@qta
FROM deleted
WHERE CAST(IdxPosizione AS NVARCHAR(50)) IN (SELECT CodMagAS FROM AS400_MagCont WHERE Attivo = 1)
)
END
-- inserisco un movimento di prelievo verso mag vecchio (SE attivo)
IF (@magTo <> '---')
BEGIN
INSERT INTO AS400_BatchMovimenti(DataIns, CodEvento, Particolare, CodMagAS, Quantita)
(
SELECT GETDATE(), 'UDC_MOV', Particolare, CAST(IdxPosizione AS NVARCHAR(50)), @qta
FROM inserted
WHERE CAST(IdxPosizione AS NVARCHAR(50)) IN (SELECT CodMagAS FROM AS400_MagCont WHERE Attivo = 1)
)
END
END
END
go
-- =============================================
-- Author: Samuele E. Locatelli
-- Create date: 2009-09-20
-- Description: trigger x inserimento movimenti
-- nella coda di trasferimento batch
-- verso AS400 x DELETE UDC
-- =============================================
alter TRIGGER trg_DelMovAS
ON ElencoCartellini
AFTER DELETE
AS
BEGIN
-- setup variabili e verbosità
SET NOCOUNT ON;
-- inserisco movimenti AS
INSERT INTO AS400_BatchMovimenti(DataIns, CodEvento, Particolare, CodMagAS, Quantita)
(
SELECT GETDATE(), 'UDC_DEL', Particolare, CAST(IdxPosizione AS NVARCHAR(50)), -Qta
FROM deleted
WHERE CAST(IdxPosizione AS NVARCHAR(50)) IN (SELECT CodMagAS FROM AS400_MagCont WHERE Attivo = 1) AND ((CASE WHEN ISNULL(Particolare,'n.d.') = 'n.d.' THEN 0 ELSE 1 END) = 1)
)
END
go
-- =============================================
-- Author: Samuele E. Locatelli
-- Create date: 2009-09-20
-- Description: trigger x inserimento movimenti
-- nella coda di trasferimento batch
-- verso AS400 x INSERT UDC
-- =============================================
alter TRIGGER trg_InsMovAS
ON ElencoCartellini
AFTER INSERT
AS
BEGIN
-- setup variabili e verbosità
SET NOCOUNT ON;
DECLARE @partOk AS BIT
-- controllo che CI SIA il particoalre (altrimenti non eseguo)
SET @partOk = (SELECT CASE WHEN ISNULL(Particolare,'n.d.') = 'n.d.' THEN 0 ELSE 1 END FROM inserted)
IF(@partOk = 1)
BEGIN
-- metto in storico la posizione attuale dell'UDC (SE esiste) CANCELLATO
INSERT INTO AS400_BatchMovimenti(DataIns, CodEvento, Particolare, CodMagAS, Quantita)
(
SELECT GETDATE(), 'UDC_NEW', Particolare, CAST(IdxPosizione AS NVARCHAR(50)), Qta
FROM inserted
WHERE CAST(IdxPosizione AS NVARCHAR(50)) IN (SELECT CodMagAS FROM AS400_MagCont WHERE Attivo = 1)
)
END
END
go
commit
go
-- fix dei CodSoggetto
set xact_abort on
go
begin transaction
go
alter table StoricoCartellini alter column
CodSoggetto nchar(17)
go
commit
go
-- aggiungo vista
set xact_abort on
go
begin transaction
go
set ANSI_NULLS on
go
create VIEW v_posizioniDelibere
AS
SELECT DISTINCT tpe.IdxPosizione, atd.CodTipoDelibera
FROM dbo.TabTranPosizEventi AS tpe INNER JOIN
dbo.AnagTipoEvento AS ate ON tpe.CodEvento = ate.CodEvento INNER JOIN
dbo.AnagTipoDelibere AS atd ON ate.CodEvento = atd.CodEvento
go
exec sp_addextendedproperty 'MS_DiagramPane1', '[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[40] 4[20] 2[20] 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 = "tpe"
Begin Extent =
Top = 6
Left = 38
Bottom = 118
Right = 208
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "ate"
Begin Extent =
Top = 6
Left = 246
Bottom = 101
Right = 416
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "atd"
Begin Extent =
Top = 6
Left = 454
Bottom = 118
Right = 632
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 9
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
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_posizioniDelibere'
go
exec sp_addextendedproperty 'MS_DiagramPaneCount', 1, 'SCHEMA', 'dbo', 'VIEW', 'v_posizioniDelibere'
go
commit
go
set xact_abort on
go
begin transaction
go
set ANSI_NULLS on
go
alter VIEW v_UdcDetail
AS
SELECT dbo.ElencoCartellini.UDC, ISNULL(dbo.ElencoCartellini.RagSociale, N'') AS RagSociale, ISNULL(dbo.ElencoCartellini.Particolare, N'') AS Particolare,
ISNULL(dbo.ElencoCartellini.DescParticolare, N'') AS DescParticolare, ISNULL(dbo.ElencoCartellini.DisegnoGrezzo, N'') AS DisegnoGrezzo,
ISNULL(dbo.ElencoCartellini.Esponente, N'') AS Esponente, ISNULL(dbo.ElencoCartellini.DescImpianto, N'') AS DescImpianto, ISNULL(dbo.ElencoCartellini.DataFus,
N'') AS DataFus, ISNULL(dbo.ElencoCartellini.TurnoFus, 0) AS TurnoFus, dbo.ElencoCartellini.CodImballo, dbo.ElencoCartellini.Qta,
ISNULL(dbo.AnagStatiProdotto.DescStato, N'') AS DescStato, dbo.ElencoCartellini.ModDate, ISNULL(dbo.Blocchi.CodMag, N'') AS CodMag,
ISNULL(dbo.Blocchi.CodBlocco, N'') AS CodBlocco, ISNULL(dbo.Celle.CodCella, N'') AS CodCella, ISNULL(dbo.Celle.IdxCella, 0) AS IdxCella, ISNULL(dbo.Celle.X, 0)
AS X, ISNULL(dbo.Celle.Y, 0) AS Y, ISNULL(dbo.Celle.Z, 0) AS Z, dbo.ElencoCartellini.IdxPosizione
FROM dbo.AnagStatiProdotto RIGHT OUTER JOIN
dbo.ElencoCartellini ON dbo.AnagStatiProdotto.CodStato = dbo.ElencoCartellini.CodStato AND
dbo.AnagStatiProdotto.CodStato = dbo.ElencoCartellini.CodStato LEFT OUTER JOIN
dbo.Celle INNER JOIN
dbo.PosizioneUdcCorrente ON dbo.Celle.IdxCella = dbo.PosizioneUdcCorrente.IdxCella AND dbo.Celle.IdxCella = dbo.PosizioneUdcCorrente.IdxCella AND
dbo.Celle.IdxCella = dbo.PosizioneUdcCorrente.IdxCella INNER JOIN
dbo.Blocchi ON dbo.Celle.IdxBlocco = dbo.Blocchi.IdxBlocco INNER JOIN
dbo.AnagMag ON dbo.Blocchi.CodMag = dbo.AnagMag.CodMag AND dbo.Blocchi.CodCS = dbo.AnagMag.CodCS AND
dbo.Blocchi.CodMag = dbo.AnagMag.CodMag AND dbo.Blocchi.CodCS = dbo.AnagMag.CodCS AND dbo.Blocchi.CodMag = dbo.AnagMag.CodMag AND
dbo.Blocchi.CodCS = dbo.AnagMag.CodCS ON dbo.ElencoCartellini.UDC = dbo.PosizioneUdcCorrente.UDC
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[40] 4[20] 2[20] 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 = "AnagStatiProdotto"
Begin Extent =
Top = 6
Left = 38
Bottom = 101
Right = 208
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "ElencoCartellini"
Begin Extent =
Top = 6
Left = 246
Bottom = 309
Right = 416
End
DisplayFlags = 280
TopColumn = 11
End
Begin Table = "Celle"
Begin Extent =
Top = 27
Left = 818
Bottom = 156
Right = 988
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "PosizioneUdcCorrente"
Begin Extent =
Top = 71
Left = 548
Bottom = 200
Right = 718
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "Blocchi"
Begin Extent =
Top = 70
Left = 1080
Bottom = 199
Right = 1250
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "AnagMag"
Begin Extent =
Top = 188
Left = 799
Bottom = 334
Right = 969
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 22
Width = 284
Width = 15', 'SCHEMA', 'dbo', 'VIEW', 'v_UdcDetail'
go
exec sp_updateextendedproperty 'MS_DiagramPane2', '00
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
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_UdcDetail'
go
commit
go
-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(259, GETDATE())
GO