<?php defined('BASEPATH') or exit('No direct script access allowed');
// created by : KuduSinau_Hendrik_081275532220 (TERIMAKASIH UNTUK MENDAPATKAN KEBERKAHAN, DENGAN TIDAK MERUBAH NAMA HAK CIPTA, PLAGIAT, DAN TIDAK MEMPERJUALBELIKAN APLIKASI INI, SEMOGA KITA SEMUA MENDAPAT MANFAAT DAN KEBERKAHAN DARI APLIKASI INI)
// created by : KuduSinau_Hendrik_081275532220 (UNTUK MASUKAN DAN SARAN SERTA PENGEMBANGAN BISA MENGHUBUNGI NOMOR)
class M_walas extends CI_Model
{
    // START VIEW DATA ==============================================================================================
    public function viewDataWalasGuru()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.nm_kelas as tingkat, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_teachers.id_teachers as kdguru
        ');
        $this->db->from('t_teachers');
        $this->db->join('t_walas', 't_walas.kd_teachers = t_teachers.id_teachers', 'left');
        $this->db->join('t_kelas', 't_walas.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->order_by('t_kelas.nm_rombel', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataWalasSiswa()
    {
        $this->db->select(' t_kelas.nm_kelas as tingkat, 
                            t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn,
                            t_walas.kd_lembaga as kdlbg,
                            t_students.status_lulus as lulus
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataCatatanSiswa()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn, 
                            t_catatan.nm_catatan as catat
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        $this->db->join('t_catatan', 't_catatan.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataPrestasiSiswa()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn, 
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        // $this->db->join('t_prestasi', 't_prestasi.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataEskulSiswa()
    {
        $this->db->select(' t_eskul.nm_eskul as eskul,
                            t_nilaieskul.predikat_eskul as predikat,
                            t_nilaieskul.deskripsi_eskul as deskripsi,
                            t_nilaieskul.kd_students as kdsiswa,
                            t_nilaieskul.kd_kelas as kdkelas,
                            t_nilaieskul.id_nilaieskul as ideskul,
                            t_nilaieskul.tipe_n as kdeskul,
                            t_nilaieskul.kd_tapel as kdtapel,                           
                            t_nilaieskul.kd_lembaga as kdlbg
        ');
        $this->db->from('t_nilaieskul');
        $this->db->join('t_eskul', 't_eskul.id_eskul = t_nilaieskul.kd_eskul', 'right');
        $this->db->order_by('t_eskul.nm_eskul', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataAbsensiSiswa()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn, 
                            t_absensi.s_absensi as s, 
                            t_absensi.i_absensi as i, 
                            t_absensi.a_absensi as a, 
                            t_absensi.tipe_absensi as tipe
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        $this->db->join('t_absensi', 't_absensi.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataNaikSiswaOld()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn, 
                            t_kls.nm_kls as nmkls, 
                            t_kls.angka_kls as angkakls, 
                            t_kls.huruf_kls as hurufkls, 
                            t_naik.ket_naik as ketnaik, 
                            t_naik.kelas_naik as klsnaik
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        $this->db->join('t_kls', 't_kls.nm_kls = t_kelas.nm_kelas', 'right');
        $this->db->join('t_naik', 't_naik.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        //$this->db->join('t_lulus', 't_naik.ket_naik = t_lulus.nm_lulus', 'left');
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
    }
    public function viewDataNaikSiswa()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn, 
                            t_naik.ket_naik as ketnaik, 
                            t_naik.kelas_naik as klsnaik
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        //$this->db->join('t_kls', 't_kls.nm_kls = t_kelas.nm_kelas', 'right');
        $this->db->join('t_naik', 't_naik.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        //$this->db->join('t_lulus', 't_naik.ket_naik = t_lulus.nm_lulus', 'left');
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataNomorUm()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn,
                            t_students.no_um as noUm
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        //$this->db->join('t_kls', 't_kls.nm_kls = t_kelas.nm_kelas', 'right');
        // $this->db->join('t_naik', 't_naik.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        //$this->db->join('t_lulus', 't_naik.ket_naik = t_lulus.nm_lulus', 'left');
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function viewDataNomorIjazah()
    {
        $this->db->select(' t_kelas.nm_rombel as kelas, 
                            t_kelas.id_kelas as kdkelas, 
                            t_walas.id_walas as idw, 
                            t_walas.kd_lembaga as kdlbg, 
                            t_walas.kd_tapel as kdtapel, 
                            t_students.id_students as kdsiswa, 
                            t_students.nm_students as siswa, 
                            t_students.nisn_students as nisn,
                            t_students.status_lulus as stsLulus,
                            t_alumni.no_ijazah as noIjazah,
                            t_alumni.tgl_terima_ijazah as tglTerimaIjazah
        ');
        $this->db->from('t_students');
        $this->db->join('t_rombelsiswa', 't_rombelsiswa.kd_students = t_students.id_students', 'left');
        $this->db->join('t_kelas', 't_rombelsiswa.kd_kelas = t_kelas.id_kelas', 'left');
        $this->db->join('t_walas', 't_walas.kd_kelas = t_kelas.id_kelas', 'right');
        //$this->db->join('t_kls', 't_kls.nm_kls = t_kelas.nm_kelas', 'right');
        $this->db->join('t_alumni', 't_alumni.kd_students = t_students.id_students', 'left');
        $this->db->order_by('t_students.nm_students', SORT_ASC);
        //$this->db->join('t_lulus', 't_naik.ket_naik = t_lulus.nm_lulus', 'left');
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    // END VIEW DATA ==============================================================================================


    // START CRUD DATA ==============================================================================================
    public function deleteDataEskul($idEskul)
    {
        $query = $this->db->delete("t_nilaieskul", $idEskul);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataEskul($data, $idEskul)
    {
        $query = $this->db->update("t_nilaieskul", $data, $idEskul);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiPrestasi($data, $idPrestasi)
    {
        $query = $this->db->update("t_prestasi", $data, $idPrestasi);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function deleteDataPrestasi($idPrestasi)
    {
        $query = $this->db->delete("t_prestasi", $idPrestasi);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiSo($data)
    {
        $query = $this->db->insert_batch('t_nilaisso', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiSo($data, $rs)
    {
        $query = $this->db->update_batch("t_nilaisso", $data, $rs);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiAkhirSo($dt)
    {
        $query = $this->db->insert('t_akhirso', $dt);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiAkhirSo($dt, $newIdakhirSo)
    {

        $query = $this->db->update('t_akhirso', $dt, $newIdakhirSo);

        if ($query) {
            return true;
        } else {
            return false;
        }
    }
    public function inputDataNilaiSp($data)
    {
        $query = $this->db->insert_batch('t_nilaissp', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiSp($data, $rs)
    {
        $query = $this->db->update_batch("t_nilaissp", $data, $rs);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiAkhirSp($dt)
    {
        $query = $this->db->insert('t_akhirsp', $dt);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiAkhirSp($dt, $newIdakhirSp)
    {
        $query = $this->db->update('t_akhirsp', $dt, $newIdakhirSp);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiEskul($data)
    {
        $query = $this->db->insert('t_nilaieskul', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function updateDataNilaiEskul($data, $rs)
    {

        $query = $this->db->update("t_nilaieskul", $data, $rs);

        if ($query) {
            return true;
        } else {
            return false;
        }
    }
    public function inputDataNilaiCatatan($data)
    {
        $query = $this->db->insert('t_catatan', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiAbsensi($data)
    {
        $query = $this->db->insert('t_absensi', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiNaik($data)
    {
        $query = $this->db->insert('t_naik', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataNilaiPrestasi($data)
    {
        $query = $this->db->insert('t_prestasi', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    public function inputDataAlumni($data)
    {
        $query = $this->db->insert('t_alumni', $data);
        if ($query) {
            return true;
        } else {
            return false;
        }
        // created by : KuduSinau_Hendrik_081275532220
    }
    // END CRUD DATA ==============================================================================================
    public function date($aksi)
    {
        date_default_timezone_set('Asia/Jakarta');
        if ($aksi == 'waktu') {
            $date     = date('d-m-Y H:i:s');
        } elseif ($aksi == 'waktu_default') {
            $date     = date('Y-m-d H:i:s');
        } elseif ($aksi == 'thn') {
            $date     = date('Y');
        } elseif ($aksi == 'bln') {
            $date     = date('m');
        } elseif ($aksi == 'tgl_default') {
            $date     = date('Y-m-d');
        } elseif ($aksi == 'tgl') {
            $date     = date('d-m-Y');
        } elseif ($aksi == 'jam') {
            $date     = date('H:i:s');
        } else {
            $date  = 'Null';
        }
        return $date;
        // created by : KuduSinau_Hendrik_081275532220
    }
    public static function tgl_indo($date)
    {
        $str = explode('-', $date);
        $bulan = array(
            '01' => 'Januari',
            '02' => 'Februari',
            '03' => 'Maret',
            '04' => 'April',
            '05' => 'Mei',
            '06' => 'Juni',
            '07' => 'Juli',
            '08' => 'Agustus',
            '09' => 'September',
            '10' => 'Oktober',
            '11' => 'November',
            '12' => 'Desember',
        );
        return $str['0'] . " " . $bulan[$str[1]] . " " . $str[2];
        // created by : KuduSinau_Hendrik_081275532220
    }
    public static function bln_indo($date)
    {
        $str = explode('-', $date);
        $bulan = array(
            '01' => 'Januari',
            '02' => 'Februari',
            '03' => 'Maret',
            '04' => 'April',
            '05' => 'Mei',
            '06' => 'Juni',
            '07' => 'Juli',
            '08' => 'Agustus',
            '09' => 'September',
            '10' => 'Oktober',
            '11' => 'November',
            '12' => 'Desember',
        );
        return $bulan[$str[0]];
        // created by : KuduSinau_Hendrik_081275532220
    }
}
// created by : KuduSinau_Hendrik_081275532220 (TERIMAKASIH UNTUK MENDAPATKAN KEBERKAHAN, DENGAN TIDAK MERUBAH NAMA HAK CIPTA, PLAGIAT, DAN TIDAK MEMPERJUALBELIKAN APLIKASI INI, SEMOGA KITA SEMUA MENDAPAT MANFAAT DAN KEBERKAHAN DARI APLIKASI INI)
