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

class Hasilses extends CI_Controller {


	public function __construct()
    {
        parent::__construct();
		$this->load->model('User_model');
        $this->load->model('Hasil_forecast_model');
		is_logged_in();
    }
	public function index()
	{
		$data['nama'] = "Hasil Single Exponential Smooting";
		$id_user=$this->session->userdata('id_user');
        $data['user']=$this->User_model->get_user($id_user);

        $data['jenis'] = $this->db->get('jenis_kopi')->result();

        $this->load->view('Templates/header.php', $data);
        $this->load->view('Templates/navbar.php', $data);
        $this->load->view('Templates/leftmenu.php', $data);
        $this->load->view('Hasil_SES/index.php', $data);
		$this->load->view('Templates/footer.php', $data);
	
    }

    public function result()
	{
        $jeniskopi = $this->input->post('jenis', true);
		$data['nama'] = "Hasil Single Exponential Smooting";
		$id_user=$this->session->userdata('id_user');
        $data['user']=$this->User_model->get_user($id_user);

        $data['jeniskopi']= $jeniskopi;


        $data['at']=$this->Hasil_forecast_model->get_at($jeniskopi);
        $data['ft']=$this->Hasil_forecast_model->get_ft($jeniskopi);
        $data['bulan']=$this->Hasil_forecast_model->get_bulan($jeniskopi);
        $data['hitung_ses1']=$this->Hasil_forecast_model->get_allses($jeniskopi);
        $data['mse'] = $this->Hasil_forecast_model->mse($jeniskopi);
        $data['rmse'] = number_format(sqrt($this->Hasil_forecast_model->mse($jeniskopi)),2);
        $data['mad'] = $this->Hasil_forecast_model->get_mad($jeniskopi);
        $data['mape'] = $this->Hasil_forecast_model->get_mape($jeniskopi);
        $data['bulan_selanjutnya'] = $this->Hasil_forecast_model->bulan_berikut($jeniskopi);

        $data['countall'] = $this->Hasil_forecast_model->count_mse($jeniskopi);

        $this->db->select('*');
        $this->db->from('jumlah_forecasting');
        $this->db->where('id',1);
        $totaldibuka = $this->db->get()->row_array();

        $totalresult = $totaldibuka['total'] + 1;

        $this->db->set('total', $totalresult);
        $this->db->where('id',1);
        $update = $this->db->update('jumlah_forecasting');

        $this->load->view('Templates/header.php', $data);
        $this->load->view('Templates/navbar.php', $data);
        $this->load->view('Templates/leftmenu.php', $data);
        $this->load->view('Hasil_SES/result.php', $data);
		$this->load->view('Templates/footer.php', $data);
	
    }
   
}