Advertisement
Guest User

Untitled

a guest
Oct 24th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. SELECT DISTINCT
  2. personnel_employee.id AS 'EmployeeID',
  3. personnel_employee.emp_code AS 'CodeID',
  4. dept_name AS 'DepartmentName',
  5. personnel_employee.first_name AS 'Name',
  6. att_attshift.alias AS 'Schedule',
  7. IF((WEEK(iclock_transaction.punch_time, 2) - WEEK(iclock_transaction.punch_time - INTERVAL DAY(iclock_transaction.punch_time)-1 DAY, 2) + 1) % 2 = 0,
  8. (SELECT att1.alias FROM att_timeinterval att1 WHERE att1.id = (SELECT time_interval_id FROM att_shiftdetail ats WHERE ats.shift_id = 12 AND ats.day_index = (7 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1),
  9. (SELECT att2.alias FROM att_timeinterval att2 WHERE att2.id = (SELECT time_interval_id FROM att_shiftdetail ats2 WHERE ats2.shift_id = 12 AND ats2.day_index = (0 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1)) AS horario,
  10. IF((WEEK(iclock_transaction.punch_time, 2) - WEEK(iclock_transaction.punch_time - INTERVAL DAY(iclock_transaction.punch_time)-1 DAY, 2) + 1) % 2 = 0,
  11. (SELECT CAST(att3.in_time AS datetime) FROM att_timeinterval att3 WHERE att3.id = (SELECT time_interval_id FROM att_shiftdetail ats3 WHERE ats4.shift_id = 12 AND ats3.day_index = (7 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1),
  12. (SELECT CAST(att4.in_time AS datetime) FROM att_timeinterval att4 WHERE att4.id = (SELECT time_interval_id FROM att_shiftdetail ats4 WHERE ats4.shift_id = 12 AND ats4.day_index = (0 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1)) AS 'FixedEntrance',
  13. IF((WEEK(iclock_transaction.punch_time, 2) - WEEK(iclock_transaction.punch_time - INTERVAL DAY(iclock_transaction.punch_time)-1 DAY, 2) + 1) % 2 = 0,
  14. (SELECT CAST(addtime((floor(att5.duration / 60)*10000 + (att5.duration % 60*100)), time(att5.in_time)) AS datetime) FROM att_timeinterval att5 WHERE att5.id = (SELECT time_interval_id FROM att_shiftdetail ats5 WHERE ats5.shift_id = 12 AND ats5.day_index = (7 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1),
  15. (SELECT CAST(addtime((floor(att6.duration / 60)*10000 + (att6.duration % 60*100)), time(att6.in_time)) AS datetime) FROM att_timeinterval att6 WHERE att6.id = (SELECT time_interval_id FROM att_shiftdetail ats6 WHERE ats6.shift_id = 12 AND ats6.day_index = (0 + DAYOFWEEK(iclock_transaction.punch_time) - 1) LIMIT 1) LIMIT 1)) AS 'FixedExit',
  16. CAST(iclock_transaction.punch_time AS date) AS 'CurrentDay',
  17. DATE_FORMAT(iclock_transaction.punch_time, '%H:%i:%s') AS 'Time1'
  18. FROM
  19. att_shiftdetail
  20. INNER JOIN
  21. att_attshift
  22. ON att_attshift.id = att_shiftdetail.shift_id
  23. INNER JOIN
  24. att_timeinterval
  25. ON att_timeinterval.id = att_shiftdetail.time_interval_id
  26. INNER JOIN
  27. att_attschedule
  28. ON att_attschedule.shift_id = att_attshift.id
  29. INNER JOIN
  30. personnel_employee
  31. ON att_attschedule.employee_id = personnel_employee.id
  32. INNER JOIN
  33. iclock_transaction
  34. ON personnel_employee.emp_code = iclock_transaction.emp_code
  35. INNER JOIN
  36. personnel_department
  37. ON personnel_employee.department_id = personnel_department.id
  38. WHERE
  39. personnel_employee.status <> 3
  40. AND CAST(iclock_transaction.punch_time AS date) BETWEEN '2018-05-11' AND '2018-05-28'
  41. AND personnel_department.id = '11'
  42. AND personnel_employee.emp_code = '101104'
  43. and dayname(iclock_transaction.punch_time) = elt(att_shiftdetail.day_index mod 7 + 1, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
  44. and elt(att_shiftdetail.day_index mod 7 + 1, '0', '1', '2', '3', '4', '5', '6') = att_shiftdetail.day_index
  45. group by
  46. iclock_transaction.punch_time
  47. ORDER BY
  48. personnel_employee.emp_code,
  49. iclock_transaction.punch_time;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement