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

class Resume extends CI_Controller
{
  function __construct()
  {
    parent::__construct();
    $this->load->model('Form_batubara_proses_model');
    $this->load->model('Blok_fee_model');
    $this->load->model('Fee_rate_model');
    $this->load->model('Driver_hauling_model');

    $this->data['module'] = 'Laporan Resume';
    if ($this->session->userdata('status') != "login") {
      redirect(base_url("login"));
    }
    if ($this->session->userdata('level') != "0" and $this->session->userdata('level') != "2") {
      redirect(base_url('error'));
    }
  }

  public function index()
  {
    $this->data['title'] = 'Data ' . $this->data['module'];
    $this->data['active'] = 'resume';
    $this->load->view('resume/resume', $this->data);
  }



  public function report()
  {
    ob_start();
    $tanggal_report_awal = $this->input->post('tanggal_report_awal');
    $tgl1 = substr($tanggal_report_awal, 0, 2);
    $bln1 = substr($tanggal_report_awal, 3, 2);
    $thn1 = substr($tanggal_report_awal, 6, 4);
    $tanggal_report_awal = "$thn1-$bln1-$tgl1";

    $tanggal_report_akhir = $this->input->post('tanggal_report_akhir');
    $tgl1 = substr($tanggal_report_akhir, 0, 2);
    $bln1 = substr($tanggal_report_akhir, 3, 2);
    $thn1 = substr($tanggal_report_akhir, 6, 4);
    $tanggal_report_akhir = "$thn1-$bln1-$tgl1";

    $this->data['pendapatan'] =  $this->Form_batubara_proses_model->get_resume($tanggal_report_awal, $tanggal_report_akhir);
    //$this->data['biaya_lain'] =  $this->Form_biaya_lain_model->get_resume($tanggal_report_awal, $tanggal_report_akhir)->biaya_lain;

    $this->data['tanggal_report_awal'] = $tanggal_report_awal;
    $this->data['tanggal_report_akhir'] = $tanggal_report_akhir;
    $this->load->view('resume/report', $this->data);

    $html = ob_get_contents();
    //      $html = '<title style="font-family: freeserif">'.nl2br($html).'</title>';
    ob_end_clean();

    require_once('application/libraries/html2pdf/html2pdf.class.php');
    $pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(15, 15, 15, 15));
    $pdf->setDefaultFont('Arial');
    $pdf->setTestTdInOnePage(false);
    $pdf->WriteHTML($html);
    $pdf->Output('Resume.pdf');
  }
}
