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

class ControllerKPI extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $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_notif/koperasi');
        $this->set_timezone();
    }
    public function set_timezone()
    {
        date_default_timezone_set("Asia/Jakarta");
    }
    public function index()
    {
        redirect('/');
    }
    public function update_kpi($id)
    {
        $kode_verif = $this->encrypt->decode($id);
        // echo '<pre>';
        // var_dump($kode_verif, $id);
        // die;
        if ($kode_verif == 'AnakTuhan@6661') :
            $this->_updateKPIMarketing();
            $this->_notifWADevOpsBerhasil();
            $this->_cekMarketingUpdateKPI();
        else:
            $this->_notifWADevOpsGagal();
        endif;
    }
    // Kirim Notifikasi KPI Update
    // Notif WA Berhasil
    private function _notifWADevOpsBerhasil()
    {
        $sett_wa = $this->db->get_where('sistem_wa', ['id' => 1])->row_array();
        $no_hp   = $sett_wa['uji_coba'];
        $pesan = 'Update KPI Marketing ' . date('Y-m-d') . ' Berhasil di Lakukan.';
        $footer = '*KSP Bina Artha Prima*';
        $data_inputan = array(
            'api_key'    => $sett_wa['api_key'],
            'sender'     => $sett_wa['no_hp'],
            'number'     => $no_hp,
            'message'    => $pesan,
            'footer'     => $footer
        );
        $curl = curl_init($sett_wa['endpoint_url']);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data_inputan));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_exec($curl);
        curl_close($curl);
    }
    // Notif WA Gagal
    private function _notifWADevOpsGagal()
    {
        $sett_wa = $this->db->get_where('sistem_wa', ['id' => 1])->row_array();
        $no_hp   = $sett_wa['uji_coba'];;
        $pesan = 'Update KPI Marketing ' . date('Y-m-d') . ' Gagal di Lakukan / Sandi Verif Salah.';
        $footer = '*KSP Bina Artha Prima*';
        $data_inputan = array(
            'api_key'    => $sett_wa['api_key'],
            'sender'     => $sett_wa['no_hp'],
            'number'     => $no_hp,
            'message'    => $pesan,
            'footer'     => $footer
        );
        $curl = curl_init($sett_wa['endpoint_url']);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data_inputan));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_exec($curl);
        curl_close($curl);
    }
    // Update KPI
    // Marketing 
    private function _updateKPIMarketing()
    {
        // Data Marketing
        $data_marketing = $this->koperasi->vd_marketingAktif();
        // Menampilkan data Marketing
        foreach ($data_marketing as $Marketing) :
            $bulan = date('m');
            $tahun = date('Y');
            if ($bulan - 1 == 0) :
                $blnlalu = '12';
                $thnlalu = $tahun - 1;
            else:
                $blncek = $bulan - 1;
                if ($blncek >= 10) :
                    $blnlalu = $blncek;
                else:
                    $blnlalu = '0' . $blncek;
                endif;
                $thnlalu = $tahun;
            endif;
            // Cek Bulan Data yang Lalu
            $data_bulan_lalu = $this->db->get_where('k_hasil', ['login_id' => $Marketing->marketing_id, 'MONTH(bln_kpi)' => $blnlalu, 'YEAR(bln_kpi)' => $thnlalu, 'sts_hasil' => 'PROSES'])->row_array();
            // APakah bulan kemarin nilai sudah selesai atau belum
            if ($data_bulan_lalu != NULL) :
                // Nilai Bulan Kemarin belum selesai
                $hasil_id = $data_bulan_lalu['id'];
                $this->_mulaiUpdateKPI($hasil_id);
                $dblnlalu = array(
                    'sts_hasil'   => 'SELESAI',
                    'updated_at'  => date('Y-m-d H:i:s')
                );
                $this->db->where('id', $hasil_id);
                $this->db->update('k_hasil', $dblnlalu);
            endif;
            // Cek apakah bulan ini sudah ada nilai atau belum
            $data_hasilbulan = $this->db->get_where('k_hasil', ['login_id' => $Marketing->marketing_id, 'MONTH(bln_kpi)' => $bulan, 'YEAR(bln_kpi)' => $tahun])->row_array();
            if ($data_hasilbulan == null) :
                // Jika data nilai masih Null
                $data_hasilbaru = array(
                    'login_id'    => $Marketing->marketing_id,
                    'bln_kpi'     => date('Y-m-d'),
                    'nilai_angka' => 0,
                    'nilai_huruf' => 'D',
                    'sts_hasil'   => 'PROSES'
                );
                $this->db->insert('k_hasil', $data_hasilbaru);
                $data_hasilbulanbaru = $this->db->get_where('k_hasil', ['login_id' => $Marketing->marketing_id, 'MONTH(bln_kpi)' => $bulan, 'YEAR(bln_kpi)' => $tahun])->row_array();
                $hasil_id     = $data_hasilbulanbaru['id'];
                $this->_mulaiUpdateKPI($hasil_id);
            else:
                if ($data_hasilbulan['sts_hasil'] == 'PROSES'):
                    $hasil_id     = $data_hasilbulan['id'];
                    $this->_mulaiUpdateKPI($hasil_id);
                endif;
            endif;
        endforeach;
    }
    // Mulai Update KPI
    private function _mulaiUpdateKPI($hasil_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->koperasi->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->koperasi->vd_totalJmlRealisasiDevisi1($bulan, $tahun);
        $ttl_realisasi_devisi2 = $this->koperasi->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->koperasi->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->koperasi->vd_totalJmlStortingDevisi1($bulan, $tahun);
        $ttl_storting_devisi2 = $this->koperasi->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;
        if ($nir >= $data_faktor1['pers_faktor']) :
            $nilai_individu_realisasi = $data_faktor1['pers_faktor'];
        else:
            $nilai_individu_realisasi = $nir;
        endif;
        // 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;
        if ($nis >= $data_faktor2['pers_faktor']) :
            $nilai_individu_storting = $data_faktor2['pers_faktor'];
        else:
            $nilai_individu_storting = $nis;
        endif;
        // 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;
        if ($ndr >= $data_faktor3['pers_faktor']) :
            $nilai_devisi_realisasi = $data_faktor3['pers_faktor'];
        else:
            $nilai_devisi_realisasi = $ndr;
        endif;
        // 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;
        if ($nds >= $data_faktor4['pers_faktor']) :
            $nilai_devisi_storting = $data_faktor4['pers_faktor'];
        else:
            $nilai_devisi_storting = $nds;
        endif;
        // 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 = '0';
        else:
            $ttl_menit = $nilai_disiplin['absensi_menit'];
        endif;
        $nilai_disiplin2 = ((($ttl_menit / $d_disiplin['tgt_kinerja']) * $data_faktor5['pers_faktor']) / 100) * 100;
        if ($nilai_disiplin2 >= $data_faktor5['pers_faktor']) :
            $nilai_disiplin_marketing = $data_faktor5['pers_faktor'];
        else:
            $nilai_disiplin_marketing = $nilai_disiplin2;
        endif;
        // 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->koperasi->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;
        if ($nilai_reviews >= $data_faktor6['pers_faktor']) :
            $nilai_reviews_marketing = $data_faktor6['pers_faktor'];
        else:
            $nilai_reviews_marketing = $nilai_reviews;
        endif;
        // echo '<pre>';
        // var_dump($nilai_reviews);
        // die;
        $nilai_angka = round((($nilai_individu_realisasi + $nilai_individu_storting) + ($nilai_devisi_realisasi + $nilai_devisi_storting) + ($nilai_disiplin_marketing + $nilai_reviews_marketing)), 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'       => $nilai_individu_realisasi
        );
        $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'       => $nilai_individu_storting
        );
        $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'       => $nilai_devisi_realisasi
        );
        $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'       => $nilai_devisi_storting
        );
        $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_marketing
        );
        $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_marketing
        );
        $this->db->insert('k_dhasil', $data_dhasil_6);
    }
    // Notifikasi Untuk Marketing
    private function _cekMarketingUpdateKPI()
    {
        // Data Marketing
        $data_marketing = $this->koperasi->vd_marketingAktif();
        $bulan = date('m');
        $tahun = date('Y');
        if ($bulan - 1 == 0) :
            $blnlalu = '12';
            $thnlalu = $tahun - 1;
        else:
            $blncek = $bulan - 1;
            if ($blncek >= 10) :
                $blnlalu = $blncek;
            else:
                $blnlalu = '0' . $blncek;
            endif;
            $thnlalu = $tahun;
        endif;
        $blnll = $this->_cekDataBulanLalu($blnlalu);
        $blnin = $this->_cekDataBulanIni($bulan);
        foreach ($data_marketing as $Marketing) :
            // Data hasil bulan lalu
            $data_bulan_lalu        = $this->db->get_where('k_hasil', ['login_id' => $Marketing->login_id, 'MONTH(bln_kpi)' => $blnlalu, 'YEAR(bln_kpi)' => $thnlalu])->row_array();
            // Detail Hasil Bulan Lalu
            $ddhl_1                 = $this->koperasi->vd_ddhl_1($data_bulan_lalu);
            $ddhl_2                 = $this->koperasi->vd_ddhl_2($data_bulan_lalu);
            $ddhl_3                 = $this->koperasi->vd_ddhl_3($data_bulan_lalu);
            $ddhl_5                 = $this->koperasi->vd_ddhl_5($data_bulan_lalu);
            $ddhl_7                 = $this->koperasi->vd_ddhl_7($data_bulan_lalu);
            $ddhl_8                 = $this->koperasi->vd_ddhl_8($data_bulan_lalu);
            // Data hasil bulan ini
            $data_bulan             = $this->db->get_where('k_hasil', ['login_id' => $Marketing->login_id, 'MONTH(bln_kpi)' => $bulan, 'YEAR(bln_kpi)' => $tahun])->row_array();
            // Detail Hasil Bulan Lalu
            $ddhi_1                 = $this->koperasi->vd_ddhi_1($data_bulan);
            $ddhi_2                 = $this->koperasi->vd_ddhi_2($data_bulan);
            $ddhi_3                 = $this->koperasi->vd_ddhi_3($data_bulan);
            $ddhi_5                 = $this->koperasi->vd_ddhi_5($data_bulan);
            $ddhi_7                 = $this->koperasi->vd_ddhi_7($data_bulan);
            $ddhi_8                 = $this->koperasi->vd_ddhi_8($data_bulan);
            // Detail nama panggilan
            $nm_panggilan           = $Marketing->nm_panggilan;
            $no_hp                  = $Marketing->no_hp;
            $data = array(
                'nm_panggilan' => $nm_panggilan,
                'no_hp'        => $no_hp,
                'bln_lalu'     => $blnll,
                'bln_ini'      => $blnin,
                'thn_lalu'      => $thnlalu,
                'thn_ini'      => $tahun
            );
            $this->_notifWAMarketing($data, $data_bulan_lalu, $data_bulan, $ddhl_1, $ddhl_2, $ddhl_3, $ddhl_5, $ddhl_7, $ddhl_8, $ddhi_1, $ddhi_2, $ddhi_3, $ddhi_5, $ddhi_7, $ddhi_8);
        endforeach;
    }
    // WA Notif Marketing
    private function _notifWAMarketing($data, $data_bulan_lalu, $data_bulan, $ddhl_1, $ddhl_2, $ddhl_3, $ddhl_5, $ddhl_7, $ddhl_8, $ddhi_1, $ddhi_2, $ddhi_3, $ddhi_5, $ddhi_7, $ddhi_8)
    {
        $sett_wa = $this->db->get_where('sistem_wa', ['id' => 1])->row_array();
        $cek_nomor = substr($data['no_hp'], 0, 1);
        if ($cek_nomor == 0) :
            $no_hp = '62' . substr($data['no_hp'], 1, 20);
        else :
            $no_hp = $data['no_hp'];
        endif;
        $pesan = 'Halo ' . $data['nm_panggilan'] . ', dibawah ini adalah rekap Nilai KPI : 

*_' . $data['bln_lalu'] . ' ' . $data['thn_lalu'] . ' :_* ' . $data_bulan_lalu['nilai_angka'] . ' ( ' . $data_bulan_lalu['nilai_huruf'] . ' )

1. *_' . $ddhl_1['komp'] . ' ' . $ddhl_1['fact'] . ' :_*
Target : ' . $ddhl_1['tgt'] . ' || Realisasi : ' . $ddhl_1['realisasi'] . '

2. *_' . $ddhl_2['komp'] . ' ' . $ddhl_2['fact'] . ' :_*
Target : ' . $ddhl_2['tgt'] . ' || Realisasi : ' . $ddhl_2['realisasi'] . '

3. *_' . $ddhl_3['komp'] . ' ' . $ddhl_3['fact'] . ' :_*
Target : ' . $ddhl_3['tgt'] . ' || Realisasi : ' . $ddhl_3['realisasi'] . '

4. *_' . $ddhl_5['komp'] . ' ' . $ddhl_5['fact'] . ' :_*
Target : ' . $ddhl_5['tgt'] . ' || Realisasi : ' . $ddhl_5['realisasi'] . '

5. *_' . $ddhl_7['komp'] . ' ' . $ddhl_7['fact'] . ' :_*
Target : ' . $ddhl_7['tgt'] . ' || Realisasi : ' . $ddhl_7['realisasi'] . '

6. *_' . $ddhl_8['fact'] . ' :_*
Target : ' . $ddhl_8['tgt'] . ' || Realisasi : ' . $ddhl_8['realisasi'] . '

*_' . $data['bln_ini'] . ' ' . $data['thn_ini'] . ' :_* ' . $data_bulan['nilai_angka'] . ' ( ' . $data_bulan['nilai_huruf'] . ' )

1. *_' . $ddhi_1['komp'] . ' ' . $ddhi_1['fact'] . ' :_*
Target : ' . $ddhi_1['tgt'] . ' || Realisasi : ' . $ddhi_1['realisasi'] . '

2. *_' . $ddhi_2['komp'] . ' ' . $ddhi_2['fact'] . ' :_*
Target : ' . $ddhi_2['tgt'] . ' || Realisasi : ' . $ddhi_2['realisasi'] . '

3. *_' . $ddhi_3['komp'] . ' ' . $ddhi_3['fact'] . ' :_*
Target : ' . $ddhi_3['tgt'] . ' || Realisasi : ' . $ddhi_3['realisasi'] . '

4. *_' . $ddhi_5['komp'] . ' ' . $ddhi_5['fact'] . ' :_*
Target : ' . $ddhi_5['tgt'] . ' || Realisasi : ' . $ddhi_5['realisasi'] . '

5. *_' . $ddhi_7['komp'] . ' ' . $ddhi_7['fact'] . ' :_*
Target : ' . $ddhi_7['tgt'] . ' || Realisasi : ' . $ddhi_7['realisasi'] . '

6. *_' . $ddhi_8['fact'] . ' :_*
Target : ' . $ddhi_8['tgt'] . ' || Realisasi : ' . $ddhi_8['realisasi'] . '

*Tingkatkan lagi kinerja kalian!!!*
*_KSP BINA ARTHA PRIMA_*';

        $footer = '*KSP Bina Artha Prima*';
        $data_inputan = array(
            'api_key'    => $sett_wa['api_key'],
            'sender'     => $sett_wa['no_hp'],
            'number'     => $no_hp,
            'message'    => $pesan,
            'footer'     => $footer
        );
        $curl = curl_init($sett_wa['endpoint_url']);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data_inputan));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_exec($curl);
        curl_close($curl);
    }
    // Cek bulan lalu
    private function _cekDataBulanLalu($blnlalu)
    {
        if ($blnlalu == '01') :
            $blnll = 'Januari';
        elseif ($blnlalu == '02'):
            $blnll = 'Februari';
        elseif ($blnlalu == '03'):
            $blnll = 'Maret';
        elseif ($blnlalu == '04'):
            $blnll = 'April';
        elseif ($blnlalu == '05'):
            $blnll = 'Mei';
        elseif ($blnlalu == '06'):
            $blnll = 'Juni';
        elseif ($blnlalu == '07'):
            $blnll = 'Juli';
        elseif ($blnlalu == '08'):
            $blnll = 'Agustus';
        elseif ($blnlalu == '09'):
            $blnll = 'September';
        elseif ($blnlalu == '10'):
            $blnll = 'Oktober';
        elseif ($blnlalu == '11'):
            $blnll = 'November';
        elseif ($blnlalu == '12'):
            $blnll = 'Desember';
        endif;
        return $blnll;
    }
    // Cek bulan Sekarang
    private function _cekDataBulanIni($bulan)
    {
        if ($bulan == '01') :
            $blnin = 'Januari';
        elseif ($bulan == '02'):
            $blnin = 'Februari';
        elseif ($bulan == '03'):
            $blnin = 'Maret';
        elseif ($bulan == '04'):
            $blnin = 'April';
        elseif ($bulan == '05'):
            $blnin = 'Mei';
        elseif ($bulan == '06'):
            $blnin = 'Juni';
        elseif ($bulan == '07'):
            $blnin = 'Juli';
        elseif ($bulan == '08'):
            $blnin = 'Agustus';
        elseif ($bulan == '09'):
            $blnin = 'September';
        elseif ($bulan == '10'):
            $blnin = 'Oktober';
        elseif ($bulan == '11'):
            $blnin = 'November';
        elseif ($bulan == '12'):
            $blnin = 'Desember';
        endif;
        return $blnin;
    }
}

/* End of file ControllerKPI.php and path \application\controllers\notifikasi\ControllerKPI.php */