Closed GoogleCodeExporter closed 8 years ago
Se edita la consulta de envio al estudio y se hace una union con los
funcionarios dados de baja que no tienen horasgeneradas en la fecha
SELECT @rownum:=@rownum+1 AS Nro,CONS.*,CAST((SELECT /*HS A SUMAR*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='HS A SUMAR') as CHAR) as 'HS A
SUMAR', CAST((SELECT /*HS. LIC. SIND.*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='HS. LIC. SIND.') as CHAR) as 'HS
LIC. SIND.',CAST((SELECT /*PAP*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='PAP') as CHAR) as PAP,CAST((SELECT
/*COMPLEMENTO*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='COMPLEMENTO') as CHAR) as 'COMPL',
/* NO LLEVA TICKETS ALIMENTACION */IF((select NoLlevaTicketsAlimentacion from
empleados where NroEmpleado=CONS.Emp)=1,'NO','') as 'TA',/* ANTIGUEDAD */
CAST((SELECT CAST(if(extract(YEAR FROM from_days(datediff(curdate(),
emp.FechaIngreso))) < 11, concat(extract(YEAR FROM
from_days(datediff(curdate(), emp.FechaIngreso))),'%'),'10%') AS CHAR) as
Antiguedad FROM empleados emp where emp.NroEmpleado=CONS.Emp) AS CHAR) as
ANTIG, /* ARMADO */CAST((SELECT CAST(if( emp.CapacitadoPortarArma=1 and
emp.EnServicioArmado=1,if(curdate()>='2012-01-01' ,'5%','2.5%'),'') AS CHAR)
from empleados emp where emp.Activo=1 and NroEmpleado=CONS.Emp) AS CHAR) as
ARMADO,/* EXTRAS DESCUENTOS */ CAST((SELECT /*RETENCION JUDICIAL*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='RETENCION JUDICIAL') AS CHAR) as
'RET. JUD.', CAST((SELECT /*ANDA*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='ANDA') AS CHAR) as ANDA,
CAST((SELECT /*RET. COOP.*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='RET. COOP.') as CHAR) as 'RET.
COOP.',CAST((SELECT /*ADELANTO*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='ADELANTO') AS CHAR) as ADELANTO,
CAST((SELECT /*RELIQ. HORAS*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='RELIQ. HORAS') as CHAR) as 'RELIQ.
HORAS', CAST((SELECT /*DESC. ADM.*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='DESC. ADM.') as CHAR) as 'DESC.
ADM.',CAST((SELECT /*BOLETOS*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='BOLETOS') AS CHAR) as BOLETOS,
CAST((SELECT /*MOVISTAR*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='MOVISTAR') AS CHAR) as
MOVISTAR,CAST((SELECT /*UNIFORME*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='UNIFORME') as CHAR) as
'UNIFORME',CAST((SELECT /*CURSO*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='CURSO') AS CHAR) as
CURSO,CAST((SELECT /*CARNET DE SALUD*/
IF(tel.LlevaHs=0,sum(if(el.Signo=0,cel.ValorCuota*(-1),cel.ValorCuota)),SEC_TO_T
IME(SUM(el.CantHs_TipoExtraLlevaHsEnSegs))) FROM cuotasextrasliquidacion cel,
extrasliquidacion el, tipoextraliquidacion tel WHERE el.IdExtraLiquidacion =
cel.IdExtraLiquidacion and el.IdEmpleado = CONS.Emp and cel.Fecha between
'FECHADESDE' and 'FECHAHASTA' and el.idTipoExtraLiquidacion =
tel.idTipoExtraLiquidacion and tel.Nombre='CARNET DE SALUD') as CHAR) as 'C. DE
SALUD', /*CUOTA SINDICAL*/ CAST(if((SELECT EnSindicato from empleados where
NroEmpleado=CONS.Emp)=1,'1%','') AS CHAR) as 'CUOTA SIND.' from (SELECT
@rownum:=0) r, ((SELECT empPrim.NroEmpleado as Emp, empPrim.Apellido,
empPrim.Nombre, empPrim.NumeroDocumento as 'C.I.', empPrim.ServicioActual,
empPrim.Turno, empPrim.FechaIngreso,empPrim.FechaBaja,empPrim.ValorHora, /* NO
FERIADOS */ /*HS COMUNES*/
CAST(sec_to_time(SUM(time_to_sec(IF(MAKEDATE(2000,DAYOFYEAR(HorasTmp.FechaCorres
pondiente)) not in (SELECT fecha FROM feriados), IF (cargo.CobraHsExtras=1,
/*EXTRAS*/CASE WHEN
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) <0 THEN
HorasTmp.Horas WHEN
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) >= 0 THEN
MAKETIME(cargo.CantidadHsComunes,0,0) END, HorasTmp.Horas),MAKETIME(0,0,0)))))
AS CHAR) AS SENCILLAS_X1, /*HS EXTRAS (X2)*/
CAST(sec_to_time(SUM(time_to_sec(IF(MAKEDATE(2000,DAYOFYEAR(HorasTmp.FechaCorres
pondiente)) not in (SELECT fecha FROM feriados), IF(cargo.CobraHsExtras=1,CASE
WHEN TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) < 0 THEN
MAKETIME(0,0,0) ELSE
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0))
END,MAKETIME(0,0,0)),MAKETIME(0,0,0))))) AS CHAR) AS EXTRAS_X2, /* FERIADOS */
CAST(sec_to_time(SUM(time_to_sec(IF(MAKEDATE(2000,DAYOFYEAR(HorasTmp.FechaCorres
pondiente)) in (SELECT fecha FROM feriados), /*HS COMUNES FERIADOS (X2)*/ IF
(cargo.CobraHsExtras=1, /*EXTRAS*/CASE WHEN
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) <0 THEN
HorasTmp.Horas WHEN
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) >= 0 THEN
MAKETIME(cargo.CantidadHsComunes,0,0) END, HorasTmp.Horas),MAKETIME(0,0,0)))))
AS CHAR) AS FERIADO_TRABAJADO_X2, /*HS EXTRAS FERIADOS (X2_5)*/
CAST(sec_to_time(SUM(time_to_sec(IF(MAKEDATE(2000,DAYOFYEAR(HorasTmp.FechaCorres
pondiente)) in (SELECT fecha FROM feriados),IF (cargo.CobraHsExtras=1,CASE WHEN
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0)) < 0 THEN
MAKETIME(0,0,0) ELSE
TIMEDIFF(HorasTmp.Horas,MAKETIME(cargo.CantidadHsComunes,0,0))
END,MAKETIME(0,0,0)),MAKETIME(0,0,0))))) AS CHAR) AS
FERIADO_TRABAJADO_EXTRAS_X2_5 FROM (SELECT
hgeaux.NroEmpleado,hgeaux.FechaCorrespondiente,
sec_to_time(SUM(time_to_sec(TIMEDIFF(hgeaux.HoraSalida,hgeaux.HoraEntrada))))
as Horas from horasgeneradasescalafon hgeaux WHERE hgeaux.FechaCorrespondiente
between 'FECHADESDE' and 'FECHAHASTA' AND hgeaux.NroEmpleado not in (9998,9999)
AND hgeaux.Descanso=0 group by hgeaux.NroEmpleado,hgeaux.FechaCorrespondiente)
AS HorasTmp, Empleados empPrim, TiposCargos cargo WHERE
empPrim.NroEmpleado=HorasTmp.NroEmpleado and empPrim.IdCargo=cargo.IdCargo and
cargo.TipoFacturacion='JORNALERO' GROUP BY Emp, Nombre, Apellido) UNION (select
emp.NroEmpleado as Emp, emp.Apellido, emp.Nombre, emp.NumeroDocumento as
'C.I.', emp.ServicioActual, emp.Turno,
emp.FechaIngreso,emp.FechaBaja,emp.ValorHora,'','','','' from empleados emp,
tiposcargos cargo where emp.IdCargo=cargo.IdCargo and
cargo.TipoFacturacion='JORNALERO' and emp.FechaBaja between 'FECHADESDE' and
'FECHAHASTA' and emp.NroEmpleado not in (select distinct(NroEmpleado) from
horasgeneradasescalafon hge where hge.FechaCorrespondiente between 'FECHADESDE'
and 'FECHAHASTA') GROUP BY Emp, Nombre, Apellido) Order by Emp) AS CONS ORDER
BY Nro
40 min
Original comment by juanga...@gmail.com
on 1 Jul 2011 at 11:34
Original comment by juanga...@gmail.com
on 1 Jul 2011 at 11:46
Original comment by juanga...@gmail.com
on 12 Jul 2011 at 3:58
Original issue reported on code.google.com by
juanga...@gmail.com
on 1 Jul 2011 at 9:31