Sorry, this is my first post and I'm asking for help hahaha ... I'll comment to see if you can give me a hand and several more can be useful.
I have an assistance system made in PHP and MySQL, which works correctly. Ex: Employee X enters at 8 AM, a record is generated indicating the time of entry, employee X leaves at 5:00 PM and this record is updated in the corresponding field with the time of 5:00 PM, in the logic the code what seeks is that if an employee has the same DATE 2 or more records takes the minimum time: jumpie: (Income) and then goes looking for the maximum (egress) to leave this as output.
My problem is that there are Employees who come to work at 18hs on day 1 and leave at 00hs on day2, so I have different dates and I get inconsistencies because I take both as income ... understands? Can you give me a hand?
EDIT
I add the info they ask me ... It consists of 2 Tables, Registers and Time Control.
-
Records: employees' marks are loaded in raw (Employee, Date and Time, State). The state field I work as a bool to not reprosesar all the records that are in the table.
-
Control Timetable: The information in the table of records is crossed to create a single record with "Employee, Date Entry, Time Entry, Departure Date, Departure Time"
I add the TIME CONTROL code that is where the whole topic is done ...
$vistaTemporal = "CREATE VIEW fingers_temp AS Select empleado, fecha, MIN(time(hora)) as ingreso_real, MAX(time(hora)) as egreso_real FROM eg_registro_fingerprint WHERE estado = 0 AND empleado NOT BETWEEN 99950 AND 99999 GROUP BY empleado,fecha";
$conn->execute($vistaTemporal);
//Consulta tabla temporal
$getAllSQL = "SELECT empleado, fecha, ingreso_real, egreso_real FROM fingers_temp";
$statementOfAll = $conn->execute($getAllSQL);
//Lectura de select
foreach ($statementOfAll as $registro) {
$id = $registro['id'];
$empleado = $registro['empleado'];
$fecha = $registro['fecha'];
$egreso_real = $registro['egreso_real'];
$ingreso_real = $registro['ingreso_real'];
$horas_trabajadas = 0;
// Verifico sin un empleado tiene mas de 1 o mas registros el mismo dia
$controlHorario = "SELECT count(fecha_entrada) as contador, fecha_entrada,empleado FROM eg_control_horario where fecha_entrada = '$fecha' AND empleado = '$empleado'";
$statementOfHorarios = $conn->execute($controlHorario);
$contador = 0;
foreach ($statementOfHorarios as $horario) {
$contador = $horario['contador'];
}
echo $contador;
if ( $contador < 1){
$newControlAsis = "INSERT INTO eg_control_horario (empleado, fecha_entrada, fecha_salida, ingreso_real, egreso_real, horas_trabajadas) VALUES ('$empleado', '$fecha','$fecha' , '$ingreso_real', '$egreso_real','$horas_trabajadas')";
$conn->execute($newControlAsis);
$updateRegistroEstado = "UPDATE eg_registro_fingerprint SET estado = 1";
$conn->execute($updateRegistroEstado);
}else{
$updateControlAsis = "UPDATE eg_control_horario SET egreso_real = '$egreso_real' where fecha_entrada = '$fecha' AND empleado = '$empleado'";
$conn->execute($updateControlAsis);
$updateRegistroEstado = "UPDATE eg_registro_fingerprint SET estado = 1";
$conn->execute($updateRegistroEstado);
}
}
$drop = "DROP VIEW fingers_temp";
$conn->execute($drop);
Raw Records
Time Control
Ignore the theoretical hours and hours worked
The first image is about where all the signings are uploaded, in the second image is where the signings of each employee are joined as long as they meet on the same day. As I do (without breaking the current logic) for when an employee enters during the night and after 00hs, that is, the date of entry is different to the exit.