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

346 lines
8.6 KiB
Transact-SQL

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, minMpp
FROM dbo.TimbratureExpl
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
-- =============================================
-- Author: G.Rottoli
-- Create date: 2013.03.12
-- Description: Stored per export x stampa di controllo tracciato paghe x ETS
-- =============================================
alter PROCEDURE export.stp_prt_orePagheMensileETS
(
@Anno NVARCHAR(4),
@Mese NVARCHAR(2),
@idxDipendente INT = 0, -- 0 = tutti
@flgOnlyErr BIT = 0,
@flgSingleUser BIT = 0 -- Stampa x singolo utente ( ritorna dati solo utente loggato SYSTEM_USER )
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @dateFrom AS SMALLDATETIME;
DECLARE @dateTo AS SMALLDATETIME;
SET @dateFrom = @Anno + @Mese + '01';
SET @dateTo = DATEADD( MM, 1, @dateFrom) -1;
EXEC export.stp_ricalcolaOrePerPaghe @dateFrom ;
SELECT
e.idxDipendente
, e.dataLav
, e.matricola
, e.codExt
, e.RifDitta
, e.oreStraordAss
, e.minLavStra
, e.minLavTot
, e.minStraProgrMese
, e.minPrevExp
, e.minLavOrdExp
, e.minStraExp
, e.minPermExp
, e.minFerieExp
, e.minMalExp
, e.minFestExp
, e.hhLavTotExp
, e.hhStraProgrMeseExp
, e.hhPrevExp
, e.hhLavOrdExp
, e.hhStraExp
, e.hhPermExp
, e.hhFerieExp
, e.hhMalExp
, e.hhFestExp
, e.CognomeNome
, e.entrata_1
, e.uscita_1
, e.entrata_2
, e.uscita_2
, e.entrata_3
, e.uscita_3
, e.entrata_4
, e.uscita_4
, e.isOkTim
, e.isOkApp
, e.isOkLav
, e.isOk
, e.block
, e.chkFunCod
, e.chkFunRes
, e.arrotMin
, e.gruppo
, e.exportEnab
--, e.h_ordinarie
--, e.h_lavorate
--, e.h_straordinarie
--, e.h_permessi
--, e.h_NonLavorati
--, e.h_ferie
--, e.h_malattia
--, e.h_festivita
--, e.mm_ordinari
--, e.mm_lavorati
--, e.mm_straordinari
--, e.mm_permessi
--, e.mm_NonLavorati
--, e.mm_ferie
--, e.mm_malattia
--, e.mm_festivita
--, e.minMpp
--, e.minLav
--, e.minOrd
--, e.minNonLav
--, e.minStra
--, e.minPerm
--, e.minFer
--, e.minMal
--, e.minFest
--, e.minArcoPres
--, e.h_lav
--, e.h_giust
FROM dbo.v_OreTimbratureDipendenteExport AS e
INNER JOIN dbo.Dipendenti AS dip
ON e.idxDipendente=dip.idxDipendente
AND ( dip.dominio + '\' + dip.utente = SYSTEM_USER OR @flgSingleUser = 0 )
WHERE datalav BETWEEN @dateFrom AND @dateTo
AND ( e.idxDipendente = @idxDipendente OR @idxDipendente = 0 OR @flgSingleUser = 1 )
AND ( @flgOnlyErr = 0 -- cmq tutti se @flgOnlyErr = False o solo quelli in errore NON USATO ( veto Sam )
OR isOk = 0 OR h_ordinarie > ( h_lavorate + h_ferie + h_permessi + h_festivita + h_malattia ) ) -- altrimenti quelle in errore
AND e.exportEnab = 1
END
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/**********************************************************
* STORED stp_lcuByDipDate
*
* elenco dati di timbratura e commessa per utente/periodo
*
* mod: S.E.L. 2012.11.02
*
**********************************************************/
alter PROCEDURE stp_lcuByDipDate
(
@idxDipendente INT,
@dataFrom DATETIME,
@dataTo DATETIME,
@maxErrMin INT = 0, -- minuti massimi di scostamento consentiti per DIFETTO, default 0
@maxErrPlus INT = 0 -- minuti massimi di scostamento consentiti per ECCESSO, default 0
)
with recompile
AS
BEGIN
-- faccio una tab temporanea con tallyTable x calcolo periodo intero...
DECLARE @numD INT
SET @numD = ( SELECT DATEDIFF(dd, @dataFrom, @dataTo ) )
-- tab dei record RegAttività progetti
;WITH myCteRA AS(
SELECT idxDipendente, dataLav, minRegAtt, descrProj
FROM dbo.RegAttivitaExpl
WHERE (idxDipendente = @idxDipendente OR @idxDipendente = 0) AND (dataLav >= DATEADD(DAY,-1,@dataFrom) AND dataLav <= @dataTo)
)
SELECT mc.Data, mc.idxDipendente, ISNULL(te.CognomeNome,'') AS CognomeNome, ISNULL(te.h_lav,0) AS h_lav, CAST(ISNULL(vra.minRegAtt,0) AS DECIMAL(9,3))/60 AS h_com
,ISNULL(te.isOk,0) AS okTimbr
,CASE WHEN ISNULL(vra.minRegAtt,0)-ISNULL(te.h_lav,0)*60 >= @maxErrMin AND ISNULL(vra.minRegAtt,0)-ISNULL(te.h_lav,0)*60 <= @maxErrPlus THEN 1 ELSE 0 END AS okLavCom
,ISNULL(vra.descrProj,'') AS progetti, ISNULL(te.minOrd,0) AS minOrd, ISNULL(te.minStra,0) AS minStra, ISNULL(te.minPerm,0) AS minPerm, ISNULL(te.minFer,0) AS minFer
,ISNULL(te.minMal,0) AS minMal, ISNULL(te.minFest,0) AS minFest, ISNULL(te.minMpp,0) AS minMpp
FROM (SELECT CONVERT(DATE,DATEADD(dd, -N, @dataTo)) as Data, idxDipendente
FROM Tally, Dipendenti
WHERE N <= @numD
AND (idxDipendente = @idxDipendente OR @idxDipendente = 0)
) AS mc
LEFT OUTER JOIN myCteRA vra ON mc.Data = vra.dataLav AND mc.idxDipendente=vra.idxDipendente
LEFT OUTER JOIN TimbratureExpl te ON mc.Data=te.dataLav AND te.idxDipendente=mc.idxDipendente
WHERE (te.idxDipendente = @idxDipendente OR @idxDipendente = 0)
ORDER BY mc.Data DESC
END
RETURN
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/**********************************************************
* STORED stp_RA_clonaLastRA_Utente
*
* clona un attività utente: se c'è da ultima altrimenti da zero x una certa data
*
* mod: S.E.L. 2013.01.17
*
**********************************************************/
alter PROCEDURE stp_RA_clonaLastRA_Utente
(
@idxDipendente INT,
@dataRif DATETIME, -- dataOra inizio record attività
@durataMin INT = 60 --durata in minuti (default 1 h)
)
AS
-- variabili
DECLARE @idxFase INT
DECLARE @idxRA INT
-- arrotondo data richiesta solo all'ora...
SELECT @dataRif = DATEADD(HOUR, DATEPART(HOUR,@dataRif), CONVERT(DATETIME,(CONVERT(DATE,@dataRif))))
-- cerco se esista ultima reg attività utente...
SELECT @idxRA = ISNULL((SELECT TOP 1 idxRA FROM RegAttivita WHERE idxDipendente = @idxDipendente ORDER BY inizio DESC),0)
-- se non ho trovato records, ovvero idxRA = 0, prendo ultima fase da elenco
IF (@idxRA = 0)
BEGIN
-- calcolo ultima fase inserita...
SELECT TOP 1 @idxFase=ISNULL(idxFase,0) FROM AnagFasi ORDER BY idxFase DESC
-- se trovata fase inserisco!
IF(@idxFase > 0)
BEGIN
INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione, importo)
VALUES (@idxDipendente, @idxFase, @dataRif, DATEADD(MINUTE, @durataMin, @dataRif), '...',0)
END
END
ELSE
BEGIN
-- inserisco su data richiesta duplicazione dell'ultima attività utente...
INSERT INTO RegAttivita(idxDipendente, idxFase, inizio, fine, descrizione, importo)
SELECT idxDipendente, idxFase, @dataRif, CASE WHEN @durataMin > 0 THEN DATEADD(MINUTE, @durataMin, @dataRif) ELSE DATEADD(minute, DATEDIFF(MINUTE, inizio, fine), @dataRif) END, descrizione, importo
FROM RegAttivita
WHERE (idxRA = @idxRA)
END
go
commit;
go
set xact_abort on;
go
begin transaction;
go
set ANSI_NULLS on;
go
/*************************************
* STORED PROCEDURE stp_VSProjFasi_search
*
* dato un campo di ricerca va alla caddia del progetto e della fase che corrispondano
* Formati consentiti:
* - testo libero fase
* - formato commessa ETS full (xxxx-xxxx)
* - formato commessa ETS compatto (xx-xx)
*
* mod : 2013.07.04
* aut : S.E. Locatelli
**************************************/
create PROCEDURE stp_VSProjFasi_search
(
@textSearch NVARCHAR(50)
)
AS
DECLARE @codFase NVARCHAR(500)
SELECT @codFase = codFase
FROM AnagFasi
WHERE nomeFase LIKE '%' + @textSearch + '%' OR descrizioneFase LIKE '%' + @textSearch + '%'
AND Attivo = 1
AND EnableTime = 0
-- se non ha trovato nulal cerco anche in progetti... e prendo il primo progetto x nome/descrizione e da li la prima fase
IF(ISNULL(@codFase,'##################') ='##################')
BEGIN
SELECT @codFase = af.codFase
FROM AnagFasi af INNER JOIN AnagProgetti ap ON af.idxProgetto = ap.idxProgetto
WHERE ap.nomeProj LIKE '%' + @textSearch + '%' OR descrProj LIKE '%' + @textSearch + '%'
AND ap.Attivo = 1
AND af.Attivo = 1
AND EnableTime = 0
ORDER BY codFase DESC
END
SELECT TOP 1 idxProgetto, idxFase
FROM AnagFasi
WHERE codFase LIKE @codFase +'%'
AND Attivo = 1
AND EnableTime <> 0
ORDER BY codFase
RETURN
go
commit;
go
-- registro versione...
INSERT INTO [dbo].[LogUpdateDb] ([Versione],[Data]) VALUES(355, GETDATE())
GO
SELECT * FROM LogUpdateDb ORDER BY Versione DESC