<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Laporan_rekap_jenis_kegiatan extends CI_Controller {

	public function __construct(){

        parent::__construct();		

        $this->load->model('M_laporan_rekap_jenis_kegiatan');

    }

    private function ubahDateTime($dateTime){

        $bulan = array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");

        $date = explode(" ", $dateTime)[0];

        return intval(explode("-", $date)[2])." ".$bulan[intval(explode("-", $date)[1])-1]." ".explode("-", $date)[0]." ".explode(" ", $dateTime)[1];

    }

    private function date_to_date($date){

        $bulan = array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");

        return intval(explode("-", $date)[2])." ".$bulan[intval(explode("-", $date)[1])-1]." ".explode("-", $date)[0];

    }

    public function laporan_rekap_jenis_kegiatan($periode_thn){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode($d)->result_array();

        $total_penerimaan = 0;

        $total_pengeluaran = 0;

        for($i=0; $i<count($result);$i++){

            $dd['jenis_kegiatan']=$result[$i]['jenis_kegiatan'];

            $dd['periode_thn'] = $d['periode_thn'];

            $r = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_kode_pka($dd)->result_array();

            $jj = 0;

            $gg = 0;

            for($ii=0; $ii<count($r);$ii++){

                $ddd['kode_pka']=$r[$ii]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($iii=0; $iii<count($rr);$iii++){

                    $j +=$rr[$iii]['penerimaan'];

                }

                $jj += $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    $g +=$rrp[$iii]['pengeluaran'];

                }

                $gg += $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                

            }

            $result[$i]['penerimaan'] = $jj;

            $result[$i]['pengeluaran'] = $gg;

            $result[$i]['saldo'] = $jj - $gg;

            $total_penerimaan +=$jj;

            $total_pengeluaran +=$gg;



        }

        ////////////////////////////////

        //tanpa proyek    ///////

        ////////////////////////////

        // [{"kode_pka":"EYY8S46","jenis_kegiatan":"2","nama_jenis_kegiatan":"Rutin","penerimaan":1130635155,"pengeluaran":1423807174,"saldo":-293172019},

        $array_no_pro = $result;

        function removeElementWithValue($array, $key, $value){

             foreach($array as $subKey => $subArray){

                  if($subArray[$key] == $value){

                       unset($array[$subKey]);

                  }

             }

             return $array;

        }

        $newArr1 = removeElementWithValue($array_no_pro, "jenis_kegiatan", 2);

        $newArr = removeElementWithValue($newArr1, "jenis_kegiatan", 3);

        $newdata =  array (

          'kode_pka' => '-',

          'jenis_kegiatan' => '-',

          'nama_jenis_kegiatan' => 'Rutin + Non Rutin',

          'penerimaan' => $result[0]['penerimaan']+$result[1]['penerimaan'],

          'pengeluaran' => $result[0]['pengeluaran']+$result[1]['pengeluaran'],

          'saldo' => $result[0]['saldo']+$result[1]['saldo']

        );

        array_push($newArr,$newdata);

        // echo json_encode($newArr);









        ///////

        $data['result'] = $result;

        $data['periode_thn'] = $d['periode_thn'];

        $data['total_penerimaan'] = $total_penerimaan;

        $data['total_pengeluaran'] = $total_pengeluaran;

        $data['total_saldo'] = $total_penerimaan - $total_pengeluaran;



        $data['newArr'] = $newArr;



        $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel',$data);

        

    }

    public function laporan_rekap_jenis_kegiatan_pdf($periode_thn){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode($d)->result_array();

        $total_penerimaan = 0;

        $total_pengeluaran = 0;

        for($i=0; $i<count($result);$i++){

            $dd['jenis_kegiatan']=$result[$i]['jenis_kegiatan'];

            $dd['periode_thn'] = $d['periode_thn'];

            $r = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_kode_pka($dd)->result_array();

            $jj = 0;

            $gg = 0;

            for($ii=0; $ii<count($r);$ii++){

                $ddd['kode_pka']=$r[$ii]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($iii=0; $iii<count($rr);$iii++){

                    $j +=$rr[$iii]['penerimaan'];

                }

                $jj += $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    $g +=$rrp[$iii]['pengeluaran'];

                }

                $gg += $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                

            }

            $result[$i]['penerimaan'] = $jj;

            $result[$i]['pengeluaran'] = $gg;

            $result[$i]['saldo'] = $jj - $gg;

            $total_penerimaan +=$jj;

            $total_pengeluaran +=$gg;



        }

        ////////////////////////////////

        //tanpa proyek    ///////

        ////////////////////////////

        // [{"kode_pka":"EYY8S46","jenis_kegiatan":"2","nama_jenis_kegiatan":"Rutin","penerimaan":1130635155,"pengeluaran":1423807174,"saldo":-293172019},

        $array_no_pro = $result;

        function removeElementWithValue($array, $key, $value){

             foreach($array as $subKey => $subArray){

                  if($subArray[$key] == $value){

                       unset($array[$subKey]);

                  }

             }

             return $array;

        }

        $newArr1 = removeElementWithValue($array_no_pro, "jenis_kegiatan", 2);

        $newArr = removeElementWithValue($newArr1, "jenis_kegiatan", 3);

        $newdata =  array (

          'kode_pka' => '-',

          'jenis_kegiatan' => '-',

          'nama_jenis_kegiatan' => 'Rutin + Non Rutin',

          'penerimaan' => $result[0]['penerimaan']+$result[1]['penerimaan'],

          'pengeluaran' => $result[0]['pengeluaran']+$result[1]['pengeluaran'],

          'saldo' => $result[0]['saldo']+$result[1]['saldo']

        );

        array_push($newArr,$newdata);

        // echo json_encode($newArr);









        ///////

        $data['result'] = $result;

        $data['periode_thn'] = $d['periode_thn'];

        $data['total_penerimaan'] = $total_penerimaan;

        $data['total_pengeluaran'] = $total_pengeluaran;

        $data['total_saldo'] = $total_penerimaan - $total_pengeluaran;



        $data['newArr'] = $newArr;



        // $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan',$data);

        $mpdf = new \Mpdf\Mpdf();

        $data = $this->load->view('laporan/v_laporan_pka_excel',$data);

        $dat = $this->load->view('laporan/rekap/jenis_kegiatan/pdf/v_laporan_rekap_jenis_kegiatan_pdf', $data, TRUE);

        // $data ="<h1>jhkjhkjh</h1>";

        $mpdf->AddPage("P","","","","","10","10","15","10","","","","","","","","","","","","Legal");

        $mpdf->WriteHTML($dat);

        $mpdf->Output();

    }

    public function laporan_rekap_jenis_kegiatan_pertriwulan($periode_thn){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode($d)->result_array();

        // echo json_encode($result);

        // var_djenis_kegiatanp($result);

        $total_penerimaan = 0;

        $total_pengeluaran = 0;

        $t_pen_t1 = 0;

        $t_pen_t2 = 0;

        $t_pen_t3 = 0;

        $t_pen_t4 = 0;

        $t_peng_t1 = 0;

        $t_peng_t2 = 0;

        $t_peng_t3 = 0;

        $t_peng_t4 = 0;

        for($i=0; $i<count($result);$i++){

            // echo $result[$i]['nama_jenis_kegiatan']."==".$result[$i]['kode_pka']."<br>";

            $dd['jenis_kegiatan']=$result[$i]['jenis_kegiatan'];

            $dd['periode_thn'] = $d['periode_thn'];

            $r = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_kode_pka($dd)->result_array();

            $jj = 0;

            $gg = 0;

            $jenis_kegiatan_pen_t1 = 0;

            $jenis_kegiatan_pen_t2 = 0;

            $jenis_kegiatan_pen_t3 = 0;

            $jenis_kegiatan_pen_t4 = 0;

            $jenis_kegiatan_peng_t1 = 0;

            $jenis_kegiatan_peng_t2 = 0;

            $jenis_kegiatan_peng_t3 = 0;

            $jenis_kegiatan_peng_t4 = 0;

            for($ii=0; $ii<count($r);$ii++){

                $ddd['kode_pka']=$r[$ii]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($iii=0; $iii<count($rr);$iii++){

                    // echo $rr[$iii]['penerimaan']."=======<br>";

                    $j +=$rr[$iii]['penerimaan'];

                }

                $jj += $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    // echo $rr[$iii]['penerimaan']."=======<br>";

                    $g +=$rrp[$iii]['pengeluaran'];

                }

                $gg += $g;

                ///END penerimaan///

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                // echo $ct['triwulan']."////";

                // echo preg_replace("/[^0-9]/", "", $ju[0]);

                // echo ";;;".count($ju)."---";

                $pen_t1 = 0;

                $pen_t2 = 0;

                $pen_t3 = 0;

                $pen_t4 = 0;

                $peng_t1 = 0;

                $peng_t2 = 0;

                $peng_t3 = 0;

                $peng_t4 = 0;

                for ($tt=0; $tt < count($ju); $tt++) { 

                    // echo preg_replace("/[^0-9]/", "", $ju[$tt])."<br>";

                    if (preg_replace("/[^0-9]/", "", $ju[$tt]) == 1) {

                        $pen_t1 += $j/count($ju);

                        $peng_t1 += $g/count($ju);

                        // echo $pen_t1."<br>";

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 2) {

                        $pen_t2 += $j/count($ju);

                        $peng_t2 +=$g/count($ju);

                        // echo $pen_t2."<br>";

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 3) {

                        $pen_t3 += $j/count($ju);

                        $peng_t3 += $g/count($ju);

                        // echo $pen_t3."<br>";

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 4) {

                        $pen_t4 += $j/count($ju);

                        $peng_t4 += $g/count($ju);

                        // echo $pen_t4."<br>";

                    }

                    // echo "<br>";

                }

                // echo "......".$g."......";

                // echo $pen_t1."|t1|";

                // echo $pen_t2."|t2|";

                // echo $pen_t3."|t3|";

                // echo $pen_t4."|t4|";

                // echo "<hr>";

                $jenis_kegiatan_pen_t1 += $pen_t1;

                $jenis_kegiatan_pen_t2 += $pen_t2;

                $jenis_kegiatan_pen_t3 += $pen_t3;

                $jenis_kegiatan_pen_t4 += $pen_t4;

                $jenis_kegiatan_peng_t1 += $peng_t1;

                $jenis_kegiatan_peng_t2 += $peng_t2;

                $jenis_kegiatan_peng_t3 += $peng_t3;

                $jenis_kegiatan_peng_t4 += $peng_t4;

                // echo $j."---<br>";

            }

            $result[$i]['penerimaan'] = $jj;

            $result[$i]['pengeluaran'] = $gg;

            $result[$i]['pen_t1'] = $jenis_kegiatan_pen_t1;

            $result[$i]['pen_t2'] = $jenis_kegiatan_pen_t2;

            $result[$i]['pen_t3'] = $jenis_kegiatan_pen_t3;

            $result[$i]['pen_t4'] = $jenis_kegiatan_pen_t4;

            $result[$i]['peng_t1'] = $jenis_kegiatan_peng_t1;

            $result[$i]['peng_t2'] = $jenis_kegiatan_peng_t2;

            $result[$i]['peng_t3'] = $jenis_kegiatan_peng_t3;

            $result[$i]['peng_t4'] = $jenis_kegiatan_peng_t4;

            // echo $jenis_kegiatan_pen_t1."<br>";

            // echo $jenis_kegiatan_pen_t2."<br>";

            // echo $jenis_kegiatan_pen_t3."<br>";

            // echo $jenis_kegiatan_pen_t4."<br>";

            // echo "<hr>";

            $total_penerimaan +=$jj;

            $total_pengeluaran +=$gg;

            $t_pen_t1 += $jenis_kegiatan_pen_t1;

            $t_pen_t2 += $jenis_kegiatan_pen_t2;

            $t_pen_t3 += $jenis_kegiatan_pen_t3;

            $t_pen_t4 += $jenis_kegiatan_pen_t4;

            // echo "<hr>".$jj."<br>";

            $t_peng_t1 += $jenis_kegiatan_peng_t1;

            $t_peng_t2 += $jenis_kegiatan_peng_t2;

            $t_peng_t3 += $jenis_kegiatan_peng_t3;

            $t_peng_t4 += $jenis_kegiatan_peng_t4;

        }

        $data['result'] = $result;

        $data['periode_thn'] = $d['periode_thn'];

        $data['total_penerimaan'] = $total_penerimaan;

        $data['total_pengeluaran'] = $total_pengeluaran;

        $data['t_pen_t1'] = $t_pen_t1;

        $data['t_pen_t2'] = $t_pen_t2;

        $data['t_pen_t3'] = $t_pen_t3;

        $data['t_pen_t4'] = $t_pen_t4;

        $data['t_peng_t1'] = $t_peng_t1;

        $data['t_peng_t2'] = $t_peng_t2;

        $data['t_peng_t3'] = $t_peng_t3;

        $data['t_peng_t4'] = $t_peng_t4;

        $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan',$data);

    }

    public function laporan_rekap_jenis_kegiatan_pertriwulan_pdf($periode_thn){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode($d)->result_array();

        $total_penerimaan = 0;

        $total_pengeluaran = 0;

        $t_pen_t1 = 0;

        $t_pen_t2 = 0;

        $t_pen_t3 = 0;

        $t_pen_t4 = 0;

        $t_peng_t1 = 0;

        $t_peng_t2 = 0;

        $t_peng_t3 = 0;

        $t_peng_t4 = 0;

        for($i=0; $i<count($result);$i++){

            $dd['jenis_kegiatan']=$result[$i]['jenis_kegiatan'];

            $dd['periode_thn'] = $d['periode_thn'];

            $r = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_kode_pka($dd)->result_array();

            $jj = 0;

            $gg = 0;

            $jenis_kegiatan_pen_t1 = 0;

            $jenis_kegiatan_pen_t2 = 0;

            $jenis_kegiatan_pen_t3 = 0;

            $jenis_kegiatan_pen_t4 = 0;

            $jenis_kegiatan_peng_t1 = 0;

            $jenis_kegiatan_peng_t2 = 0;

            $jenis_kegiatan_peng_t3 = 0;

            $jenis_kegiatan_peng_t4 = 0;

            for($ii=0; $ii<count($r);$ii++){

                $ddd['kode_pka']=$r[$ii]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($iii=0; $iii<count($rr);$iii++){

                    $j +=$rr[$iii]['penerimaan'];

                }

                $jj += $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    $g +=$rrp[$iii]['pengeluaran'];

                }

                $gg += $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                $pen_t1 = 0;

                $pen_t2 = 0;

                $pen_t3 = 0;

                $pen_t4 = 0;

                $peng_t1 = 0;

                $peng_t2 = 0;

                $peng_t3 = 0;

                $peng_t4 = 0;

                for ($tt=0; $tt < count($ju); $tt++) {

                    if (preg_replace("/[^0-9]/", "", $ju[$tt]) == 1) {

                        $pen_t1 += $j/count($ju);

                        $peng_t1 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 2) {

                        $pen_t2 += $j/count($ju);

                        $peng_t2 +=$g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 3) {

                        $pen_t3 += $j/count($ju);

                        $peng_t3 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 4) {

                        $pen_t4 += $j/count($ju);

                        $peng_t4 += $g/count($ju);

                    }

                }

                $jenis_kegiatan_pen_t1 += $pen_t1;

                $jenis_kegiatan_pen_t2 += $pen_t2;

                $jenis_kegiatan_pen_t3 += $pen_t3;

                $jenis_kegiatan_pen_t4 += $pen_t4;

                $jenis_kegiatan_peng_t1 += $peng_t1;

                $jenis_kegiatan_peng_t2 += $peng_t2;

                $jenis_kegiatan_peng_t3 += $peng_t3;

                $jenis_kegiatan_peng_t4 += $peng_t4;

            }

            $result[$i]['penerimaan'] = $jj;

            $result[$i]['pengeluaran'] = $gg;

            $result[$i]['pen_t1'] = $jenis_kegiatan_pen_t1;

            $result[$i]['pen_t2'] = $jenis_kegiatan_pen_t2;

            $result[$i]['pen_t3'] = $jenis_kegiatan_pen_t3;

            $result[$i]['pen_t4'] = $jenis_kegiatan_pen_t4;

            $result[$i]['peng_t1'] = $jenis_kegiatan_peng_t1;

            $result[$i]['peng_t2'] = $jenis_kegiatan_peng_t2;

            $result[$i]['peng_t3'] = $jenis_kegiatan_peng_t3;

            $result[$i]['peng_t4'] = $jenis_kegiatan_peng_t4;

            $total_penerimaan +=$jj;

            $total_pengeluaran +=$gg;

            $t_pen_t1 += $jenis_kegiatan_pen_t1;

            $t_pen_t2 += $jenis_kegiatan_pen_t2;

            $t_pen_t3 += $jenis_kegiatan_pen_t3;

            $t_pen_t4 += $jenis_kegiatan_pen_t4;

            $t_peng_t1 += $jenis_kegiatan_peng_t1;

            $t_peng_t2 += $jenis_kegiatan_peng_t2;

            $t_peng_t3 += $jenis_kegiatan_peng_t3;

            $t_peng_t4 += $jenis_kegiatan_peng_t4;

        }

        $data['result'] = $result;

        $data['periode_thn'] = $d['periode_thn'];

        $data['total_penerimaan'] = $total_penerimaan;

        $data['total_pengeluaran'] = $total_pengeluaran;

        $data['t_pen_t1'] = $t_pen_t1;

        $data['t_pen_t2'] = $t_pen_t2;

        $data['t_pen_t3'] = $t_pen_t3;

        $data['t_pen_t4'] = $t_pen_t4;

        $data['t_peng_t1'] = $t_peng_t1;

        $data['t_peng_t2'] = $t_peng_t2;

        $data['t_peng_t3'] = $t_peng_t3;

        $data['t_peng_t4'] = $t_peng_t4;

        // $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan',$data);

        $mpdf = new \Mpdf\Mpdf();

        // $data = $this->load->view('laporan/v_laporan_pka_excel',$data);

        $dat = $this->load->view('laporan/rekap/jenis_kegiatan/pdf/v_laporan_rekap_jenis_kegiatan_pdf_pertriwulan', $data, TRUE);

        // $data ="<h1>jhkjhkjh</h1>";

        $mpdf->AddPage("P","","","","","10","10","15","10","","","","","","","","","","","","Legal");

        $mpdf->WriteHTML($dat);

        $mpdf->Output();

    }

    public function laporan_rekap_jenis_kegiatan_pertriwulan_2($periode_thn,$id_jenis_kegiatan){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $d['id_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[0];

    

        $tot_pen_t1 = 0;

        $tot_pen_t2 = 0;

        $tot_pen_t3 = 0;

        $tot_pen_t4 = 0;

        $tot_peng_t1 = 0;

        $tot_peng_t2 = 0;

        $tot_peng_t3 = 0;

        $tot_peng_t4 = 0;

        $tot_pen = 0;

        $tot_peng = 0;

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_2($d)->result_array();

        for($i=0; $i<count($result);$i++){

                $ddd['kode_pka']=$result[$i]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($ii=0; $ii<count($rr);$ii++){

                    if (empty($rr[$ii]['penerimaan'])) {

                        $j +=0;

                    }else{

                        $j +=$rr[$ii]['penerimaan'];    

                    }

                }

                $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    if (empty($rrp[$iii]['pengeluaran'])) {

                        $g +=0;

                    }else{

                        $g +=$rrp[$iii]['pengeluaran'];

                    }

                }

                $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                $pen_t1 = 0;

                $pen_t2 = 0;

                $pen_t3 = 0;

                $pen_t4 = 0;

                $peng_t1 = 0;

                $peng_t2 = 0;

                $peng_t3 = 0;

                $peng_t4 = 0;

                for ($tt=0; $tt < count($ju); $tt++) {

                    if (preg_replace("/[^0-9]/", "", $ju[$tt]) == 1) {

                        $pen_t1 += $j/count($ju);

                        $peng_t1 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 2) {

                        $pen_t2 += $j/count($ju);

                        $peng_t2 +=$g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 3) {

                        $pen_t3 += $j/count($ju);

                        $peng_t3 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 4) {

                        $pen_t4 += $j/count($ju);

                        $peng_t4 += $g/count($ju);

                    }

                }

                $tot_pen_t1 += $pen_t1;

                $tot_pen_t2 += $pen_t2;

                $tot_pen_t3 += $pen_t3;

                $tot_pen_t4 += $pen_t4;

                $tot_peng_t1 += $peng_t1;

                $tot_peng_t2 += $peng_t2;

                $tot_peng_t3 += $peng_t3;

                $tot_peng_t4 += $peng_t4;

                $data[$i]["pen_t1"] = $pen_t1;

                $data[$i]["pen_t2"] = $pen_t2;

                $data[$i]["pen_t3"] = $pen_t3;

                $data[$i]["pen_t4"] = $pen_t4;

                $data[$i]["peng_t1"] = $peng_t1;

                $data[$i]["peng_t2"] = $peng_t2;

                $data[$i]["peng_t3"] = $peng_t3;

                $data[$i]["peng_t4"] = $peng_t4;

                $data[$i]["penerimaan"] = $j;

                $data[$i]["pengeluaran"] = $g;

                $tot_pen    += $j;

                $tot_peng   += $g;

                $data[$i]["kma"] = $result[$i]['kma'];

                $data[$i]["nama_um"] = $result[$i]['nama_um'];

                $data[$i]["nama_kegiatan"] = $result[$i]['nama_kegiatan'];

        }

        $data['result'] = $data;

        $data['nama_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[1];

        $data["t_pen_t1"] = $tot_pen_t1;

        $data["t_pen_t2"] = $tot_pen_t2;

        $data["t_pen_t3"] = $tot_pen_t3;

        $data["t_pen_t4"] = $tot_pen_t4;

        $data["t_peng_t1"] = $tot_peng_t1;

        $data["t_peng_t2"] = $tot_peng_t2;

        $data["t_peng_t3"] = $tot_peng_t3;

        $data["t_peng_t4"] = $tot_peng_t4;

        $data["tot_pen"]   = $tot_pen;

        $data["tot_peng"]    = $tot_peng;

        $data['periode_thn'] = $d['periode_thn'];

        $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan_2',$data);

    }

    public function laporan_rekap_jenis_kegiatan_pertriwulan_pdf_2($periode_thn,$id_jenis_kegiatan){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $d['id_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[0];

    

        $tot_pen_t1 = 0;

        $tot_pen_t2 = 0;

        $tot_pen_t3 = 0;

        $tot_pen_t4 = 0;

        $tot_peng_t1 = 0;

        $tot_peng_t2 = 0;

        $tot_peng_t3 = 0;

        $tot_peng_t4 = 0;

        $tot_pen = 0;

        $tot_peng = 0;

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_2($d)->result_array();

        for($i=0; $i<count($result);$i++){

                $ddd['kode_pka']=$result[$i]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($ii=0; $ii<count($rr);$ii++){

                    if (empty($rr[$ii]['penerimaan'])) {

                        $j +=0;

                    }else{

                        $j +=$rr[$ii]['penerimaan'];    

                    }

                }

                $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    if (empty($rrp[$iii]['pengeluaran'])) {

                        $g +=0;

                    }else{

                        $g +=$rrp[$iii]['pengeluaran'];

                    }

                }

                $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                $pen_t1 = 0;

                $pen_t2 = 0;

                $pen_t3 = 0;

                $pen_t4 = 0;

                $peng_t1 = 0;

                $peng_t2 = 0;

                $peng_t3 = 0;

                $peng_t4 = 0;

                for ($tt=0; $tt < count($ju); $tt++) {

                    if (preg_replace("/[^0-9]/", "", $ju[$tt]) == 1) {

                        $pen_t1 += $j/count($ju);

                        $peng_t1 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 2) {

                        $pen_t2 += $j/count($ju);

                        $peng_t2 +=$g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 3) {

                        $pen_t3 += $j/count($ju);

                        $peng_t3 += $g/count($ju);

                    }elseif (preg_replace("/[^0-9]/", "", $ju[$tt]) == 4) {

                        $pen_t4 += $j/count($ju);

                        $peng_t4 += $g/count($ju);

                    }

                }

                $tot_pen_t1 += $pen_t1;

                $tot_pen_t2 += $pen_t2;

                $tot_pen_t3 += $pen_t3;

                $tot_pen_t4 += $pen_t4;

                $tot_peng_t1 += $peng_t1;

                $tot_peng_t2 += $peng_t2;

                $tot_peng_t3 += $peng_t3;

                $tot_peng_t4 += $peng_t4;

                $data[$i]["pen_t1"] = $pen_t1;

                $data[$i]["pen_t2"] = $pen_t2;

                $data[$i]["pen_t3"] = $pen_t3;

                $data[$i]["pen_t4"] = $pen_t4;

                $data[$i]["peng_t1"] = $peng_t1;

                $data[$i]["peng_t2"] = $peng_t2;

                $data[$i]["peng_t3"] = $peng_t3;

                $data[$i]["peng_t4"] = $peng_t4;

                $data[$i]["penerimaan"] = $j;

                $data[$i]["pengeluaran"] = $g;

                $tot_pen    += $j;

                $tot_peng   += $g;

                $data[$i]["kma"] = $result[$i]['kma'];

                $data[$i]["nama_um"] = $result[$i]['nama_um'];

                $data[$i]["nama_kegiatan"] = $result[$i]['nama_kegiatan'];

        }

        $data['result'] = $data;

        $data['nama_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[1];

        $data["t_pen_t1"] = $tot_pen_t1;

        $data["t_pen_t2"] = $tot_pen_t2;

        $data["t_pen_t3"] = $tot_pen_t3;

        $data["t_pen_t4"] = $tot_pen_t4;

        $data["t_peng_t1"] = $tot_peng_t1;

        $data["t_peng_t2"] = $tot_peng_t2;

        $data["t_peng_t3"] = $tot_peng_t3;

        $data["t_peng_t4"] = $tot_peng_t4;

        $data["tot_pen"]   = $tot_pen;

        $data["tot_peng"]    = $tot_peng;

        $data['periode_thn'] = $d['periode_thn'];

        // $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan_2',$data);

        $mpdf = new \Mpdf\Mpdf();

        $dat = $this->load->view('laporan/rekap/jenis_kegiatan/pdf/v_laporan_rekap_jenis_kegiatan_pdf_pertriwulan_2', $data, TRUE);

        $mpdf->AddPage("L","","","","","10","10","15","5","","","","","","","","","","","","Legal");

        $mpdf->WriteHTML($dat);

        $mpdf->Output();

    }

    public function laporan_rekap_jenis_kegiatan_3($periode_thn,$id_jenis_kegiatan){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $d['id_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[0];

        $tot_pen = 0;

        $tot_peng = 0;

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_3($d)->result_array();

        for($i=0; $i<count($result);$i++){

                $ddd['kode_pka']=$result[$i]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($ii=0; $ii<count($rr);$ii++){

                    if (empty($rr[$ii]['penerimaan'])) {

                        $j +=0;

                    }else{

                        $j +=$rr[$ii]['penerimaan'];    

                    }

                }

                $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    if (empty($rrp[$iii]['pengeluaran'])) {

                        $g +=0;

                    }else{

                        $g +=$rrp[$iii]['pengeluaran'];

                    }

                }

                $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                $data[$i]["penerimaan"] = $j;

                $data[$i]["pengeluaran"] = $g;

                $tot_pen    += $j;

                $tot_peng   += $g;

                $data[$i]["kma"] = $result[$i]['kma'];

                $data[$i]["nama_um"] = $result[$i]['nama_um'];

                $data[$i]["nama_kegiatan"] = $result[$i]['nama_kegiatan'];

                $data[$i]["nama_bidang"] = $result[$i]['nama_b'];

                $data[$i]["tujuan_kegiatan"] = $result[$i]['tujuan_kegiatan'];

                $data[$i]["lokasi_pp"] = $result[$i]['lokasi_pp'];

                $data[$i]["pendukung_program"] = $result[$i]['pendukung_program'];

                $data[$i]["pen_jawab_program"] = $result[$i]['pen_jawab_program'];

                $data[$i]["w_awal_pp"] = $result[$i]['w_awal_pp'];

                $data[$i]["w_akhir_pp"] = $result[$i]['w_akhir_pp'];

                $data[$i]["indikator_kuantitatif"] = $result[$i]['indikator_kuantitatif'];

                $data[$i]["indikator_kualitatif"] = $result[$i]['indikator_kualitatif'];

                $data[$i]["keterangan"] = $result[$i]['keterangan'];

        }

        $data['result'] = $data;

        // var_dump($data);

        $data['nama_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[1];

        $data["tot_pen"]   = $tot_pen;

        $data["tot_peng"]    = $tot_peng;

        $data['periode_thn'] = $d['periode_thn'];

        $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_3',$data);

        // $mpdf = new \Mpdf\Mpdf();

        // $dat = $this->load->view('laporan/rekap/jenis_kegiatan/pdf/v_laporan_rekap_jenis_kegiatan_pdf_3', $data, TRUE);

        // $mpdf->AddPage("L","","","","","10","10","15","5","","","","","","","","","","","","Legal");

        // $mpdf->WriteHTML($dat);

        // $mpdf->Output();

    }

    public function laporan_rekap_jenis_kegiatan_pdf_3($periode_thn,$id_jenis_kegiatan){

        $d['periode_thn'] = str_replace('-', '/', $periode_thn);

        $d['id_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[0];

        $tot_pen = 0;

        $tot_peng = 0;

        $result = $this->M_laporan_rekap_jenis_kegiatan->data_pka_periode_3($d)->result_array();

        for($i=0; $i<count($result);$i++){

                $ddd['kode_pka']=$result[$i]['kode_pka'];

                ///penerimaan///

                $rr = $this->M_laporan_rekap_jenis_kegiatan->ambil_penerimaan($ddd)->result_array();

                $j = 0;

                for($ii=0; $ii<count($rr);$ii++){

                    if (empty($rr[$ii]['penerimaan'])) {

                        $j +=0;

                    }else{

                        $j +=$rr[$ii]['penerimaan'];    

                    }

                }

                $j;

                ///END penerimaan///

                ///pengeluaran///

                $rrp = $this->M_laporan_rekap_jenis_kegiatan->ambil_pengeluaran($ddd)->result_array();

                $g = 0;

                for($iii=0; $iii<count($rrp);$iii++){

                    if (empty($rrp[$iii]['pengeluaran'])) {

                        $g +=0;

                    }else{

                        $g +=$rrp[$iii]['pengeluaran'];

                    }

                }

                $g;

                $ct = $this->M_laporan_rekap_jenis_kegiatan->ambil_triwulan($ddd)->row_array();

                $ju = explode(",", $ct['triwulan']);

                $data[$i]["penerimaan"] = $j;

                $data[$i]["pengeluaran"] = $g;

                $tot_pen    += $j;

                $tot_peng   += $g;

                $data[$i]["kma"] = $result[$i]['kma'];

                $data[$i]["nama_um"] = $result[$i]['nama_um'];

                $data[$i]["nama_kegiatan"] = $result[$i]['nama_kegiatan'];

                $data[$i]["nama_bidang"] = $result[$i]['nama_b'];

                $data[$i]["tujuan_kegiatan"] = $result[$i]['tujuan_kegiatan'];

                $data[$i]["lokasi_pp"] = $result[$i]['lokasi_pp'];

                $data[$i]["pendukung_program"] = $result[$i]['pendukung_program'];

                $data[$i]["pen_jawab_program"] = $result[$i]['pen_jawab_program'];

                $data[$i]["w_awal_pp"] = $result[$i]['w_awal_pp'];

                $data[$i]["w_akhir_pp"] = $result[$i]['w_akhir_pp'];

                $data[$i]["indikator_kuantitatif"] = $result[$i]['indikator_kuantitatif'];

                $data[$i]["indikator_kualitatif"] = $result[$i]['indikator_kualitatif'];

                $data[$i]["keterangan"] = $result[$i]['keterangan'];

        }

        $data['result'] = $data;

        // var_dump($data);

        $data['nama_jenis_kegiatan'] = explode("_", $id_jenis_kegiatan)[1];

        $data["tot_pen"]   = $tot_pen;

        $data["tot_peng"]    = $tot_peng;

        $data['periode_thn'] = $d['periode_thn'];

        // $this->load->view('laporan/rekap/jenis_kegiatan/excel/v_laporan_rekap_jenis_kegiatan_excel_pertriwulan_2',$data);

        $mpdf = new \Mpdf\Mpdf();

        $dat = $this->load->view('laporan/rekap/jenis_kegiatan/pdf/v_laporan_rekap_jenis_kegiatan_pdf_3', $data, TRUE);

        $mpdf->AddPage("L","","","","","10","10","15","5","","","","","","","","","","","","Legal");

        $mpdf->WriteHTML($dat);

        $mpdf->Output();

    }

}