
<?php namespace App\Controllers;
use App\Models\AttendanceModel;

class Employee extends BaseController {
    public function dashboard() {
        return view('employee_dashboard',[
            'records'=>(new AttendanceModel())->where('user_id',session('id'))->findAll()
        ]);
    }
    public function punch() {
        $m=new AttendanceModel(); $d=date('Y-m-d');
        $r=$m->where('user_id',session('id'))->where('created_at',$d)->first();
        if(!$r){
            $m->insert(['user_id'=>session('id'),'punch_in'=>date('Y-m-d H:i:s'),
            'work_mode'=>$this->request->getPost('mode'),'created_at'=>$d]);
        } else { $m->update($r['id'],['punch_out'=>date('Y-m-d H:i:s')]); }
        return redirect()->back();
    }
}
