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

class Mumat extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();
		
		$this->pmodul = 'mumat';
		$this->modul = 'mumat';
		
		$this->title = 'LAPORAN MUTASI BAHAN BAKU DAN BAHAN PENOLONG';
		$this->mat_type = '1';
		$this->tp_barang = "IN ('1','2')";
		
		$this->load->model($this->pmodul.'/'.$this->pmodul.'_mdl','pmdl');
		$this->load->model($this->modul.'_mdl','mdl');
		
	}

	public function index()
	{		
		$data = array(
			'content' 	=> 	$this->pmodul.'/'.$this->pmodul,
			);	
		// print_r($data);exit();	
		$this->load('tpl',$data['content'], $data);
		$this->load->view($this->pmodul.'/'.$this->pmodul.'_cjs');
		$this->load->view($this->pmodul.'/'.$this->pmodul.'_mjs');
		
	}
	
	function aksi($cmd)
	{
		// echo 'fff';exit();
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 9999;	
		$key = $_REQUEST["q"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$kd_cmpy = $_REQUEST["kd_cmpy"];
		$rs = $this->mdl->getAll2($page,$rows,$key,$dtdari,$dtsampai,$kd_cmpy);
		$rsl = $this->mdl->getAll2($page,$rows,$key,$dtdari,$dtsampai,$kd_cmpy);
		
		if ($cmd=='cari'){
			echo json_encode($rs);
		} else {
			$data = array(
				'rs' 	=> 	$rsl,
				'dtdari' 	=> 	$dtdari,
				'dtsampai' 	=> 	$dtsampai
			);	
			
			if ($cmd=='excel'){
				$filename =$this->title.".xls";
				header('Content-type: application/ms-excel');
				header('Content-Disposition: attachment; filename='.$filename);
			}
			$this->load->view($this->pmodul.'/print',$data);
		}
		
	}
}