<?php

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

    require './vendor/autoload.php';

class Pengajuan extends MY_Controller {

    protected $template = "app";
    protected $module = "pengajuan";
    protected $per_page = 20;
    protected $url_uji = 'uji_air';

    public function __construct() {
        parent::__construct();
        $this->load->model('m_disposisi');
        $this->load->model('m_master');

    }

    public function index() {
        $this->data['halaman'] = "Disposisi";
        $this->data['sub_halaman'] = '';
        $this->data['idGroup'] = $this->idGroup;
        $this->data['parameter_uji'] = $this->m_master->getDataMaster('parameter_uji');
        $this->data['keterangan'] = $this->m_master->getDataMaster('gol_jenis_sampel');
        $this->data['penanganan_sampel'] = $this->m_master->getDataMaster('penanganan_sampel');
        $this->data['role_analis'] = $this->roleAnalis;

        if(!empty($this->input->post('filter_cari'))){
          $this->data['filter'] = $this->input->post();
        }

        $total_data = $this->m_disposisi->getDataUji(true);
        $this->data['total_data'] = $total_data;

        //CONFIG PAGINATION
        $this->load->library('pagination');

        $url = site_url('sampel/pengajuan/index');
        $per_page = $this->per_page;
        $uri_segment = 3;

        $this->data['link_paging'] = $this->paging->set_paging2($url, $total_data, $per_page,$uri_segment);
        if ($this->uri->segment($uri_segment)) {
            $this->cur_page = $page = $this->uri->segment($uri_segment);
        } else {
            $this->cur_page = $page = 0;
        }

        $this->data['per_page']     = $per_page;
        $this->data['data']         = $this->m_disposisi->getDisposisi(false, $per_page, $page);//

        //END CONFIG PAGINATION

        $this->render('index');
    }

    function disposisi_history() {
        $this->data['halaman'] = "Data History";
        $this->data['sub_halaman'] = '';
        $this->data['idGroup'] = $this->idGroup;

        $total_data = $this->m_disposisi->getDataUji(true);
        $this->data['total_data'] = $total_data;

        //CONFIG PAGINATION
        $this->load->library('pagination');

        $url = site_url('sampel/pengajuan/disposisi_history');
        $per_page = $this->per_page;
        $uri_segment = 3;

        $this->data['link_paging'] = $this->paging->set_paging2($url, $total_data, $per_page,$uri_segment);
        if ($this->uri->segment($uri_segment)) {
            $this->cur_page = $page = $this->uri->segment($uri_segment);
        } else {
            $this->cur_page = $page = 0;
        }

        $this->data['per_page']     = $per_page;
        $this->data['data']         = $this->m_disposisi->getDisposisi(false, $per_page, $page, null, true);
        //END CONFIG PAGINATION

        $this->render("disposisi_history");
    }

    public function penyiapan_sampel() {
        $this->data['halaman'] = "Penyiapan Sampel";
        $this->data['sub_halaman'] = '';
        $this->data['bentuk_sampel'] = $this->m_master->getDataMaster('bentuk_sampel');
        $this->data['penanganan_arsip'] =$this->m_master->getDataMaster('jenis_penanganan_sampel', 'arsip');
        $this->data['penanganan_kerja'] = $this->m_master->getDataMaster('jenis_penanganan_sampel', 'kerja');
        $this->data['sampel_kerja'] = $this->m_master->getDataMaster('penyimpanan_sampel');
        $this->data['sampel_arsip'] = $this->m_master->getDataMaster('penyimpanan_sampel');
        $this->data['grinder'] = $this->m_master->getDataMaster('jenis_grinder');

        $this->data['id_sampel'] = $id_sampel = $this->input->get('id_sampel');
        $id_uji = $this->input->get('id_uji');
        $id_status = $this->input->get('status');
        $this->data['edit'] = $this->m_disposisi->getEditSampel($id_sampel);

        $data = $this->input->post();

        if($data){
            if(in_array($this->idGroup, array('1', '8'))){
                $data['pukul_mulai'] = toi_time01($data['pukul_mulai']);
                $data['pukul_selesai'] = toi_time01($data['pukul_selesai']);

                $id_bentuk_sampel = null;
                if($data['id_bentuk_sampel'] === '1' || $data['id_bentuk_sampel'] === 'Cair') $id_bentuk_sampel = 1;
                if($data['id_bentuk_sampel'] === '2' || $data['id_bentuk_sampel'] === 'Padat'){
                    if(!empty($data['bentuk_padat']) && isset($data['bentuk_padat'])){
                        $id_bentuk_sampel = '';
                        $x = count($data['bentuk_padat']);
                        for ($i=0; $i < $x; $i++) {
                            $id_bentuk_sampel .= $data['bentuk_padat'][$i].'|';
                        }
                    }
                }

                $id_sampel = null;
                if($data['id_sampel'] != '' && isset($data['id_sampel'])) $id_sampel = $data['id_sampel'];

                //var_dump($data); die();
                $data2 = array(
                  'id_sampel_kerja' => $data['id_sampel_kerja'],
                  'id_sampel_arsip' => $data['id_sampel_arsip'],
                  'berat_sampel' => $data['berat_sampel'],
                  'satuan_berat' => $data['satuan_sampel'],
                  'kemasan' => $data['kemasan'],
                  'id_sampel' => $id_sampel
                );

                $data = array(
                    'pukul_mulai' => $data['pukul_mulai'],
                    'pukul_selesai' => $data['pukul_selesai'],
                    'id_bentuk_sampel' => $id_bentuk_sampel,
                    'id_penanganan_arsip' => $data['id_penanganan_arsip'],
                    'id_penanganan_kerja' => $data['id_penanganan_kerja'],
                    'id_jenis_grinder' => $data['id_jenis_grinder'],
                    'keterangan' => $data['keterangan'],
                    'last_modified_user' => $this->idUser,
                    'ket_penanganan_kerja' => ($data['id_penanganan_kerja'] == 5) ? $data['ket_penanganan_kerja'] : null,
                    'id_sampel' => $id_sampel
                );

                $status = $this->m_disposisi->penyiapan_sampel($data);

                if($status){
                  $status = $this->m_disposisi->update_disposisi($data2);
                }

                if($status){
                    $msg = 'Sampel berhasil disiapkan';
                    $this->session->set_flashdata('msg', $msg);
                }else{
                    $msg = 'Sampel gagal disiapkan';
                    $this->session->set_flashdata('msgw', $msg);
                }
                redirect("sampel/pengajuan/penyiapan_uji?id_uji=".$id_uji.'&status='.$id_status);
            }
        }

        $this->render("penyiapan_sampel");
    }

    public function penyiapan_uji(){
        $this->data['halaman'] = "Penyiapan Uji Sampel";
        $this->data['sub_halaman'] = '';
        $data = $this->input->get();

        if(isset($data['id_uji'])){
            $this->data['data'] = $this->m_disposisi->penyiapanUji($data['id_uji']);
            $this->data['id_uji'] = $data['id_uji'];
            $this->data['status'] = $data['status'];

            if(!empty($data['status'])){
                $this->data['idStatus'] = $data['status'];
            }
        }

        $this->render("penyiapan_uji");
    }

    function siapkan_sampel(){
        $data = $this->input->get();

        if($data['status'] == 8){
          $this->m_disposisi->set_tgl_persetujuan($data['id_uji']);
        }
        if($data['status'] !== '0'){
            $param = array(
                'id_uji' => $data['id_uji'],
                'id_status' => $data['status'],
                'id_user'=> $this->idUser
            );
            $status = $this->m_disposisi->siapkanSampel($param);
            $msg = 'Penyiapan Sampel Berhasil';
        }else if($data['status'] === '0'){
            $status = $this->m_disposisi->deletePenyiapanSampel($data['id_uji']);
            $msg = 'Penyiapan Sampel Dihapus';
        }

        if($status){
            $this->session->set_flashdata('msg', $msg);
        }else{
            $msg = 'Sampel gagal disiapkan';
            $this->session->set_flashdata('msgw', $msg);
        }
        redirect("sampel/pengajuan");
    }

    public function mulai_uji_sampel() {
        $this->module = 'uji_analis';
        $this->data['halaman'] = "Uji Analis";
        $this->data['sub_halaman'] = '';
        $this->data['get'] = $data = $this->input->get();
        $this->data['data'] = $this->m_disposisi->getAnalis($data);
        $this->render('index');
    }

    public function verifikasi_penyelia() {
      $this->module = 'uji_analis';
      $this->data['halaman'] = "Uji Analis";
      $this->data['sub_halaman'] = '';
      $this->data['idGroup'] = $this->idGroup;
  		$this->data['get'] = $data = $this->input->get();
  		$this->data['data'] = $this->m_disposisi->getAnalis($data);
      $this->render('index');
    }

    public function lhp(){
        $this->module = "lhu_lhp";
        $this->data['halaman'] = 'LHP';
        $this->data['sub_halaman'] = '';
		    $this->data['get'] = $data = $this->input->get();
		    $this->data['data'] = $this->m_disposisi->getAnalis($data);
        $this->render('lhp');
    }

    public function lhu(){
        $this->module = "uji_analis";
        $this->data['halaman'] = 'LHU';
        $this->data['sub_halaman'] = '';
        $this->data['get'] = $data = $this->input->get();
		$this->data['data'] = $this->m_disposisi->getAnalis($data);
        $this->render('index');
    }

    public function tdn(){
      $this->module = "lhu_lhp";
      $this->data['halaman'] = 'TDN';
      $this->data['sub_halaman'] = '';
      $this->data['get'] = $dget = $this->input->get();
      $this->data['data'] = $this->m_disposisi->get_tdn($dget);

      if($this->input->post()){
        $data = $this->input->post();
        $data_key = array_keys($data);

        $param = $this->tdn_perulangan1($data, $data_key);//mengubah sturktur array dari brdsrkan jenis k id
        //print('<pre>'.print_r($param, true).'</pre>'); die();
        $param = $this->tdn_perulangan2($param, $data_key);// digunakan untuk menampilkan 2 angka d blkng koma(,)

        $status = '';
        foreach($param as $p){
          $p = array_reverse($p);
          $key = array_keys($p);
          $pkey['insert'] =  $pkey['insert_p']= $pkey['update'] = '';

          foreach($key as $k){
            $pkey['insert'] .= $k.',';
            $pkey['insert_p'] .= '?,';

            if($k != 'id_sampel'){
              $pkey['update'] .= $k.'=?,';
            }
          }

          $pkey['insert'] = substr($pkey['insert'],0,-1);
          $pkey['insert_p'] = substr($pkey['insert_p'],0,-1);
          $pkey['update'] = substr($pkey['update'],0,-1);
          $pkey['update_p'] = 'id_sampel = ?';

          //print("<pre>".print_r($pkey, true)."</pre?"); die();
          $status .=  $this->m_disposisi->set_tdn($p, $pkey);
        }

        if(strpos($status, 'gagal') == false){
          $msg = 'TDN berhasil diupdate';
          $this->session->set_flashdata('msg', $msg);
        }else{
          $msg = 'TDN gagal diupdate';
          $this->session->set_flashdata('msg', $msg);
        }
        redirect("sampel/pengajuan/tdn?id_uji=".$dget['id_uji']."&status=".$dget['status']);
      }

      $this->render('tdn');
    }

    function tdn_perulangan1($data, $data_key){
      $param = array();
      $x = count($data['id_sampel']);
      for ($i=0; $i < $x; $i++) {
        foreach($data_key as $dk){
          $tdn = (float)$data[$dk][$i];

          if($dk == 'id_sampel'){
            $param[$i][$dk] = $tdn;
          }else{
            if($dk == 'air') $tdn = 100-$tdn;
            else $tdn = 100/$param[$i]['bk_air']*$tdn;

            $param[$i]['bk_'.$dk] = round($tdn, 2);
          }
        }

        $p = $param[$i];
        $p['bk_betn'] = 100-($p['bk_abu']+$p['bk_protein_kasar']+$p['bk_lemak_kasar']+$p['bk_serat_kasar']);
        $p['bk_tdn'] = 5.31 + (0.412 * $p['bk_protein_kasar']) + (0.249 * $p['bk_serat_kasar']) + (1.444 * $p['bk_lemak_kasar']) + (0.937 * $p['bk_betn']);
          //5,31 + 0,412 x PK + 0,249 x SK + 1,444 x LK + 0,937 x BETN

        $param[$i] = $p;
      }

      return $param;
    }

    function tdn_perulangan2($param, $data_key){
      $data_key[] = 'betn';
      $data_key[] = 'tdn';
      $s = 0;
      foreach($param as $pa){
        foreach ($data_key as $k) {
          if($k != 'id_sampel'){
            if(strpos($pa['bk_'.$k], '.') != false){
              $pa['bk_'.$k] = explode('.', $pa['bk_'.$k]);
              $pa['bk_'.$k][1] = substr($pa['bk_'.$k][1],0,2);
              $pa['bk_'.$k] = $pa['bk_'.$k][0].'.'.$pa['bk_'.$k][1];

              $param[$s]['bk_'.$k] = $pa['bk_'.$k];
            }
          }
        }
        $s++;
      }

      return $param;
    }

    public function kadar_air_total(){
      $this->module = "lhu_lhp";
      $this->data['halaman'] = 'Kadar Air';
      $this->data['sub_halaman'] = '';
      $this->data['get'] = $dget = $this->input->get();
      $this->data['data'] = $this->m_disposisi->get_kadar_air_total($dget);

      if($this->input->post()){
        $data = $this->input->post();
        for($i=0; $i < count($data['id_sampel']); $i++){
          if(isset($data['kadar_air1'][$i]) && isset($data['kadar_air2'][$i])){
            $ka1 = isset($data['kadar_air1'][$i]) && $data['kadar_air1'][$i] != '' ? (float)$data['kadar_air1'][$i] : 0;
            $ka2 = isset($data['kadar_air2'][$i]) && $data['kadar_air2'][$i] != '' ? (float)$data['kadar_air2'][$i] : 0;

            $ka3 = $ka1+(((100-$ka1)/100)*$ka2);

            $param['kadar_air3'] = $ka3;
            $param['pj_air3'] = $this->uname;
            $param['id_sampel'] = $data['id_sampel'][$i];

            $status = $this->m_disposisi->set_kat($param);
          }
        }
        redirect("sampel/pengajuan/kadar_air_total?id_uji=".$dget['id_uji']."&status=".$dget['status']);
      }

      $this->render('kadar_air');
    }

    public function deret_fosfor() {
      $this->module = "uji_analis";
      $this->data['halaman'] = 'Deret Fosfor';
      $this->data['sub_halaman'] = '';
      $this->data['vget'] = $vget = $this->input->get();
      var_dump($vget); die();
      $this->data['data'] = $this->m_disposisi->get_deret_fosfor();
      $this->render('deret_fosfor');
    }

    public function create_deret_fosfor() {
      $this->module = "uji_analis";
      $this->data['halaman'] = 'Form Deret Fosfor';
      $this->data['sub_halaman'] = '';
      $this->data['vpost'] = $vpost = $this->input->post();

      if($this->input->post()){
        $data = $this->input->post();
        $status = $this->m_disposisi->set_deret_fosfor($data);

        if($status) {
          $this->session->set_flashdata('msg', 'Data berhasil disimpan');
        } else {
          $this->session->set_flashdata('msgw', 'Data gagal disimpan');
        }
        redirect('sampel/pengajuan/deret_fosfor');
      }

      $this->render('create_deret_fosfor');
    }

    function verifikasi_analis(){
        $data = $this->input->get();
        if($data['status'] !== '0'){
            $param = array(
                'id_uji' => $data['id_uji'],
                'id_status' => $data['status'],
                'id_user'=> $this->idUser
            );
            $status = $this->m_disposisi->verifikasi_analis($param);
            $msg = 'Sampel Berhasil Dianalisis';
        }

        if($status){
            $this->session->set_flashdata('msg', $msg);
        }else{
            $msg = 'Sampel gagal disiapkan';
            $this->session->set_flashdata('msgw', $msg);
        }
        redirect("sampel/pengajuan");
    }

    function tolak_deputi() {
        $data = $this->input->post();
        $status = $this->m_disposisi->tolak_deputi($data);
        if($status){
            $msg = 'Sampel Berhasil Ditolak';
            $this->session->set_flashdata('msg', $msg);
        }else{
            $msg = 'Sampel gagal ditolak';
            $this->session->set_flashdata('msgw', $msg);
        }
        redirect("sampel/pengajuan");
    }

    function save_uji_sampel(){
        $data = $this->input->post();
        $x = count($data['id_sampel']);
        for($i = 0; $i < $x; $i++){
            $param['id_sampel'] = $data['id_sampel'][$i];
            $param['air'] = $data['air'][$i];
            $param['abu'] = $data['abu'][$i];
            $param['protein_kasar'] = $data['protein_kasar'][$i];
            $param['lemak_kasar'] = $data['lemak_kasar'][$i];
            $param['serat_kasar'] = $data['serat_kasar'][$i];
            $param['kalsium'] = $data['kalsium'][$i];
            $param['fosfor'] = $data['fosfor'][$i];

            $param['tdn'] = $data['tdn'][$i];
            $param['ur'] = $data['ur'][$i];
            $param['af'] = $data['af'][$i];
            $param['andf'] = $data['andf'][$i];
            $param['mbm'] = $data['mbm'][$i];

            $param['mulai_uji_air'] = $data['mulai_uji_air'];
            $param['mulai_uji_abu'] = $data['mulai_uji_abu'];
            $param['mulai_uji_protein_kasar'] = $data['mulai_uji_protein_kasar'];
            $param['mulai_uji_lemak_kasar'] = $data['mulai_uji_lemak_kasar'];
            $param['mulai_uji_serat_kasar'] = $data['mulai_uji_serat_kasar'];
            $param['mulai_uji_kalsium'] = $data['mulai_uji_kalsium'];
            $param['mulai_uji_fosfor'] = $data['mulai_uji_fosfor'];

            $param['mulai_uji_tdn'] = $data['mulai_uji_tdn'];
            $param['mulai_uji_ur'] = $data['mulai_uji_ur'];
            $param['mulai_uji_af'] = $data['mulai_uji_af'];
            $param['mulai_uji_andf'] = $data['mulai_uji_andf'];
            $param['mulai_uji_mbm'] = $data['mulai_uji_mbm'];

            $param['selesai_uji_air'] = $data['selesai_uji_air'];
            $param['selesai_uji_abu'] = $data['selesai_uji_abu'];
            $param['selesai_uji_protein_kasar'] = $data['selesai_uji_protein_kasar'];
            $param['selesai_uji_lemak_kasar'] = $data['selesai_uji_lemak_kasar'];
            $param['selesai_uji_serat_kasar'] = $data['selesai_uji_serat_kasar'];
            $param['selesai_uji_kalsium'] = $data['selesai_uji_kalsium'];
            $param['selesai_uji_fosfor'] = $data['selesai_uji_fosfor'];

            $param['selesai_uji_tdn'] = $data['selesai_uji_tdn'];
            $param['selesai_uji_ur'] = $data['selesai_uji_ur'];
            $param['selesai_uji_af'] = $data['selesai_uji_af'];
            $param['selesai_uji_andf'] = $data['selesai_uji_andf'];
            $param['selesai_uji_mbm'] = $data['selesai_uji_mbm'];

            $param['last_modified_user'] = $this->idUser;

            $status[] = $this->m_disposisi->saveAnalis($param);
        }

        if($status){
            $msg = 'Sampel uji berhasi disimpan';
            $this->session->set_flashdata('msg', $msg);
        }else{
            $msg = 'Sampel uji gagal disimpan';
            $this->session->set_flashdata('msgw', $msg);
        }

        redirect("sampel/pengajuan/mulai_uji_sampel?id_uji=".$data['id_uji']."&status=".$data['status']);
    }

    function get_penanganan_sampel_arsip() {
        $type= $this->input->post('type');
        echo $this->m_disposisi->getPenangananSampelArsip($type);
    }

    function cetak_lhp() {
        $data = $this->input->get();
        $data_uji = $this->m_disposisi->dataUji($data['id_uji']);
        $data = $this->m_disposisi->getAnalis($data);

        $nomor_permintaan_uji = nomor_id($data_uji['id_uji']);

        if(count($data) > 1)
            $nomor_permintaan_uji .= ' ('.nomor_id($data[0]['id_sampel']).'-'.nomor_id($data[intval(count($data)-1)]['id_sampel']).')';
        else
            $nomor_permintaan_uji .= ' ('.$data[0]['id_sampel'].')';

        // var_dump(FCPATH.'assets/img/lab_pakan02.png');
        // echo $nomor_permintaan_uji;
        // print_r(count($data));
        // print('<pre>'.print_r($data, true).'</pre>');

        ##-----------------------------------------------------------------------------------
        ## Setting filename, pathfile and template directory
        $filename = DATE("YmdHis") . '_lhp.xlsx';
        $temp_dir = FCPATH . 'files/lhp/';
        if (!file_exists($temp_dir)) {
            mkdir($temp_dir, 0775, true); // create folder
        } else { // empty folder
            $files = glob($temp_dir.'*'); // get all file names
            foreach($files as $file){ // iterate files
                if(is_file($file)) unlink($file); // delete file
            }
        }
        $path_file = $temp_dir . $filename;
        if (!copy(FCPATH . 'template/template_lhp.xlsx', $path_file)) {
            //$this->session->set_flashdata('msgw', 'Gagal membuat file XLS!');
            //redirect('data_rumah');
        }
        ##---------------------------------------------------------------------------------

        ## Initialize phpsreadsheet
        $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path_file);
        $sheet = $spreadsheet->getActiveSheet();

        $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
            $path = FCPATH.'assets/img/lab_pakan02.png';
            $drawing->setName('Paid');
            $drawing->setDescription('Paid');
            $drawing->setPath($path);
            $drawing->setCoordinates('E2');
            $drawing->setWorksheet($spreadsheet->getActiveSheet());

        $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
            $path = FCPATH.'assets/img/lab_pakan01.png';
            $drawing->setPath($path);
            $drawing->setCoordinates('O2');
            $drawing->setWorksheet($spreadsheet->getActiveSheet());

        $x = 0;
        $row_data = 25;
        foreach ($data as $r) {
            $sheet->insertNewRowBefore($row_data + $x + 0, 1);
            $baris = $row_data + $x;
            $sheet->setCellValue("A" . $baris, $x + 1);
            $sheet->setCellValue('B' . $baris, nomor_id($r['id_sampel']));
            $sheet->setCellValue('D' . $baris, $r['nama_jenis'].'/'.$r['asal_sampel']);

            $sheet->setCellValue('F' . $baris, $r['l_air']);
            $sheet->setCellValue('G' . $baris, $r['kadar_air']);

            $sheet->setCellValue('H' . $baris, $r['l_abu']);
            $sheet->setCellValue('I' . $baris, $r['kadar_abu']);

            $sheet->setCellValue('J' . $baris, $r['l_protein_kasar']);
            $sheet->setCellValue('K' . $baris, $r['protein_kasar']);

            $sheet->setCellValue('L' . $baris, $r['l_lemak_kasar']);
            $sheet->setCellValue('M' . $baris, $r['lemak_kasar']);

            $sheet->setCellValue('N' . $baris, $r['l_serat_kasar']);
            $sheet->setCellValue('O' . $baris, $r['serat_kasar']);

            $sheet->setCellValue('P' . $baris, $r['l_kalsium']);
            $sheet->setCellValue('Q' . $baris, $r['kalsium']);

            $sheet->setCellValue('R' . $baris, $r['l_fosfor']);
            $sheet->setCellValue('S' . $baris, $r['fosfor']);

            $sheet->mergeCells("D".$baris.":E".$baris);
            $sheet->mergeCells("B".$baris.":C".$baris);

            $x++;
        }

        $sheet->setCellValue('Q14',': '.date('d/m/Y (H.i').' WIB)');
        $sheet->setCellValue('Q16',': '.$nomor_permintaan_uji);
        $sheet->setCellValue('Q17',': '.date('d/m/Y (H.i', strtotime('-2Day', strtotime(date('Y-m-d H:i')))).' WIB)');
        $sheet->setCellValue('Q18',': '.date('d/m/Y (H.i', strtotime('-1Day', strtotime(date('Y-m-d H:i')))).' WIB)');
        $sheet->setCellValue('Q19',': '.date('d/m/Y (H.i').' WIB)');

        $sheet->setCellValue('Q'.intval(29+count($data)),'Surabaya, '.date('d-m-Y'));

        $sheet->setCellValue('E14',': '.$data_uji['instansi_umum']);
        $sheet->setCellValue('E15',': '.$data_uji['alamat']);
        $sheet->setCellValue('E16',': '.$data[0]['gol_jenis_sampel']);
        $sheet->setCellValue('E17',': '.$data[0]['kualitas']);

        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
        $writer->save($path_file);

        $path = explode('\\', $path_file);
        $path = base_url().end($path);

        $path = explode('files', $path_file);
        $path = base_url().'files/'.end($path);

        $url ="https://view.officeapps.live.com/op/view.aspx?src=".$path;
        redirect($url);
    }

    function ket_lhu(){
      $data = $this->input->get();
      $status = $this->m_disposisi->set_intruksi($data);
      redirect('sampel/pengajuan/verifikasi_penyelia?id_uji='.$data['id_uji'].'&status='.$data['status']);
    }

}
