82 lines
2.0 KiB
PHP
82 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use Codeigniter\HTTP\RequestInterface;
|
|
|
|
class ModelAbsensi extends Model
|
|
{
|
|
|
|
protected $db;
|
|
protected $request;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->db = \Config\Database::connect();
|
|
$this->request = \Config\Services::request();
|
|
}
|
|
|
|
protected $table = 'absensi';
|
|
protected $primaryKey = 'id_absensi';
|
|
protected $returnType = 'object';
|
|
protected $allowedFields = ['id_absensi', 'bulan', 'tahun', 'nip', 'nama', 'sakit', 'ijin', 'alpa', 'cuti', 'total_kehadiran', 'total_kerja'];
|
|
|
|
public function getAbsensi()
|
|
{
|
|
return $this->get()->getResult();
|
|
}
|
|
|
|
public function insert_absensi($data)
|
|
{
|
|
return $this->db->table($this->table)->insert($data);
|
|
}
|
|
|
|
public function getById($id)
|
|
{
|
|
return $this->where(['id_absensi' => $id])->get();
|
|
}
|
|
|
|
public function getByBulanTahun($bulan, $tahun, $nip)
|
|
{
|
|
return $this->where([
|
|
'bulan' => $bulan,
|
|
'tahun' => $tahun,
|
|
'nip' => $nip
|
|
])->get()->getResult();
|
|
}
|
|
public function getAbsensiTahun($nip, $selectedYear = null)
|
|
{
|
|
$builder = $this->db->table('absensi');
|
|
|
|
if (!empty($selectedYear)) {
|
|
$builder->where([
|
|
'nip' => $nip,
|
|
'tahun' => $selectedYear
|
|
]);
|
|
}else{
|
|
$selectedYear = date('Y'); // Mengambil tahun sekarang
|
|
$builder->where([
|
|
'nip' => $nip,
|
|
'tahun' => $selectedYear
|
|
]);
|
|
}
|
|
|
|
return $builder->get()->getResult();
|
|
}
|
|
|
|
public function getRekapAbsensi($bulan, $tahun, $nip)
|
|
{
|
|
$builder = $this->db->table($this->table);
|
|
$builder->select('*')
|
|
->where('nip', $nip)
|
|
->where('tahun', $tahun)
|
|
->where('bulan >=', $bulan - 2)
|
|
->where('bulan <=', $bulan)
|
|
->orderBy('bulan', 'ASC');
|
|
|
|
return $builder->get()->getResult();
|
|
}
|
|
|
|
|
|
} |