2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`workerTimeControl_calculateOddDays`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Calculo de las fichadas impares por empleado y dia.
|
|
|
|
*
|
|
|
|
* @return tmp.workerTimeControlOddDays (userFk, dated)
|
|
|
|
*/
|
|
|
|
SET @cont := FALSE;
|
|
|
|
SET @lastUserFk:= NULL;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays;
|
|
|
|
CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays
|
|
|
|
SELECT sub2.userFk workerFk, sub2.dated
|
|
|
|
FROM (
|
|
|
|
SELECT userFk,
|
|
|
|
dated,
|
|
|
|
COUNT(*) cont2
|
|
|
|
FROM (
|
|
|
|
SELECT DATE(wtc.timed) dated,
|
|
|
|
userFk,
|
|
|
|
IFNULL(@cont, @cont := TRUE ),
|
|
|
|
IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE),
|
|
|
|
@cont cont,
|
|
|
|
@lastUserFk := userFk
|
|
|
|
FROM workerTimeControl wtc
|
|
|
|
WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND util.dayEnd(util.VN_CURDATE())
|
|
|
|
ORDER BY userFk, timed
|
|
|
|
LIMIT 10000000000000000000)sub
|
|
|
|
GROUP BY cont
|
|
|
|
HAVING cont2 MOD 2 = 1
|
|
|
|
)sub2;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|