<?php
defined('BASEPATH') or exit('No direct script access allowed');

class ControllerKPIMarketing extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        //validasi jika user belum login
        check_not_login();
        if ($this->session->userdata('level') != 2) {
            redirect();
        }
        $this->set_timezone();
        $this->load->library('encrypt');
        $this->load->library('form_validation');
        $this->load->library('Mycustom');
        $this->load->library('pdfgenerator');
        $this->load->library('Notifikasi');
        $this->load->model('bagian_manager/insert_model');
        $this->load->model('bagian_manager/select_model');
        $this->load->model('bagian_manager/update_model');
    }
    public function set_timezone()
    {
        date_default_timezone_set("Asia/Jakarta");
    }
    public function index()
    {
        // Data Login
        $data_login            = $this->userlogin->user_login();
        $data_id_login         = $this->session->userdata('isloggedin');
        $notif                 = $this->notifikasi->notif_manager();
        // Data Komponen dan Faktor
        $komp_faktor           = $this->select_model->vd_KompFaktor();
        $komponen              = $this->db->get_where('k_komp', ['tgt' => 'MARKETING', 'sts_komp' => 'AKTIF'])->result();
        $persentase            = $this->select_model->vd_persentaseKompFaktor();
        // echo '<pre>';
        // var_dump($persentase);
        // die;
        $data = array(
            // Untuk memanggil halaman sesuai menu
            'folder'              => 'sistem/kpi_marketing',
            'page'                => 'index',
            'judul'               => 'Kelola Data KPI Marketing || Bagian Manager',
            'data_id_login'       => $data_id_login,
            'data_login'          => $data_login,
            'notif'               => $notif,
            // Data Nilai Komponen Faktor
            'komponen'            => $komponen,
            'komp_faktor'         => $komp_faktor,
            'persentase'          => $persentase
        );
        $this->load->view('manager/index', $data);
    }
    public function target($id)
    {
        $faktor_id = $this->encrypt->decode($id);
        // echo '<pre>';
        // var_dump($faktor_id);
        // die;
        // Data Login
        $data_login            = $this->userlogin->user_login();
        $data_id_login         = $this->session->userdata('isloggedin');
        $notif                 = $this->notifikasi->notif_manager();
        // Data Komponen dan Faktor
        $komp_faktor           = $this->select_model->vd_KompFaktor();
        $persentase            = $this->select_model->vd_persentaseKompFaktor();
        // Data Target Anggota
        $data_faktor           = $this->db->get_where('k_faktor', ['id' => $faktor_id])->row_array();
        $data_komponen         = $this->db->get_where('k_komp', ['id' => $data_faktor['komp_id']])->row_array();
        $data_target           = $this->select_model->vd_marketingKPITarget($faktor_id);
        // Data Marketing
        $data_marketing        = $this->select_model->vd_marketingAktfNew();
        // marketing KPI
        // echo '<pre>';
        // var_dump($data_target);
        // die;
        $data = array(
            // Untuk memanggil halaman sesuai menu
            'folder'              => 'sistem/dkpi_marketing',
            'page'                => 'index',
            'judul'               => 'Kelola Data KPI Marketing || Bagian Manager',
            'data_id_login'       => $data_id_login,
            'data_login'          => $data_login,
            'notif'               => $notif,
            'data_marketing'      => $data_marketing,
            // Data Nilai Komponen Faktor
            'faktor'              => $data_faktor,
            'komponen'            => $data_komponen,
            'komp_faktor'         => $komp_faktor,
            'persentase'          => $persentase,
            'target'              => $data_target
        );
        $this->load->view('manager/index', $data);
    }
    public function crud()
    {
        // Tambah Komponen KPI
        if (isset($_POST['simpanKomponen'])) :
            // Konfirmasi apakah komponen Utama atau tambahan
            if (htmlspecialchars($this->input->post('komp_status')) == 'PILIH') :
                $input_komponen = array(
                    'nm_komp'      => htmlspecialchars($this->input->post('nm_komp')),
                    'ket_komp'     => htmlspecialchars($this->input->post('ket_komp')),
                    'pers_komp'    => htmlspecialchars($this->input->post('pers_komp')),
                    'sts_komp'     => 'AKTIF',
                    'tgt'          => 'MARKETING',
                    'created_at'   => date('Y-m-d H:i:s')
                );
                // Cek apakah komponen sudah penuh atau belum
                $komponen          = $this->select_model->vd_persentaseKompFaktor();
                $jml_persen        = $komponen['jml_persentase'] + $input_komponen['pers_komp'];
                if ($jml_persen <= 100) :
                    $pers_komp = htmlspecialchars($this->input->post('pers_komp'));
                    if ($pers_komp <= $input_komponen['pers_komp']) :
                        // Data Faktor
                        $this->db->insert('k_komp', $input_komponen);
                        $komp_baru = $this->db->get_where('k_komp', ['created_at' => $input_komponen['created_at']])->row_array();
                        $input_faktor = array(
                            'komp_id'      => $komp_baru['id'],
                            'nm_faktor'    => htmlspecialchars($this->input->post('nm_komp')),
                            'ket_faktor'   => htmlspecialchars($this->input->post('ket_komp')),
                            'pers_faktor'  => $pers_komp,
                            'sts_faktor'   => 'AKTIF'
                        );
                        $this->db->insert('k_faktor', $input_faktor);
                        $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil aktif data faktor KPI!</div>');
                        redirect('manager/sistem/kpi_marketing/');
                    else:
                        $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Faktor Terlalu Besar!</div>');
                        redirect('manager/sistem/kpi_marketing/');
                    endif;
                else:
                    $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Komponen Terlalu Besar!</div>');
                    redirect('manager/sistem/kpi_marketing/');
                endif;
            else:
                $komp_id      = htmlspecialchars($this->input->post('komp_id'));
                // Cek data komponen
                $komp         = $this->db->get_where('k_komp', ['id' => $komp_id])->row_array();
                $faktor       = $this->select_model->vd_jmlPersFaktor($komp_id);
                if ($faktor['jml_faktor'] == $komp['pers_komp']) :
                    $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Komponen Sudah Penuh!</div>');
                    redirect('manager/sistem/kpi_marketing/');
                else:
                    $ttl_faktor = $faktor['jml_faktor'] + $this->input->post('pers_faktor');
                    if ($ttl_faktor > $komp['pers_komp']) :
                        $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Kontribusi Terlalu Besar!</div>');
                        redirect('manager/sistem/kpi_marketing/');
                    else:
                        $input_faktor = array(
                            'komp_id'     => $komp_id,
                            'nm_faktor'   => htmlspecialchars($this->input->post('nm_faktor')),
                            'ket_faktor'  => htmlspecialchars($this->input->post('ket_faktor')),
                            'pers_faktor' => htmlspecialchars($this->input->post('pers_faktor')),
                            'sts_faktor'  => 'AKTIF'
                        );
                        $this->db->insert('k_faktor', $input_faktor);
                        $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil tambah data komponen dan faktor KPI!</div>');
                        redirect('manager/sistem/kpi_marketing/');
                    endif;
                endif;
            endif;
        endif;
        // Hapus Faktor KPI
        if (isset($_POST['aktifKPIFaktor'])) :
            $komp_id      = htmlspecialchars($this->input->post('komp_id'));
            $faktor_id    = htmlspecialchars($this->input->post('faktor_id'));
            $persen_baru  = htmlspecialchars($this->input->post('pers_faktor'));
            $persen_lama  = htmlspecialchars($this->input->post('persen_lama'));
            // Cek data komponen
            $komp         = $this->db->get_where('k_komp', ['id' => $komp_id])->row_array();
            $faktor       = $this->select_model->vd_jmlPersFaktor($komp_id);
            if ($faktor['jml_faktor'] == $komp['pers_komp']) :
                $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Komponen Sudah Penuh!</div>');
                redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
            else:
                $ttl_faktor = $faktor['jml_faktor'] + $persen_baru;
                if ($ttl_faktor > $komp['pers_komp']) :
                    $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persentase Kontribusi Terlalu Besar!</div>');
                    redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
                else:
                    $data_update = array(
                        'nm_faktor'   => htmlspecialchars($this->input->post('nm_faktor')),
                        'ket_faktor'  => htmlspecialchars($this->input->post('ket_faktor')),
                        'pers_faktor' => htmlspecialchars($this->input->post('pers_faktor')),
                        'sts_faktor'  => 'AKTIF',
                        'update_at'   => date('Y-m-d H:i:s')
                    );
                    $this->db->where('id', $faktor_id);
                    $this->db->update('k_faktor', $data_update);
                    $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil aktif data faktor KPI!</div>');
                    redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
                endif;
            endif;
        endif;
        // Ubah data faktor
        if (isset($_POST['updateKPIFaktor'])) :
            $komp_id      = htmlspecialchars($this->input->post('komp_id'));
            $faktor_id    = htmlspecialchars($this->input->post('faktor_id'));
            $persen_baru  = htmlspecialchars($this->input->post('pers_faktor'));
            $persen_lama  = htmlspecialchars($this->input->post('persen_lama'));
            // Cek data komponen
            $komp         = $this->db->get_where('k_komp', ['id' => $komp_id])->row_array();
            $faktor       = $this->select_model->vd_jmlPersFaktor($komp_id);
            if ($persen_baru != $persen_lama) :
                if ($persen_baru > $persen_lama) :
                    $jml_persen = ($faktor['jml_faktor'] - $persen_lama) + $persen_baru;
                    if ($jml_persen > $komp['pers_komp']) :
                        $this->session->set_flashdata('pesan_gagal', '<div class="alert alert-danger" id="pesan_gagal" role="alert">Persen Kontribusi Terlalu Besar!</div>');
                        redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
                    else:
                        $data_update = array(
                            'nm_faktor'   => htmlspecialchars($this->input->post('nm_faktor')),
                            'ket_faktor'  => htmlspecialchars($this->input->post('ket_faktor')),
                            'pers_faktor' => htmlspecialchars($this->input->post('pers_faktor')),
                            'update_at'   => date('Y-m-d H:i:s')
                        );
                        $this->db->where('id', $faktor_id);
                        $this->db->update('k_faktor', $data_update);
                        $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil merubah data faktor KPI!</div>');
                        redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
                    endif;
                else:
                    $data_update = array(
                        'nm_faktor'   => htmlspecialchars($this->input->post('nm_faktor')),
                        'ket_faktor'  => htmlspecialchars($this->input->post('ket_faktor')),
                        'pers_faktor' => htmlspecialchars($this->input->post('pers_faktor')),
                        'update_at'   => date('Y-m-d H:i:s')
                    );
                    $this->db->where('id', $faktor_id);
                    $this->db->update('k_faktor', $data_update);
                    $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil merubah data faktor KPI!</div>');
                    redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
                endif;
            else:
                $data_update = array(
                    'nm_faktor'   => htmlspecialchars($this->input->post('nm_faktor')),
                    'ket_faktor'  => htmlspecialchars($this->input->post('ket_faktor')),
                    'update_at'   => date('Y-m-d H:i:s')
                );
                $this->db->where('id', $faktor_id);
                $this->db->update('k_faktor', $data_update);
                $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil merubah data faktor KPI!</div>');
                redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode($faktor_id));
            endif;
        endif;
        // Hapus Faktor KPI
        if (isset($_POST['hapusKPIFaktor'])) :
            $data_update = array(
                'sts_faktor' => 'HAPUS',
                'update_at'  => date('Y-m-d H:i:s')
            );
            $this->db->where('id', htmlspecialchars($this->input->post('faktor_id')));
            $this->db->update('k_faktor', $data_update);
            $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Berhasil hapus data faktor KPI!</div>');
            redirect('manager/sistem/kpi_marketing/target_marketing/' . $this->encrypt->encode(htmlspecialchars($this->input->post('faktor_id'))));
        endif;
    }
    // Update Data Nilai KPI
    public function kpi_update($id)
    {
        $hasil_id     = $this->encrypt->decode($id);
        $hasil        = $this->db->get_where('k_hasil', ['id' => $hasil_id])->row_array();
        $bulan        = date('m', strtotime($hasil['bln_kpi']));
        $tahun        = date('Y', strtotime($hasil['bln_kpi']));
        // $bulan        = '09';
        // $tahun        = 2024;
        $marketing_id = $hasil['login_id'];
        // Realisasi Bulan ini Individu
        $ttl_realisasi = $this->select_model->vd_totalJmlRealisasi($marketing_id, $bulan, $tahun);
        if ($ttl_realisasi['jml_realisasi'] == null) :
            $jml_realisasi = 0;
        else:
            $jml_realisasi = $ttl_realisasi['jml_realisasi'];
        endif;
        // Realisasi Bulan ini Devisi
        $ttl_realisasi_devisi1 = $this->select_model->vd_totalJmlRealisasiDevisi1($bulan, $tahun);
        $ttl_realisasi_devisi2 = $this->select_model->vd_totalJmlRealisasiDevisi2($bulan, $tahun);
        $ttl_realisasi_devisinew = $ttl_realisasi_devisi1['jml_realisasi'] + $ttl_realisasi_devisi2['jml_realisasi'];
        if ($ttl_realisasi_devisinew == null) :
            $realisasi_devisi = 0;
        else:
            $realisasi_devisi = $ttl_realisasi_devisinew;
        endif;
        // Storting Bulan ini
        $ttl_storting = $this->select_model->vd_totalJmlStorting($marketing_id, $bulan, $tahun);
        if ($ttl_storting['jml_storting'] == null) :
            $jml_storting = 0;
        else:
            $jml_storting = $ttl_storting['jml_storting'];
        endif;
        // Storting Bulan ini Devisi
        $ttl_storting_devisi1 = $this->select_model->vd_totalJmlStortingDevisi1($bulan, $tahun);
        $ttl_storting_devisi2 = $this->select_model->vd_totalJmlStortingDevisi2($bulan, $tahun);
        $ttl_storting_devisi = $ttl_storting_devisi1['jml_storting'] + $ttl_storting_devisi2['jml_storting'];
        if ($ttl_storting_devisi == null) :
            $storting_devisi = 0;
        else:
            $storting_devisi = $ttl_storting_devisi;
        endif;
        // Target Individu bulanan
        // Data Individu Realisasi
        $di_realisasi = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'sts_target' => 'AKTIF', 'faktor_id' => 1])->row_array();
        $data_faktor1 = $this->db->get_where('k_faktor', ['id' => 1])->row_array();
        $nir          = ((($jml_realisasi / $di_realisasi['tgt_kinerja']) * $data_faktor1['pers_faktor']) / 100) * 100;
        // Data Individu Storting
        $di_storting  = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'sts_target' => 'AKTIF', 'faktor_id' => 2])->row_array();
        $data_faktor2 = $this->db->get_where('k_faktor', ['id' => 2])->row_array();
        $nis          = ((($jml_storting / $di_storting['tgt_kinerja']) * $data_faktor2['pers_faktor']) / 100) * 100;
        // Target Devisi bulanan
        // Data Devisi Realisasi
        $dd_realisasi = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'sts_target' => 'AKTIF', 'faktor_id' => 3])->row_array();
        $data_faktor3 = $this->db->get_where('k_faktor', ['id' => 3])->row_array();
        $ndr          = ((($realisasi_devisi / $dd_realisasi['tgt_kinerja']) * $data_faktor3['pers_faktor']) / 100) * 100;
        // Data Devisi Storting
        $dd_storting  = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'sts_target' => 'AKTIF', 'faktor_id' => 5])->row_array();
        $data_faktor4 = $this->db->get_where('k_faktor', ['id' => 5])->row_array();
        $nds          = ((($storting_devisi / $dd_storting['tgt_kinerja']) * $data_faktor4['pers_faktor']) / 100) * 100;
        // Target Kedisiplinan
        // Data Disiplin
        $d_disiplin   = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'faktor_id' => 7, 'sts_target' => 'AKTIF'])->row_array();
        $data_faktor5 = $this->db->get_where('k_faktor', ['id' => 7])->row_array();
        $nilai_disiplin = $this->db->get_where('k_disiplin', ['login_id' => $marketing_id, 'MONTH(tgl_laporan)' => $bulan, 'YEAR(tgl_laporan)' => $tahun])->row_array();
        if ($nilai_disiplin == null) :
            $ttl_menit = '10800';
        else:
            $ttl_menit = $nilai_disiplin['absensi_menit'];
        endif;
        $nilai_disiplin = ((($ttl_menit / $d_disiplin['tgt_kinerja']) * $data_faktor5['pers_faktor']) / 100) * 100;
        // Data Review
        $d_reviews     = $this->db->get_where('k_target', ['login_id' => $marketing_id, 'faktor_id' => 8, 'sts_target' => 'AKTIF'])->row_array();
        $data_faktor6  = $this->db->get_where('k_faktor', ['id' => 8])->row_array();
        $jml_reviews   = count($this->db->get_where('k_rkonsumen', ['login_id' => $marketing_id, 'MONTH(tgl_review)' => $bulan, 'YEAR(tgl_review)' => $tahun])->result());
        $ttl_bintang   = $this->select_model->vd_bintangReviewsPelanggan($marketing_id, $bulan, $tahun);
        if ($jml_reviews == null) :
            $reviews_nilai = 0;
            $nilai_reviews = 0;
        else:
            $reviews_nilai = $ttl_bintang['rate_bintang'] / $jml_reviews;
            $nilai_reviews = (((($ttl_bintang['rate_bintang'] / $jml_reviews) / $d_reviews['tgt_kinerja']) * $data_faktor6['pers_faktor']) / 100) * 100;
        endif;
        $nilai_angka = round((($nir + $nis) + ($ndr + $nds) + $nilai_disiplin + $nilai_reviews), 2);
        if ($nilai_angka > 95) :
            $nilai_huruf = 'S+';
        elseif ($nilai_angka >= 91):
            $nilai_huruf = 'S';
        elseif ($nilai_angka >= 86):
            $nilai_huruf = 'A+';
        elseif ($nilai_angka >= 81):
            $nilai_huruf = 'A';
        elseif ($nilai_angka >= 76):
            $nilai_huruf = 'B+';
        elseif ($nilai_angka >= 71):
            $nilai_huruf = 'B';
        elseif ($nilai_angka >= 61):
            $nilai_huruf = 'C';
        elseif ($nilai_angka >= 51):
            $nilai_huruf = 'D';
        elseif ($nilai_angka <= 50):
            $nilai_huruf = 'E';
        endif;
        $bulan_now = date('m');
        if ($bulan == $bulan_now) :
            $sts_hasil = 'PROSES';
        else:
            $sts_hasil = 'SELESAI';
        endif;
        $data_hasil = array(
            'nilai_angka' => $nilai_angka,
            'nilai_huruf' => $nilai_huruf,
            'sts_hasil'   => $sts_hasil,
            'updated_at'  => date('Y-m-d H:i:s')
        );
        $this->db->where('id', $hasil['id']);
        $this->db->update('k_hasil', $data_hasil);
        $this->db->where('hasil_id', $hasil['id']);
        $this->db->delete('k_dhasil');
        // Detail Nilai Realisasi Individu
        $data_dhasil_1 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 1,
            'target'      => $di_realisasi['tgt_kinerja'],
            'realisasi'   => $jml_realisasi,
            'persentase'  => $data_faktor1['pers_faktor'],
            'nilai'       => $nir
        );
        $this->db->insert('k_dhasil', $data_dhasil_1);
        // Detail Nilai Storting Individu
        $data_dhasil_2 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 2,
            'target'      => $di_storting['tgt_kinerja'],
            'realisasi'   => $jml_storting,
            'persentase'  => $data_faktor2['pers_faktor'],
            'nilai'       => $nis
        );
        $this->db->insert('k_dhasil', $data_dhasil_2);
        // Detail Nilai Realisasi Devisi
        $data_dhasil_3 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 3,
            'target'      => $dd_realisasi['tgt_kinerja'],
            'realisasi'   => $realisasi_devisi,
            'persentase'  => $data_faktor3['pers_faktor'],
            'nilai'       => $ndr
        );
        $this->db->insert('k_dhasil', $data_dhasil_3);
        // Detail Nilai Storting Devisi
        $data_dhasil_4 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 5,
            'target'      => $dd_storting['tgt_kinerja'],
            'realisasi'   => $storting_devisi,
            'persentase'  => $data_faktor4['pers_faktor'],
            'nilai'       => $nds
        );
        $this->db->insert('k_dhasil', $data_dhasil_4);
        // Detail Nilai Kedisiplinan
        $data_dhasil_5 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 7,
            'target'      => $d_disiplin['tgt_kinerja'],
            'realisasi'   => $ttl_menit,
            'persentase'  => $data_faktor5['pers_faktor'],
            'nilai'       => $nilai_disiplin
        );
        $this->db->insert('k_dhasil', $data_dhasil_5);
        // Detail Nilai Review Konsumen
        $data_dhasil_6 = array(
            'hasil_id'    => $hasil['id'],
            'faktor_id'   => 8,
            'target'      => $d_reviews['tgt_kinerja'],
            'realisasi'   => $reviews_nilai,
            'persentase'  => $data_faktor6['pers_faktor'],
            'nilai'       => $nilai_reviews
        );
        $this->db->insert('k_dhasil', $data_dhasil_6);
        $this->session->set_flashdata('pesan_berhasil', '<div class="alert alert-success" id="pesan_berhasil" role="alert">Nilai KPI Berhasil di Update!</div>');
        redirect('manager/identitas/karyawan/' . $this->encrypt->encode($marketing_id));
    }
    // Detail KPI Marketing
    public function detail_kpi($id)
    {
        $hasil_id = $this->encrypt->decode($id);
        // Data Login
        $data_login            = $this->userlogin->user_login();
        $data_id_login         = $this->session->userdata('isloggedin');
        $notif                 = $this->notifikasi->notif_manager();
        // Data Detail KPI
        $kpi_detail            = $this->select_model->vd_detKPIMarketing($hasil_id);
        $kpi                   = $this->db->get_where('k_hasil', ['id' => $hasil_id])->row_array();
        $login_marketing       = $this->db->get_where('sistem_login', ['id' => $kpi['login_id']])->row_array();
        $identitas_marketing   = $this->db->get_where('sistem_identitas', ['login_id' => $kpi['login_id']])->row_array();
        // Data Marketing
        // marketing KPI
        $data = array(
            // Untuk memanggil halaman sesuai menu
            'folder'              => 'sistem/kpi_detail',
            'page'                => 'index',
            'judul'               => 'Detail KPI Marketing || Bagian Manager',
            'data_id_login'       => $data_id_login,
            'data_login'          => $data_login,
            'notif'               => $notif,
            // Data Nilai Komponen Faktor
            'data_kpi'            => $kpi,
            'marketing'           => $login_marketing,
            'identitas_marketing' => $identitas_marketing,
            'detail_kpi'          => $kpi_detail
        );
        $this->load->view('manager/index', $data);
    }
}

/* End of file ControllerKPIMarketing.php and path \application\controllers\manager\sistem\ControllerKPIMarketing.php */