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

class Erpt_kstok_rm extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();
		
		$this->modul = 'erpt_kstok_rm';
		$this->title = 'Kartu Stok Bahan Baku';
		
		$this->load->model('erpt_kstok_rm_mdl','mdl');
		$this->load->model('bahanbaku/bahanbaku_mdl','bbmdl');
	}
	
	public function index()
	{		
		$data = array(
			'title' 	=> 	$this->title,
			'content' 	=> 	$this->modul.'/'.$this->modul,
			);		
		$this->load('tpl',$data['content'], $data);
		$this->load->view($this->modul.'/'.$this->modul.'_cjs');
		$this->load->view($this->modul.'/'.$this->modul.'_mjs');
		
	}
	
	function grid(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$prodcard_id = $_REQUEST["prodcard_id"];
		$lot_no = $_REQUEST["lot_no"];
		
		$rs = $this->mdl->getAll($page,$rows,$key,$dtdari,$dtsampai,$prodcard_id,$lot_no);
		
		echo json_encode($rs);
	}
	
	function aksi($cmd)
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$prodcard_id = $_REQUEST["prodcard_id"];
		$lot_no = $_REQUEST["lot_no"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'kd_barang' => 	$key,
			'nm_barang' => 	$nm_barang,
			'row' => 	$this->bbmdl->getRow($key),			
			'rs' 	=> 	$this->mdl->getAll($page,$rows,$key,$dtdari,$dtsampai,$prodcard_id,$lot_no)
		);	
		
		if ($aksi=='excel'){
			$filename =$this->title.date('Ymd').".xls";
			header('Content-type: application/ms-excel');
			header('Content-Disposition: attachment; filename='.$filename);
		}
		
		$this->load->view($this->modul.'/print',$data);	
				
		
	}
	
}