<?php


class Dashboard_admin extends CI_Controller{
	public function __construct(){
		parent::__construct();

		if($this->session->userdata('role_id') != '1'){
			$this->session->set_flashdata('pesan','<div class="alert alert-danger alert-dismissible fade show" role="alert">
				  Anda Belum Login!
				  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
				  <span aria-hidden="true">&times; </span>
				  </button>
				</div>');
			redirect('auth/login');
		}
	}

	public function index()
	{
		$tgl[1] = (string)$this->input->post('tgl1');
		$tgl[2] = $this->input->post('tgl2');
		$uri = $this->input->post('uri');
		if($tgl[1] !=null && $tgl[2] !=null){
			$pencarian = $this->db->query("SELECT * FROM tb_invoice WHERE tgl_pesan BETWEEN '$tgl[1]' AND '$tgl[2]'")->result();
		}else if($tgl[1] !=null){
			$tgl[2]=mdate('%Y-%m-%d',now());
			$pencarian = $this->db->query("SELECT * FROM tb_invoice WHERE tgl_pesan BETWEEN '$tgl[1]' AND '$tgl[2]'")->result();
		}else{
			$pencarian = $this->model_invoice->tampil_data();
		}
 		$data = [
			'str'=>'dashboard',
			'invoice' => $pencarian,
			'ket'=>''
		];
		$this->load->view('templates_admin/header');
		$this->load->view('templates_admin/sidebar',$data);
		$this->load->view('admin/dashboard',$data);
		$this->load->view('templates_admin/footer');
	}
}
 

  //class Invoice extends CI_Controller{
	// public function __construct(){
	// 	parent::__construct();

	// 	if($this->session->userdata('role_id') != '1'){
	// 		date_default_timezone_set('Asia/Jakarta');
	// 		$this->session->set_flashdata('pesan','<div class="alert alert-danger alert-dismissible fade show" role="alert">
	// 			  Anda Belum Login!
	// 			  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
	// 			  <span aria-hidden="true">&times; </span>
	// 			  </button>
	// 			</div>');
	// 		redirect('auth/login');
	// 	}
	// }
 // 	public function index()
 // 	{
	// 	$tgl[1] = (string)$this->input->post('tgl1');
	// 	$tgl[2] = $this->input->post('tgl2');
	// 	$uri = $this->input->post('uri');
	// 	if($tgl[1] !=null && $tgl[2] !=null){
	// 		$pencarian = $this->db->query("SELECT * FROM tb_invoice WHERE tgl_pesan BETWEEN '$tgl[1]' AND '$tgl[2]'")->result();
	// 	}else if($tgl[1] !=null){
	// 		$tgl[2]=mdate('%Y-%m-%d',now());
	// 		$pencarian = $this->db->query("SELECT * FROM tb_invoice WHERE tgl_pesan BETWEEN '$tgl[1]' AND '$tgl[2]'")->result();
	// 	}else{
	// 		$pencarian = $this->model_invoice->tampil_data();
	// 	}
 // 		$data = [
	// 		'str'=>'dashboard',
	// 		'invoice' => $pencarian
	// 	];
 // 		$this->load->view('templates_admin/header');
 // 		$this->load->view('templates_admin/sidebar', $data);
 // 		$this->load->view('admin/invoice', $data);
 // 		$this->load->view('templates_admin/footer');
 // 	}
	//  