lundi 11 février 2019

How do I prevent Further updates on a specific column of a Model instance for a specific period of a time?

I'm counting the amount of times employees were late. If they check-in/swipe their card past a certain time, then "late" is stored as true via boolean automatically.

However, if the card swipe was to happen multiple times in a day, the "late" amount keeps increasing. Is there a way to state that if a record of being late for a specific attendant already exsits for today, don't save any new ones until the next day?

If something like ->startOfNExtDay for Carbon exists, that would perhaps fit well.

Here's a picture and code where I save late records:

https://imgur.com/yx8ya29

  if($attendance) {
        $attendance->checked_out_at = $current;
        $attendance->time_spent_working = $attendance->checked_out_at->diffInSeconds($attendance->checked_in_at);
    } else {
        $attendance = new Attendance();
        $attendance->name = $employee->name;
        $attendance->employee_id = $employee->id;
        $attendance->checked_in_at = $current;

        if (($attendance->checked_in_at->startOfDay()->addHours(10)) < $attendance->checked_in_at) {
            $attendance->late = true;


        } else {
            $attendance->late = false;
        }

Displaying it in the view:

            <table class="table attendances_table">
                <tr class="thead-bordered">
                    <th>Employee</th>
                    <th class="centered-text">Total time Worked</th>
                    <th class="centered-text">Times Being Late</th>
                </tr>
                @foreach($employees as $employee)
                <tr>
                    <td></td>
                    <td class="centered-text"></td>
                    <td class="centered-text"></td>
                @endforeach
                </tr>
            </table>

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire