db = \Config\Database::connect(); $this->request = \Config\Services::request(); } protected $table = 'surat'; protected $primaryKey = 'id_surat'; protected $returnType = 'object'; protected $allowedFields = ['id_surat', 'nip', 'jenis_surat', 'jabatan', 'tanggal', 'keterangan_surat', 'lampiran']; public function getSurat($nip) { return $this->db->table('surat') ->join('guru', 'surat.nip = guru.nip') ->where([ 'surat.nip' => $nip, ]) ->get() ->getResult(); } public function getSuratAll() { return $this->db->table('surat') ->join('guru', 'surat.nip = guru.nip')->get()->getResult(); } public function insert_surat($data) { return $this->db->table($this->table)->insert($data); } public function getById($id) { return $this->where(['id_surat' => $id])->get(); } public function getRekapTugas($nip) { $builder = $this->db->table($this->table); $currentDate = date('Y-m-d'); $threeMonthsAgo = date('Y-m-d', strtotime('-3 months')); return $this->db->table('surat') ->join('guru', 'surat.nip = guru.nip') ->where('jenis_surat', 1) ->where('surat.nip', $nip) ->where('tanggal >=', $threeMonthsAgo) ->where('tanggal <=', $currentDate) ->get() ->getResult(); } public function getRekapPanitia($nip) { $currentDate = date('Y-m-d'); $threeMonthsAgo = date('Y-m-d', strtotime('-3 months')); return $this->db->table('surat') ->join('guru', 'surat.nip = guru.nip') ->where('jenis_surat', 2) ->where('surat.nip', $nip) ->where('tanggal >=', $threeMonthsAgo) ->where('tanggal <=', $currentDate) ->get() ->getResult(); } }