PHP Laravel 考勤系统[节假日]

PHP Laravel 考勤系统

PHP Laravel 考勤系统

PHP Laravel 考勤系统

前言

最近在做员工考勤系统,为了各部门员工考勤精准把控。本帖更多提供思路作为交流!

功能

  • 根据权限设定查看其他的员工的考勤,否则只展示自己的考勤内容。
  • 使用日历形式展示当月或其他时间(月)考勤情况。
  • 统计缺勤、迟到时间、加班时间情况。
  • 签到上班下班和补卡。
  • 节假日。
  • 节假日公司可能会对工作日期进行调整。

关于节假日 请查看github老哥的中国节假日github.com/NateScarlet/holiday-cn

设置

上班打卡的时间范围设定;例如:张三公司工作时间是9:00 ~ 17:00,我们所说的朝九晚五。那么超出9点进行打卡呢是属于迟到的。

A. 在打卡时间5分钟内属于正常范围。我们按21.75天进行计算假设张三每天都迟到5分钟。最多是108分钟。下班也是提前5分钟走。张三一个月就提前217分钟既3.6个小时。半个工作日。那么这是属于公司能接受的范围。(这都是我理想化的哈,我进过的公司都没这么好的。)

B. 在本月内在累计20分钟内属于正常范围。超出按迟到计算。

  1. 工作时间设定
  2. 允许范围类型 (a. 每天; b. 累计)
  3. 打卡时间范围(上下班打卡不同设定)。超出即不允许打卡。
  4. 允许补卡次数。

表设计


$table->id();
$table->unsignedBigInteger('holder_id');
$table->boolean('punch_in')->default(0);
$table->timestamp('punch_in_at')->nullable();
$table->string('punch_in_driver', 50)->nullable();
$table->unsignedInteger('absent_am_duration')->default(0);
$table->json('punch_in_locale')->nullable();

$table->date('punch_at')->index();

$table->boolean('punch_out')->default(0);
$table->timestamp('punch_out_at')->nullable();
$table->string('punch_out_driver', 50)->nullable();
$table->unsignedInteger('absent_pm_duration')->default(0);
$table->json('punch_out_locale')->nullable();

$table->enum('supplement_punch_type', ['punch_in', 'punch_out'])->nullable();
$table->text('supplement_punch_content')->nullable();
$table->text('supplement_punch_at')->nullable();
$table->unsignedBigInteger('approver_id')->nullable();

$table->unsignedInteger('work_duration')->default(0);
$table->json('hash_transaction');
$table->timestamps();

生成日历

  1. HTML 模版看另外一个帖子 TailwindCSS日历模版

  2. PHP 生成日历

设计思路: 按月进行查看,前端默认 0 月既当月。 通过 Carbon 进行时间计算


$now = now()->addMonths($request->input('month', 0));

$calendar = new Calendar($now->year, $now->month);

class Calendar {
    const CALENDAR_WEEKS = 6;

    public function __construct(public int $year, public int $month) {}


    public function title() : string
    {
        return ucfirst($this->firstDayOfMonth()->translatedFormat('F \'y'));
    }

    public function calendarDays() : array
    {
        $results = [];

        $dateCursor = $this->firstDayOfCalendar();


        for($i = 0; $i < 35; $i++) {
            $results[] = [
                'date' => $dateCursor->toDateString(),
                'events' => [
                    // ... 上班的记录啦~~~上下午补卡~~
                ]
            ]

            $dateCursor = $dateCursor->addDay();
        }

        return $results;
    }

    protected function firstDayOfMonth() : Carbon
    {
        return Carbon::createFromFormat('Y-m-d', $this->year.'-'.$this->month.'-1');
    }

    protected function firstDayOfCalendar(): Carbon
    {
        $firstOfMonth = $this->firstDayOfMonth();

        return $firstOfMonth->subDays($firstOfMonth->dayOfWeekIso - $this->weekStartsOn);
    }

    protected function lastDayOfCalendar(): Carbon
    {
        return $this->firstDayOfCalendar()->addDays(7 * self::CALENDAR_WEEKS);
    }

}
Mujin
Mumujin
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 9

节假日,调休怎么做啊

1年前 评论
Mumujin (楼主) 1年前
打不死的小强 1年前
她来听我的演唱会 1年前
buyucoder 1年前

申请个钉钉帐号,然后用laravel仿一套出来就行了,不用特别的去设计,什么调休,节假日余额假,请假计算啥的,仿排班制设置,固定班制,自由班制,考勤组,定位打卡啥的,都有试例的,基本上购用了,

1年前 评论
Mumujin (楼主) 1年前
xini2603 (作者) 1年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!