%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/hr/api/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/hr/api/app/Models/Day.php

<?php

namespace App\Models;

use Carbon\Carbon;

/**
 * @property integer id
 * @property string code
 * @property string name
 */
class Day extends BaseModel
{
    public $timestamps = false;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'code',
        'name',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id'   => 'integer',
        'code' => 'string',
        'name' => 'string',
    ];

    public static function getNextWorkingDay($date)
    {
        if (!$date) {
            $date = Carbon::now();
        } else {
            $date = Carbon::parse($date);
        }
        $date = $date->addDay();
        if (self::isWorkingDay($date)) {
            return $date;
        }
        return self::getNextWorkingDay($date);
    }

    public static function isWorkingDay($date = null)
    {
        if (!$date) {
            $date = Carbon::now();
        } else {
            $date = Carbon::parse($date);
        }
        $day = self::getDayByCode($date->dayOfWeekIso);

        return WorkingDay::query()
                         ->where('day_id', $day->id)
                         ->where('valid_from', '<=', $date)
                         ->where(function ($q) use ($date) {
                             $q->whereNull('valid_to');
                             $q->orWhere('valid_to', '>=', $date);
                         })
                         ->exists();
    }

    public static function getDayByCode($code)
    {
        return self::query()
                   ->where('code', $code)
                   ->first();
    }

}

Zerion Mini Shell 1.0