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

class Ceisatpb extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();
		
		$this->load->model('ceisatpb_mdl','mdl');
		$this->title = 'Ceisa TPB Integration';
	}
	
	public function index()
	{		
		$data = array(
			'title' 	=> 	$this->title,
			'content' 	=> 	'index',
			);		
		$this->load('tpl',$data['content'], $data);
		$this->load->view('ceisatpb/_cjs');
		$this->load->view('ceisatpb/_mjs');
		
	}
	
	function grid(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];		
		$KdJnsDok = $_REQUEST["KdJnsDok"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$rs = $this->mdl->getAll($page,$rows,$key,$KdJnsDok,$dtdari,$dtsampai);
		
		echo json_encode($rs);
	}
	
	function cetak()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$KdJnsDok = $_REQUEST["KdJnsDok"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'rs' 	=> 	$this->mdl->getAll($page,$rows,$key,$KdJnsDok,$dtdari,$dtsampai),
		);	
		
		$this->load->view('ceisatpb/print',$data);
		
	}
	
	function excel()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$KdJnsDok = $_REQUEST["KdJnsDok"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'rs' 	=> 	$this->mdl->getAll($page,$rows,$key,$KdJnsDok,$dtdari,$dtsampai),
		);
		
		$filename =$this->title2.date('Ymd').".xls";
		header('Content-type: application/ms-excel');
		header('Content-Disposition: attachment; filename='.$filename);
		$this->load->view('ceisatpb/print',$data);
	}
}