-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRespaldoProcedimientosAl.txt
282 lines (266 loc) · 12.1 KB
/
RespaldoProcedimientosAl.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
--------------Logueo--------------------------
USE [db_IntranetMEDC]
GO
/****** Object: StoredProcedure [dbo].[usp_LogAdmin] Script Date: 01/12/2021 05:49:14 p. m. ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_LogAdmin]
@usuario varchar (25),
@Pass nvarchar(255)
As
declare @salida int
Begin
if not exists (select e.NumEmpleado, l.Pass from tbl_Empleados e
inner join tbl_Logueo l on e.id_Empleado=l.Id_Empleado
where @usuario = NumEmpleado and l.Pass =@Pass )
if not exists
( SELECT
--A.Id_Usuario,
--A.Id_Tipo,
A.Usuario,
CONVERT(varchar(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)),
ISNULL(B.Nombre,'')+' '+ISNULL(B.ApPaterno,'')+' '+ISNULL(B.ApMaterno,'') [Nombre]
FROM Med_Marketing.dbo.tbl_LogIn A
INNER JOIN Med_Marketing.DBO.tbl_Usuarios B ON A.Id_Usuario=B.Id_Usuario
INNER JOIN Med_Marketing.DBO.tbl_Tipos C ON B.Id_Tipo=C.Id_Tipo
where A.Usuario collate latin1_general_cs_as =@usuario
and CONVERT(VARCHAR(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)) collate latin1_general_cs_as =@Pass)
Begin
select 1 as Opcion---- Datos erroneos
end;
--if exists (select e.NumEmpleado , Pass from tbl_Empleados e
--inner join tbl_Logueo l on e.id_Empleado=l.Id_Empleado
--where @usuario = e.NumEmpleado and Pass =@Pass AND l.Pass <> CAST( e.NumEmpleado as varchar))
--and exists (select u.NumEmpleado
--from tbl_Logueo l
--inner join tbl_Empleados u on u.id_Empleado = l.Id_Empleado
--where
--cast(Fecha_caducar as date) = cast (getdate() as date) and
-- u.NumEmpleado=@usuario )
-- Begin
--select 2 as Opcion ---Cambiar contraseña
--end;
--if exists (select e.NumEmpleado , l.Pass , l.Id_status from tbl_Empleados e
--inner join tbl_Logueo l on e.id_Empleado=l.Id_Empleado
--where @usuario = e.NumEmpleado and l.Pass =@Pass
-- and cast(l.Fecha_caducar as date) <> cast (getdate() as date)
--and exists (select u.id_Empleado from
--tbl_Empleados u inner join
--tbl_Logueo l on u.id_Empleado = l.Id_Empleado
--where @usuario = u.NumEmpleado and l.Pass =@Pass))
--if exists (select l.Pass from
--tbl_Empleados u
--inner join tbl_Logueo l on u.id_Empleado = l.Id_Empleado
--where @Pass = cast(u.NumEmpleado as varchar))
-- Begin
--select 5 as Opcion --- Cambio de contraseña (1° de sesion)
--end;
Begin
if exists (select e.NumEmpleado, l.Pass
from tbl_Empleados e
inner join tbl_Logueo l on e.id_Empleado=l.Id_Empleado
where (cast(e.NumEmpleado as varchar) = @usuario) AND (l.Pass = @Pass)
AND (l.Pass <> cast(e.NumEmpleado as varchar)))
select 3 as Opcion, cast (l.Fecha_caducar as date) as FechaCaducar,
e.Nombre_1, e.Nombre_2, e.AMaterno, e.APaterno,e.id_Empleado,e.Site,e.Puesto, l.Pass
FROM tbl_Empleados e
inner join tbl_Logueo l on e.id_Empleado=l.Id_Empleado
WHERE cast(e.NumEmpleado as varchar) = @usuario AND l.Pass = @Pass AND l.Pass <> cast(e.NumEmpleado as varchar) --- Dtos correctos
end;
if exists ( SELECT
--A.Id_Usuario,
--A.Id_Tipo,
A.Usuario,
CONVERT(varchar(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)),
ISNULL(B.Nombre,'')+' '+ISNULL(B.ApPaterno,'')+' '+ISNULL(B.ApMaterno,'') [Nombre]
FROM Med_Marketing.dbo.tbl_LogIn A
INNER JOIN Med_Marketing.DBO.tbl_Usuarios B ON A.Id_Usuario=B.Id_Usuario
INNER JOIN Med_Marketing.DBO.tbl_Tipos C ON B.Id_Tipo=C.Id_Tipo
where A.Usuario collate latin1_general_cs_as =@usuario
and CONVERT(VARCHAR(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)) collate latin1_general_cs_as =@Pass)
Begin
if not exists (SELECT
A.Usuario
FROM Med_Marketing.dbo.tbl_LogIn A
INNER JOIN tbl_Empleados e on a.Usuario collate latin1_general_cs_as =cast(NumEmpleado as varchar)
where @usuario= cast(e.NumEmpleado as varchar))
Begin
insert into db_IntranetMEDC.dbo.tbl_Empleados (NumEmpleado,Nombre_1,APaterno,AMaterno,Puesto,IdDireccion,IdDepartamento) SELECT
--A.Id_Usuario,
--A.Id_Tipo,
A.Usuario,B.Nombre,B.ApPaterno,B.ApMaterno,33 as Puesto,10 IdDireccion,28 as IdDepartamento
FROM Med_Marketing.dbo.tbl_LogIn A
INNER JOIN Med_Marketing.DBO.tbl_Usuarios B ON A.Id_Usuario=B.Id_Usuario
INNER JOIN Med_Marketing.DBO.tbl_Tipos C ON B.Id_Tipo=C.Id_Tipo
where A.Usuario collate latin1_general_cs_as =@usuario
and CONVERT(VARCHAR(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)) collate latin1_general_cs_as =@Pass
end
select 3 as Opcion, 'NULL' as FechaCaducar,B.Nombre[Nombre_1],[Nombre_2], B.ApPaterno[AMaterno],B.ApMaterno [APaterno],e.id_Empleado,e.Puesto,'NULL' as[Site],CONVERT(VARCHAR(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass) )as Pass
FROM Med_Marketing.dbo.tbl_LogIn A
INNER JOIN tbl_Empleados e on a.Usuario collate latin1_general_cs_as =cast(NumEmpleado as varchar)
INNER JOIN Med_Marketing.DBO.tbl_Usuarios B ON A.Id_Usuario=B.Id_Usuario
INNER JOIN Med_Marketing.DBO.tbl_Tipos C ON B.Id_Tipo=C.Id_Tipo
where A.Usuario collate latin1_general_cs_as =@usuario
and CONVERT(VARCHAR(MAX),DECRYPTBYPASSPHRASE('LLAVE',A.Pass)) collate latin1_general_cs_as =@Pass --- Dtos correctos
end;
if exists (select u.Id_Empleado from
tbl_Empleados u
inner join tbl_Logueo l on u.id_Empleado = l.Id_Empleado
where l.Id_status= 1 and @usuario = cast(u.NumEmpleado as varchar) and Pass =@Pass)
Begin
select 4 as result ,@salida as Estatus ---Estatus bloqueado
end;
end;
-----------------------------------------
SP VALIDAR CONTRASEÑA
ALTER procedure [dbo].[usp_ValiCambioContra]
@usuario varchar (25),
@newpass varchar (20)
As
DECLARE
@fecha_actualizada datetime = GETDATE(),
@fecha_caducar datetime= DATEADD(month, 1, SYSDATETIME()),
@us varchar(25) ,
@fecha_hoy date = GETDATE()
if exists (select u.Usuario , Pass
from tbl_Usuarios u , tbl_Logueo l
where @usuario = u.Usuario
and datepart( day,l.Fecha_caducar) >= datepart( day,@fecha_hoy)
and datepart( MONTH,l.Fecha_caducar) = datepart( MONTH,@fecha_hoy)
or datepart( MONTH,l.Fecha_caducar) <= datepart( MONTH,@fecha_hoy))
Begin
select 1
end
update tbl_Logueo
set
Pass =@newpass,
Fecha_actualizada = @fecha_actualizada ,
Fecha_caducar = @fecha_caducar
from tbl_Logueo l, tbl_Usuarios u
where @usuario = u.Usuario
and l.Id_usuario= u.Id_usuario and datepart( MONTH,l.Fecha_caducar) = datepart( MONTH,@fecha_hoy)
if not exists (select u.Usuario , Pass
from tbl_Usuarios u , tbl_Logueo l
where @usuario = u.Usuario
and datepart( day,l.Fecha_caducar) >= datepart( day,@fecha_hoy)
and datepart( MONTH,l.Fecha_caducar) = datepart( MONTH,@fecha_hoy)
or datepart( MONTH,l.Fecha_caducar) <= datepart( MONTH,@fecha_hoy))
Begin
select 2
end
-------------------------Reporte 05-------------------------------------
ALTER procedure [dbo].[usp_Reporte05]
@Tipo int ,
@FechaInicio DATE,
@FechaFin DATE ,
@Puesto int,
@Campaña int
as
declare @T int
set @T=@Tipo;
if (@T=1)
begin
--- alta por usuario
select distinct e.NumEmpleado,Nombre_1,Nombre_2,APaterno,AMaterno,cast(Fingreso as date) as Fingreso, c.Campania, p.Puesto,@T as Tipo
from tbl_Empleados e , cat_Campanias c ,cat_Puestos p
where cast (e.FBaja as date) between @FechaInicio and @FechaFin
and
e.Campania= @Campaña and e.Puesto=@Puesto and e.Campania= c.Id_Campania and p.id_Puesto=e.Puesto
order by NumEmpleado desc
end
else
---baja por usuario
begin
select distinct NumEmpleado,Nombre_1,Nombre_2,APaterno,AMaterno,tb.TipoBaja,Motivo, cast(e.FBaja as date) as FechaBaja, c.Campania, p.Puesto,@T as Tipo
from tbl_Empleados e , cat_Motivo m , cat_TipoBaja tb, cat_Campanias c ,cat_Puestos p
where cast (e.FBaja as date) between @FechaInicio and @FechaFin
and e.TipoBaja= tb.Id_TipoBaja and e.MotivoBaja = m.Id_Motivo and
e.Campania= @Campaña and e.Puesto=@Puesto and e.Campania= c.Id_Campania and p.id_Puesto=e.Puesto
order by NumEmpleado desc
end
----------------------------------------------Insertar Horarios-----------------------------------------------------
ALTER procedure [dbo].[usp_Horarios]
@IdEmp int,
@EntL time = null,
@SaL time= null,
@EntM time=null,
@SalM time=null,
@EntMi time=null,
@SalMi time=null,
@EntJ time=null,
@SalJ time=null,
@EntV time=null,
@SalV time=null,
@EntS time=null,
@SalS time=null,
@EntD time=null,
@SalD time=null
as
begin
if not exists (select id_Empleado from tbl_Horarios where @IdEmp=id_Empleado)
begin
if exists ( select e.id_Empleado from tbl_Empleados e , tbl_Horarios h where e.id_Empleado= @IdEmp )
begin
insert into tbl_Horarios (id_Empleado,Lunes_E,Lunes_S,Martes_E,Martes_S,Miercoles_E,Miercoles_S,Jueves_E,Jueves_S,Viernes_E,Viernes_S,Sabado_E,Sabado_S,Domingo_E,Domingo_S)
values (@IdEmp,@EntL,@SaL,@EntM, @SalM,@EntMi,@SalMi,@EntJ,@SalJ,@EntV,@SalV,@EntS,@SalS,@EntD,@SalD)
Select 1
end
END
else
select 3
end
----------------------------------------Reporte de horarios------------------------------------------------------------
ALTER procedure [dbo].[usp_RHorarios]
@NumEmp int = null,
@area int = null,
@status int = null
as
--FORMAT(cast(h.Lunes as time), N'hh\.mm')
declare @ID int,
@estado int
---Por numero de empleado---
if (@NumEmp is not null and @area is null and @status is null)
begin
select distinct e.NumEmpleado, concat (e.Nombre_1 ,' ',e.Nombre_2,' ',e.APaterno,' ',e.AMaterno)as Nombre ,
p.Puesto, FORMAT(cast(h.Lunes_E as time), N'hh\:mm') as Lunes_E, FORMAT(cast(h.Lunes_S as time), N'hh\:mm') as Lunes_S,
FORMAT (CAST(h.Martes_E AS time),N'hh\:mm') AS Martes_E, FORMAT (CAST(h.Martes_S AS time),N'hh\:mm') AS Martes_S,
FORMAT(CAST(h.Miercoles_E AS time), N'hh\:mm') AS Miercoles_E , FORMAT(CAST(h.Miercoles_S AS time), N'hh\:mm') AS Miercoles_S,
FORMAT(CAST(h.Jueves_E AS time), N'hh\:mm')AS Jueves_E , FORMAT(CAST(h.Jueves_S AS time), N'hh\:mm')AS Jueves_S,
FORMAT(CAST(h.Viernes_E AS time) ,N'hh\:mm') AS Viernes_E, FORMAT(CAST(h.Viernes_S AS time) ,N'hh\:mm') AS Viernes_S,
FORMAT(CAST(h.Sabado_E AS time),N'hh\:mm') AS Sabado_E,FORMAT(CAST(h.Sabado_S AS time),N'hh\:mm') AS Sabado_S,
FORMAT(CAST(h.Domingo_E AS time),N'hh\:mm') AS Domingo_E,FORMAT(CAST(h.Domingo_S AS time),N'hh\:mm') AS Domingo_S
from tbl_Empleados e , cat_Puestos p, tbl_Empleados , tbl_Horarios h
where @NumEmp = e.NumEmpleado and h.id_Empleado = e.id_Empleado and e.Puesto= p.id_Puesto
end
---Por area---
if (@NumEmp is null and @area is not null and @status is null)
begin
select distinct e.NumEmpleado,concat (e.Nombre_1 ,' ',e.Nombre_2,' ',e.APaterno,' ',e.AMaterno)as Nombre ,
p.Puesto,FORMAT(cast(h.Lunes_E as time), N'hh\:mm') as Lunes_E, FORMAT(cast(h.Lunes_S as time), N'hh\:mm') as Lunes_S,
FORMAT (CAST(h.Martes_E AS time),N'hh\:mm') AS Martes_E, FORMAT (CAST(h.Martes_S AS time),N'hh\:mm') AS Martes_S,
FORMAT(CAST(h.Miercoles_E AS time), N'hh\:mm') AS Miercoles_E , FORMAT(CAST(h.Miercoles_S AS time), N'hh\:mm') AS Miercoles_S,
FORMAT(CAST(h.Jueves_E AS time), N'hh\:mm')AS Jueves_E , FORMAT(CAST(h.Jueves_S AS time), N'hh\:mm')AS Jueves_S,
FORMAT(CAST(h.Viernes_E AS time) ,N'hh\:mm') AS Viernes_E, FORMAT(CAST(h.Viernes_S AS time) ,N'hh\:mm') AS Viernes_S,
FORMAT(CAST(h.Sabado_E AS time),N'hh\:mm') AS Sabado_E,FORMAT(CAST(h.Sabado_S AS time),N'hh\:mm') AS Sabado_S,
FORMAT(CAST(h.Domingo_E AS time),N'hh\:mm') AS Domingo_E,FORMAT(CAST(h.Domingo_S AS time),N'hh\:mm') AS Domingo_S
from tbl_Empleados e , cat_Puestos p, tbl_Empleados , tbl_Horarios h
where @area = e.IdDepartamento
and h.id_Empleado = e.id_Empleado and e.Puesto= p.id_Puesto
end
---Por Estatus---
if (@NumEmp is null and @area is null and @status is not null)
begin
select distinct e.NumEmpleado,concat (e.Nombre_1 ,' ',e.Nombre_2,' ',e.APaterno,' ',e.AMaterno)as Nombre ,
p.Puesto,FORMAT(cast(h.Lunes_E as time), N'hh\:mm') as Lunes_E, FORMAT(cast(h.Lunes_S as time), N'hh\:mm') as Lunes_S,
FORMAT (CAST(h.Martes_E AS time),N'hh\:mm') AS Martes_E, FORMAT (CAST(h.Martes_S AS time),N'hh\:mm') AS Martes_S,
FORMAT(CAST(h.Miercoles_E AS time), N'hh\:mm') AS Miercoles_E , FORMAT(CAST(h.Miercoles_S AS time), N'hh\:mm') AS Miercoles_S,
FORMAT(CAST(h.Jueves_E AS time), N'hh\:mm')AS Jueves_E , FORMAT(CAST(h.Jueves_S AS time), N'hh\:mm')AS Jueves_S,
FORMAT(CAST(h.Viernes_E AS time) ,N'hh\:mm') AS Viernes_E, FORMAT(CAST(h.Viernes_S AS time) ,N'hh\:mm') AS Viernes_S,
FORMAT(CAST(h.Sabado_E AS time),N'hh\:mm') AS Sabado_E,FORMAT(CAST(h.Sabado_S AS time),N'hh\:mm') AS Sabado_S,
FORMAT(CAST(h.Domingo_E AS time),N'hh\:mm') AS Domingo_E,FORMAT(CAST(h.Domingo_S AS time),N'hh\:mm') AS Domingo_S
from tbl_Empleados e , cat_Puestos p, tbl_Empleados , tbl_Horarios h
where @status = e.Estatus
and e.Puesto= p.id_Puesto and h.id_Empleado = e.id_Empleado
end