<br />
<b>Warning</b>:  Undefined variable $auth in <b>/home/pevo0181/public_html/pia-soft.com/cleania/routes/index.php</b> on line <b>542</b><br />
<br />
<b>Warning</b>:  Trying to access array offset on value of type null in <b>/home/pevo0181/public_html/pia-soft.com/cleania/routes/index.php</b> on line <b>542</b><br />
<?php

namespace App\Models;

use App\Models\Matiere;
use App\Models\SousMatiere;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Note extends Model
{
    use HasFactory;

    protected $table = 'notes';
    protected $primaryKey = 'note_id';

    public $timestamps = false;
    protected $fillable = [
        'usr_id',
        'class_id',
        'competence_id',
        'mat_id',
        'note_mat_max',
        'moy_mat_max',
        'div_group_mat',
        's_mat_id',
        'note_s_mat_max',
        'note_s_mat_usr',
        'trim_id',
        'appreciable',
        'class_session',
        'class_cycle',
        'note_annee',
        'ad_id',
        'note_date'
    ];

    protected $casts = [
        'note_s_mat_max' => 'decimal:2',
        'note_date' => 'date'
    ];

    public function student()
    {
        return $this->belongsTo(User::class, 'usr_id');
    }

    public function matiere()
    {
        return $this->belongsTo(Matiere::class, 'mat_id', 'mat_id');
    }

    public function sousMatiere()
    {
        return $this->belongsTo(SousMatiere::class, 's_mat_id', 's_mat_id');
    }

    public function competence()
    {
        return $this->belongsTo(Competence::class, 'competence_id', 'competence_id');
    }

    
    public function scopeForStudent($query, $studentId, $classId, $year = null)
    {
        return $query->where('usr_id', $studentId)
                    ->where('class_id', $classId)
                    ->where('note_annee', $year ?? getLastYear());
    }

    public function scopeForStudentSequence($query, $studentId, $classId,$sequence_id, $year = null)
    {
        re