Skip to content

Instantly share code, notes, and snippets.

@fwarren
Last active February 2, 2021 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwarren/822d6c0984763e5e5fe07294e1dca65c to your computer and use it in GitHub Desktop.
Save fwarren/822d6c0984763e5e5fe07294e1dca65c to your computer and use it in GitHub Desktop.
employee_ids = [7, 25, 35, 18]
date_start = datetime.strptime('2021-01-15', '%Y-%m-%d')
date_finish = datetime.strptime('2021-01-31', '%Y-%m-%d')
def get_job_time_punches(cursor, employee_ids, date_start, date_end):
"""Get all punches fror all employees during the required date range."""
SQL = """
SELECT tp.inpunch_dt, tp.workingpunch_ts, tp.inout_id, job.job_id,
tp.task_id, tp.job_id, jobpunch_yn, job.jobname
FROM timeWorkingPunch tp
JOIN job ON tp.job_id = job.job_id
WHERE tp.employee_id IN (""" + ( "%s, " * len(employee_ids) )[:-2] + """)
AND tp.inpunch_dt BETWEEN %s AND %s
ORDER BY tp.inpunch_dt, tp.workingpunch_ts
"""
cursor.execute(SQL, (*employee_id, date_start, date_end))
punches = cursor.fetchall()
return punches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment