<?php 

namespace App\Models;
use CodeIgniter\Model;

class AttendanceModel extends Model {
    protected $table = 'attendance';
    protected $primaryKey = 'id';
    protected $allowedFields = ['user_id', 'punch_in', 'punch_out', 'work_mode', 'attendance_date', 'created_at', 'updated_at'];
    public function getAllByUser($user_id = null) {
        $builder = $this->select('attendance.*, users.name')
                        ->join('users', 'users.id = attendance.user_id');

        if ($user_id) {
            $builder->where('attendance.user_id', $user_id);
        }

        return $builder->orderBy('attendance.attendance_date', 'DESC')->findAll();
    }


     public function getAll()
    {
 return $this->select('attendance.*, users.name')
                ->join('users', 'users.id = attendance.user_id', 'left')
                ->findAll();    }


}
