Files
2021-03-26 17:17:28 +01:00

312 lines
7.6 KiB
Transact-SQL

alter table AnagClienti add
constraint DF_AnagClienti_codExt default ('n.d.') for codExt,
constraint DF_AnagClienti_Attivo default ((1)) for Attivo,
constraint DF_AnagClienti_OldIdx default ((-1)) for OldIdx;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
alter VIEW v_logCommUt
AS
SELECT dataLav AS Data, idxDipendente, CognomeNome, h_lav, 0.00 AS h_com, isOk AS okTimbr, isOk AS okLavCom, '---' AS progetto, minOrd, minStra, minPerm,
minFer, minMal, minFest
FROM dbo.TimbratureExpl
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 = "TimbratureExpl"
Begin Extent =
Top = 6
Left = 38
Bottom = 357
Right = 213
End
DisplayFlags = 280
TopColumn = 9
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 13
Width = 284
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_logCommUt';
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/**********************************************************
* STORED stp_AC_insert
*
* crea un cliente in anagrafica
*
* mod: S.E.L. 2013.02.26
*
**********************************************************/
create PROCEDURE stp_AC_insert
(
@RagSociale NVARCHAR(50),
@indirizzo NVARCHAR(50),
@CAP NVARCHAR(5),
@citta NVARCHAR(50),
@prov NVARCHAR(50),
@tel NVARCHAR(50),
@email NVARCHAR(50),
@pIva NVARCHAR(20),
@CF NVARCHAR(20),
@nota NVARCHAR(500)
)
AS
SET NOCOUNT OFF;
INSERT INTO AnagClienti(RagSociale, indirizzo, CAP, citta, prov, tel, email, pIva, CF, nota)
VALUES (@RagSociale, @indirizzo, @CAP, @citta, @prov, @tel, @email, @pIva, @CF, @nota)
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/**********************************************************
* STORED stp_freqProjByDipPeriodo
*
* elenco dei progetti/fasi per dipendente/periodo
*
* mod: S.E.L. 2013.02.20
*
**********************************************************/
create PROCEDURE stp_freqProjByDipPeriodo
(
@idxDipendente INT = 0, -- 0 = tutti
@inizio DATETIME,
@fine DATETIME,
@maxRes INT = 999 -- num max risultati desiderati
)
AS
-- calcolo il totale dei risultati per prima cosa...
DECLARE @totNum AS INT = 1
DECLARE @tabFreq AS TABLE
(
nomeProj NVARCHAR(250)
,nomeFase NVARCHAR(250)
,qty DECIMAL(9,3)
,idxFase INT
)
INSERT @tabFreq
SELECT TOP (@maxRes) nomeProj, nomeFase ,SUM(ra.oreTot) as qty, ra.idxFase
FROM RegAttivita ra INNER JOIN AnagFasi af ON ra.idxFase=af.idxFase
INNER JOIN AnagProgetti ap ON af.idxProgetto=ap.idxProgetto
WHERE ra.inizio BETWEEN @inizio AND @fine
AND (ra.idxDipendente = @idxDipendente OR @idxDipendente = 0 )
GROUP BY nomeProj, nomeFase, ra.idxFase
ORDER BY qty DESC
-- calcolo il totale
SELECT @totNum = ISNULL(SUM(qty),1) FROM @tabFreq
-- restituisco tab con calcolo freq reale
SELECT idxFase, nomeProj, nomeFase, qty/@totNum as freq, qty, @totNum AS tot
FROM @tabFreq
RETURN
go
/**********************************************************
* STORED stp_RA_clonaLastRA_byFaseUtente
*
* clona un attività utente: ultima di un dato tipo di fase
*
* mod: S.E.L. 2013.02.20
*
**********************************************************/
create PROCEDURE stp_RA_clonaLastRA_byFaseUtente
(
@idxDipendente INT
,@dataRif DATETIME -- data x cui creare un record attività
,@idxFase INT
)
AS
-- variabili
DECLARE @idxRA INT
DECLARE @round AS INT
SET @round = ( SELECT valInt FROM AnagKeyValue WHERE nomeVar = 'minutiRoundDay' )
-- arrotondo data richiesta...
SELECT @dataRif = DATEADD(n, (ROUND(dbo.TimeSpanUnits('m', dbo.TimeOnly(DATEADD(n,-1,@dataRif))) / @round, 2) + 1) * @round , CAST(CAST(@dataRif AS DATE) AS DATETIME))
-- controlla che x la data richiesta non ci siano già altre attività, in quel caso "accoda"...
DECLARE @trovate INT = 0
SELECT @trovate = COUNT(idxRA) FROM RegAttivita WHERE idxDipendente = @idxDipendente AND CAST(@dataRif AS DATE) = CAST(inizio AS DATE)
IF @trovate > 0
BEGIN
-- imposto @dataRif per iniziare alla fine dell'ultimo record
SELECT TOP 1 @dataRif=fine FROM RegAttivita WHERE idxDipendente = @idxDipendente AND CAST(@dataRif AS DATE) = CAST(inizio AS DATE) ORDER BY fine DESC
END
-- cerco ultima reg attività utente x fase indicata...
SELECT @idxRA=ISNULL((SELECT TOP 1 idxRA FROM RegAttivita WHERE idxDipendente = @idxDipendente AND idxFase = @idxFase ORDER BY inizio DESC),0)
-- inserisco su data richeista duplicazione dell'ultima attività utente...
INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione, importo)
SELECT idxDipendente, idxFase, @dataRif, DATEADD(minute, DATEDIFF(MINUTE, inizio, fine), @dataRif), descrizione, importo
FROM RegAttivita
WHERE (idxRA = @idxRA)
go
commit;
go
-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(304, GETDATE())
GO
SELECT * FROM LogUpdateDb ORDER BY Versione DESC