DEV Community

Discussion on: Design for a time clocking app

Collapse
 
sir_wernich profile image
Wernich ️

this is right up my ally. :)

what reader are you using? is it a simple "put your finger and clock" reader or does it have some buttons that they maybe can press to allow the employees to select on/off?

what you will probably end up doing is keeping track of the employee's current state and toggling it and storing all the clockings in one table. in your employee table you can have something like "CurrentState", which will tell you if the employee is currently clocked on or off (i suck at naming, so feel free to use a better name than that).

when you query the device, you can sort all the clockings by employee number and then by time, so you can then process each individual clocking for that employee and save it in the DB with either 1 for "on" or 0 for "off". when you're done with processing the employee's clockings, you write that status to the employee table, then move on to the next employee.

the fun part is deciding whether you're always just going to toggle, or if you will manually set the employee to be "off" at the end of the day. then you need to figure out what the "end of the day" will be: if it's midnight, then that's cool, but if someone can possibly work past midnight, then you're going to have to start looking at setting up shifts and so on.

if you're not too interested in calculating the time that people work, then it gets easier, but you'll still want to put in a reasonable amount of logic to prevent the system from showing you clocked out at 8am and clocked in at 5pm. :)