ianvizarra / attendance

Attendance package for Laravel application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attendance package for Laravel applications.

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Add Attendance feature with ease to your laravel application.

Installation

You can install the package via composer:

composer require ianvizarra/attendance

You can publish and run the migrations with:

php artisan vendor:publish --tag="attendance-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="attendance-config"

This is the contents of the published config file:

return [
  'logs_table' => 'attendance_logs',
    'schedule' => [
        'timeIn' => 9,
        'timeOut' => 17,
        'requiredDailyHours' => 8,
        'timeInAllowance' => 30, // minutes
        
        'workDays' => [
            'Monday',
            'Tuesday',
            'Wednesday',
            'Thursday',
            'Friday'
        ],
        'offDays' => [
            'Saturday',
            'Sunday'
        ]
    ],
    'user_model' => config('auth.providers.users.model', \App\Models\User::class),
    'users_table' => 'users'
];

Add CanLogAttendance Interface and HasAttendance Trait to your User model.

class User extends Authenticatable implements CanLogAttendance
{
    use HasAttendance;
}

Usage

Using User Model

$user->attendance(); // HasMany relationship to attendance log model

$user->timeIn(); // create an time-in attendance log entry

$user->timeOut(); // create an time-out attendance log entry

$user->hasTimeIn(); // return true if user already time-in for today
$user->hasTimeOut(); // return true if user already time-out for today
$user->hasWorked(); // return true if user already time-in and time-out for today
$user->getTimeIn(); // return the time-in attendance log for today

$user->logAttendance('in', 'on-time', now()); // manually log an attendance by type, status and time

Using Facade

use Ianvizarra\Attendance\Facades\Attendance;

 // create an attendance log entry for the currently logged-in user
 // by default it will the current time
 Attendance::timeIn(); 
 Attendance::timeOut();
 
 // manually set the time logged instead of the current time
 Attendance::timeIn(now()->subMinutes(30));
 
 // manually set the schedule configuration
 // the default config values can be found in config/attendance.php `config('attendance.schedule.hours')`
 Attendance::timeIn(now(), [
    'timeIn' => 8,
    'timeOut' => 16,
    'requiredDailyHours' => 8
]);
 
 // manually set the user other than the logged-in user
 Attendance::setUser($user)->timeIn();
 
 // get the time in status
 Attendance::timeInStatus(); // on-time, late
 // manually set the time using Carbon instance
 Attendance::timeInStatus(now()->subMinutes(30)); // on-time, late
  // manually set the schedule configuration
 Attendance::timeInStatus(now(), [
    'timeIn' => 8,
    'timeOut' => 16,
    'requiredDailyHours' => 8
]); // on-time, late
 
 // get the time out status
 Attendance::timeOutStatus(); // on-time, under-time
 // manually set the time using Carbon instance
 Attendance::timeOutStatus(now()->subMinutes(30)); // on-time, under-time
 // manually set the schedule configuration
 Attendance::timeOutStatus(now(), [
    'timeIn' => 8,
    'timeOut' => 16,
    'requiredDailyHours' => 8
]); // on-time, under-time

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Attendance package for Laravel application

License:MIT License


Languages

Language:PHP 100.0%