<?php



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







class Laporan_excel extends CI_Controller {







	public function __construct(){



        parent::__construct();		



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



    }



    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 cetak_excel($no_pka){



        $d['no_pka'] = $no_pka;



        $result = $this->M_laporan_excel->data_detail_pka($d)->result_array();



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



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



            $pengeluaran = $this->M_laporan_excel->select_data_pka_pengeluaran($data)->result_array();



            $penerimaan = $this->M_laporan_excel->select_data_pka_penerimaan($data)->result_array();



            // $a=0;



            // for($o=0; $o<count($pengeluaran);$o++){



            //     $a+=$pengeluaran[$o]['pengeluaran'];



            // }



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



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



            if($result[$i]['w_awal_pp'] == "00-00-000"){



                $result[$i]['w_awal_pp_case'] ="";



            }else{



                // $result[$i]['w_awal_pp_case']= explode("-", $result[$i]['w_awal_pp'])[2]." ".$this->date_to_date(explode("-", $result[$i]['w_awal_pp'])[1])." ".explode("-", $result[$i]['w_awal_pp'])[0] ;



                $result[$i]['w_awal_pp_case']= $this->date_to_date($result[$i]['w_awal_pp']);



            }



            if($result[$i]['w_akhir_pp'] == "00-00-000"){



                $result[$i]['w_akhir_pp_case']="";



            }else{



                // $result[$i]['w_akhir_pp_case']=explode("-", $result[$i]['w_akhir_pp'])[2]." ".$this->ubahDate(explode("-", $result[$i]['w_akhir_pp'])[1])." ".explode("-", $result[$i]['w_akhir_pp'])[0] ;



                 $result[$i]['w_akhir_pp_case']= $this->date_to_date($result[$i]['w_akhir_pp']);



            }



            if($result[$i]['keterangan']==""){



            	$result[$i]['ket'] = "n/a";	



            }else{



            	$result[$i]['ket'] = $result[$i]['keterangan'];



            }



            $result[$i]['dibuat_pada'] = $this->ubahDateTime($result[$i]['created_at']);



            



        }



        $data['result'] = $result;



        $data['no_pka'] = $no_pka;



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



    }



    public function cetak_excel_dashboard_user($periode){



        $result = $this->M_laporan_excel->data_pka_dashboard_user(str_replace("-","/",$periode))->result_array();



        // print_r($result);



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



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



            $pengeluaran = $this->M_laporan_excel->select_data_pka_pengeluaran($data)->result_array();



            $penerimaan = $this->M_laporan_excel->select_data_pka_penerimaan($data)->result_array();



            // $a=0;



            // for($o=0; $o<count($pengeluaran);$o++){



            //     $a+=$pengeluaran[$o]['pengeluaran'];



            // }



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



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



            if($result[$i]['w_awal_pp'] == "00-00-000"){



                $result[$i]['w_awal_pp_case'] ="";



            }else{



                // $result[$i]['w_awal_pp_case']= explode("-", $result[$i]['w_awal_pp'])[2]." ".$this->date_to_date(explode("-", $result[$i]['w_awal_pp'])[1])." ".explode("-", $result[$i]['w_awal_pp'])[0] ;



                $result[$i]['w_awal_pp_case']= $this->date_to_date($result[$i]['w_awal_pp']);



            }



            if($result[$i]['w_akhir_pp'] == "00-00-000"){



                $result[$i]['w_akhir_pp_case']="";



            }else{



                // $result[$i]['w_akhir_pp_case']=explode("-", $result[$i]['w_akhir_pp'])[2]." ".$this->ubahDate(explode("-", $result[$i]['w_akhir_pp'])[1])." ".explode("-", $result[$i]['w_akhir_pp'])[0] ;



                 $result[$i]['w_akhir_pp_case']= $this->date_to_date($result[$i]['w_akhir_pp']);



            }



            if($result[$i]['keterangan']==""){



                $result[$i]['ket'] = "n/a"; 



            }else{



                $result[$i]['ket'] = $result[$i]['keterangan'];



            }



            $result[$i]['dibuat_pada'] = $this->ubahDateTime($result[$i]['created_at']);



            



        }



        $data['result'] = $result;



        $data['periode'] = str_replace("-","/",$periode);



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



    }



    public function cetak_excel_dashboard_admin($periode){



        $result = $this->M_laporan_excel->data_pka_dashboard_admin(str_replace("-","/",$periode))->result_array();



        // print_r($result);



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



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



            $pengeluaran = $this->M_laporan_excel->select_data_pka_pengeluaran($data)->result_array();



            $penerimaan = $this->M_laporan_excel->select_data_pka_penerimaan($data)->result_array();



            // $a=0;



            // for($o=0; $o<count($pengeluaran);$o++){



            //     $a+=$pengeluaran[$o]['pengeluaran'];



            // }



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



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



            if($result[$i]['w_awal_pp'] == "00-00-000"){



                $result[$i]['w_awal_pp_case'] ="";



            }else{



                // $result[$i]['w_awal_pp_case']= explode("-", $result[$i]['w_awal_pp'])[2]." ".$this->date_to_date(explode("-", $result[$i]['w_awal_pp'])[1])." ".explode("-", $result[$i]['w_awal_pp'])[0] ;



                $result[$i]['w_awal_pp_case']= $this->date_to_date($result[$i]['w_awal_pp']);



            }



            if($result[$i]['w_akhir_pp'] == "00-00-000"){



                $result[$i]['w_akhir_pp_case']="";



            }else{



                // $result[$i]['w_akhir_pp_case']=explode("-", $result[$i]['w_akhir_pp'])[2]." ".$this->ubahDate(explode("-", $result[$i]['w_akhir_pp'])[1])." ".explode("-", $result[$i]['w_akhir_pp'])[0] ;



                 $result[$i]['w_akhir_pp_case']= $this->date_to_date($result[$i]['w_akhir_pp']);



            }



            if($result[$i]['keterangan']==""){



                $result[$i]['ket'] = "n/a"; 



            }else{



                $result[$i]['ket'] = $result[$i]['keterangan'];



            }



            $result[$i]['dibuat_pada'] = $this->ubahDateTime($result[$i]['created_at']);



            



        }



        $data['result'] = $result;



        $data['periode'] = str_replace("-","/",$periode);



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



    }



    public function laporan_ev_pka_excel($no_pka){



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



        $data["no_pka"] = $no_pka;



        $result = $this->M_pka->ambil_data_pka_evaluasi($data)->result_array();



        $r = $this->M_pka->ambil_data_pka_evaluasi($data)->row_array();



        $d['dibuat'] = $this->ubahDateTime($r['dibuat']);



        $d['pembuat'] = $r['username'];



        $d['um'] = $r['um'];



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







            $row = $this->M_pka->ambil_detail_pka_evaluasi($result[$i]['kode_pka'])->row_array();



            $result[$i]['pencapaian'] = $row['pencapaian'];



            $result[$i]['atp'] = $row['atp'];



            $result[$i]['target_kehadiran'] = $row['target_kehadiran'];



            $result[$i]['realisasi_kehadiran'] = $row['realisasi_kehadiran'];



            $result[$i]['realisasi_penerimaan'] = $row['realisasi_penerimaan'];



            $result[$i]['realisasi_pengeluaran'] = $row['realisasi_pengeluaran'];



            $result[$i]['epsk'] = $row['epsk'];







            $result[$i]['jml_pengeluaran'] = 0;



            $rp = $this->M_pka->ambil_data_pka_evaluasi_pengeluaran($result[$i]['kode_pka'])->result_array();



            for($u=0; $u<count($rp);$u++){



                $result[$i]['jml_pengeluaran'] += $rp[$u]['pengeluaran'];



            }



            $result[$i]['jml_penerimaan'] = 0;



            $rpn = $this->M_pka->ambil_data_pka_evaluasi_penerimaan($result[$i]['kode_pka'])->result_array();



            // if(rp)



            for($u=0; $u<count($rpn);$u++){



                $result[$i]['jml_penerimaan'] += $rpn[$u]['penerimaan'];



            }



        }



        $d['result'] = $result;



        $this->load->view('laporan/v_laporan_pka_ev_excel',$d);



    }



}