<?php

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

class Asam_amino extends MY_Controller {

    protected $template = "app";
    protected $module = "asam_amino";

    protected $kode_batch = "";
    protected $param_uji = "";
    protected $id_parameter_uji = "";

    protected $per_page = 20;

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

    public function index() {
        $vget = $this->input->get();
        $this->data['halaman']     = "Asam Amino";
        $this->data['sub_halaman'] = '';
        $this->data['idGroup']     = $this->id_group;
        $this->data['vget']        = $vget;
        $this->data['lhp_amino']   = $this->m_amino->get_lhp_amino($vget['id_uji']);

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

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

    public function create_edit($id=null){
        $this->data['halaman'] = "Tambah Asam Amino";
        $this->data['sub_halaman'] = '';
        $this->data['idGroup'] = $this->id_group;
        $this->data['vget'] = $vget = $this->input->get();

        if(!is_null($id)){
            $this->data['edit'] = $this->m_amino->get_amino($vget['id_uji']);
        }

        if($this->input->post()){
            $data = $this->input->post();
            $wp = explode(' ', str_replace('/', ' ', $data['waktu_tanggal_persetujuan']));
            $wp = $wp[2].'-'.$wp[1].'-'.$wp[0].' '.$wp[3];
            $data['waktu_tanggal_persetujuan']  = strtotime($wp);
            if(!is_null($id)){
            $status = $this->m_amino->set_amino($data, $id);
            }else{
            $status = $this->m_amino->set_amino($data);
            }

            if($status){
            $this->session->set_flashdata('msg', 'Data Persetujuan Asam Amino berhasil disimpan');
            }else{
            $this->session->set_flashdata('msgw', 'Data Persetujuan Asam Amino berhasil disimpan');
        }

        redirect('sampel/asam_amino?id_uji='.$vget['id_uji'].'&status=11');
    }

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

    public function lhp_amino($id=null){
    $this->data['halaman'] = "LHP Amino";
    $this->data['sub_halaman'] = '';
    $this->data['idGroup'] = $this->id_group;
    $this->data['vget'] = $vget = $this->input->get();

    if($this->input->post()){
        $data = $this->input->post();
        //print('<pre>'.print_r($data, true).'</pre>'); die();
        
        if(is_null($id)){
        $status = $this->m_amino->set_lhp_amino($data);
        }else{
        $status = $this->m_amino->set_lhp_amino($data, $id);
        } 
        
        if($status) {
        echo 'sukses';
        }else {
        echo 'gagal';
        }

        redirect('sampel/asam_amino?id_uji='.$vget['id_uji'].'&status=11');
    }

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