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

require_once APPPATH . "third_party/vendor/autoload.php";


use Dompdf\Dompdf;

class Excel extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
		$this->load->model('User_model');
        $this->load->model('Alpha_model');
		$this->load->model('Hasil_forecast_model');
        $this->load->model('Data_kopi_model');
        $this->load->model('Jenis_model');
		is_logged_in();
    }

    public function exportkopi()
	{
        $dompdf = new Dompdf();

        $data['title'] = 'Export Produksi Kopi';
        $data['data_kopi']=$this->Data_kopi_model->get_all_data_kopi();
        $html = $this->load->view('excel/kopi', $data, TRUE);

        $dompdf->load_html($html);

        $dompdf->render();

        $dompdf->stream('Produksi-Kopi '.date('Y-m-d').'.pdf');
    }

	public function exportjenis()
	{
        $dompdf = new Dompdf();

        $data['title'] = 'Export Jenis Kopi';
        $data['jenis_kopi']=$this->Jenis_model->get_all_data();
        $html = $this->load->view('excel/jeniskopi', $data, TRUE);

        $dompdf->load_html($html);

        $dompdf->render();

        $dompdf->stream('Jenis-Kopi '.date('Y-m-d').'.pdf');
    }

    public function exportresult($jeniskopi)
	{
        $dompdf = new Dompdf();

        $data['title'] = 'Export Hasil Forecasting';

        $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);

        $html = $this->load->view('excel/result', $data, true);

        $dompdf->load_html($html);

        $dompdf->render();

        $dompdf->stream('Data-Forecasting '.date('Y-m-d').'.pdf');
    }
}