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

class Welcome extends CI_Controller {

	function __construct(){
        parent::__construct();
      
         $this->load->model('live_model');
         $this->load->helper('content');
    }


    function index(){
    	set_time_limit(0);
        ini_set('memory_limit', '1024M');

        $view['error'] = '';
        $view['content'] = 'admin\home';
        $view['data'] = $this->live_model->view_thamrin()->result();
        $view['resultstb']    =   $this->live_model->show_ruangan();
        $view['table_now'] = $this->live_model->show_table_now();
        $view['resultstotal'] = $this->live_model->show_total_ranap();

        //$a = $this->load->database('default', TRUE);
        //$c = $this->load->database('salemba', TRUE);
        $this->load->view('index', $view);
    }

    public function view_thamrin(){
	    $data['data'] = $this->live_model->view_thamrin();
    }

    public function chart_kunjungan_debitur() {
        $view['content'] = 'chart/indikator_rs';
        $view['uri'] = 'chart_kunjungan_debitur/'.$this->uri->segment('3');
        $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Debitur - '.date('Y');
        $view['data'] = $this->live_model->chart_get_kunjungan_debitur()->result();
        $view['tahun'] = date('Y');
        if(isset($_POST['filter'])){
            $tahun = $_POST['tahun'];
            $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Debitur - '.$tahun;
            $view['data'] = $this->live_model->chart_get_kunjungan_debitur_by_tahun($tahun)->result();
        }
        $this->load->view('index', $view);
    }



    public function chart_kunjungan_poliklinik() {
        $view['content'] = 'chart/indikator_rs';
        $view['uri'] = 'chart_kunjungan_poliklinik/'.$this->uri->segment('3');
        $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Poliklinik - '.date('Y');
        $view['data'] = $this->live_model->chart_get_kunjungan_poliklinik()->result();
        $view['tahun'] = date('Y');
        if(isset($_POST['filter'])){
            $tahun = $_POST['tahun'];
            $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Poliklinik - '.$tahun;
            $view['data'] = $this->live_model->chart_get_kunjungan_poliklinik_by_tahun($tahun)->result();
        }
        $this->load->view('index', $view);
    }

    public function chart_kunjungan_penunjang_medis() {
        $view['content'] = 'chart/indikator_rs';
        $view['uri'] = 'chart_kunjungan_penunjang_medis/'.$this->uri->segment('3');
        $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Penunjang Medis - '.date('Y');
        $view['data'] = $this->live_model->chart_get_kunjungan_penujang_medis()->result();
        $view['tahun'] = date('Y');
        if(isset($_POST['filter'])){
            $tahun = $_POST['tahun'];
            $view['title'] = 'Kunjungan Rawat Jalan Berdasarkan Penunjang Medis - '.$tahun;
            $view['data'] = $this->live_model->chart_get_kunjungan_penujang_medis_by_tahun($tahun)->result();
        }
        $this->load->view('index', $view);
    }

    public function chart_barberjohnson() {
        $view['content'] = 'chart/indikator_rs';
        $view['uri'] = 'chart_barberjohnson/'.$this->uri->segment('3');
        $view['title'] = 'Indikator RS - '.date('Y');
        $view['data'] = $this->live_model->chart_get_barberjohnson()->result();
        $view['tahun'] = date('Y');
        if(isset($_POST['filter'])){
            $tahun = $_POST['tahun'];
            $view['title'] = 'Indikator RS - '.$tahun;
            $view['data'] = $this->live_model->chart_get_barberjohnson_by_tahun($tahun)->result();
        }
        $this->load->view('index', $view);
    }

    function search_tanggal()
    {
        $start = $this->input->post('tanggal');
        $startformat = date("d F Y", strtotime($start));
        $finish = $this->input->post('tanggal_to');
        $finishformat = date("d F Y", strtotime($finish));

        $data['data'] = $this->live_model->view_thamrin()->result();
        $data['content'] = 'table/tbl_home_kunjungan';
        $data['uri'] = 'chart_kunjungan_poliklinik/'.$this->uri->segment('3');
        $data["tanggal_from"] = $startformat;
        $data["tanggal_last"] = $finishformat;
        $tanggal    =   $this->input->post('tanggal');
        $tanggal_to = $this->input->post('tanggal_to');
        $data['resultstb']    =   $this->live_model->show_ruangan();
        $data['results']    =   $this->live_model->show_poliklinik($tanggal,$tanggal_to);
        $this->load->view('index',$data);
    }

    function search_tanggal_dokter()
    {
        $start = $this->input->post('tanggal');
        $startformat = date("d F Y", strtotime($start));
        $finish = $this->input->post('tanggal_to');
        $finishformat = date("d F Y", strtotime($finish));

        $data['data'] = $this->live_model->view_thamrin()->result();
        $data['content'] = 'table/tbl_home_dokter';
        $data['uri'] = 'dokter_poliklinik/'.$this->uri->segment('3');
        $data["tanggal_from"] = $startformat;
        $data["tanggal_last"] = $finishformat;
        $tanggal    =   $this->input->post('tanggal');
        $tanggal_to = $this->input->post('tanggal_to');
        $data['resultstb']    =   $this->live_model->show_ruangan();
        $data['results']    =   $this->live_model->show_dokter_rajal($tanggal,$tanggal_to);
        $this->load->view('index',$data);
    }

    function tampil_table()
    {
        $start = $this->input->post('tanggal');
        $startformat = date("d F Y", strtotime($start));
        $finish = $this->input->post('tanggal_to');
        $finishformat = date("d F Y", strtotime($finish));

        $data['data'] = $this->live_model->view_thamrin()->result();
        $data['content'] = 'table/tbl_home';
        $data['uri'] = 'tampil_table/'.$this->uri->segment('3');
        $data["tanggal_from"] = $startformat;
        $data["tanggal_last"] = $finishformat;
        $tanggal    = $this->input->post('tanggal');
        $tanggal_to = $this->input->post('tanggal_to');
        $data['resultstb']    =   $this->live_model->show_ruangan();
 $data['tgl_value_from']    = $this->input->post('tanggal');
        $data['tgl_value_last'] = $this->input->post('tanggal_to');       $data['table']    =   $this->live_model->show_table($tanggal,$tanggal_to);
        $this->load->view('index',$data);
    }
}
