<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH."modules/ks/controllers/ks.php";

class Kswip extends Ks {
	
	function __construct()
	{
		parent::__construct();
		
		$this->pmodul = 'ks';
		$this->modul = 'kswip';
		
		$this->title = 'KARTU STOK WIP';
		$this->mat_type = '11';
		$this->tp_barang = '1';
		
		$this->tbl = 'mat_inchdr_sub';		
		$this->tbl2 = 'mat_incdet_sub';
		$this->tbl3 = 'mst_in_type';
		$this->tbl4 = 'mst_perusahaan';
		$this->tbl5 = 'mst_barang';
		$this->tbl6 = 'jenis_dok';
		
		$this->pk = 'matin_id';
		$this->pk2 = 'child_no';
		$this->pk3 = 'matin_type';
		$this->pk4 = 'KdPrshn';
		$this->pk5 = 'KdBarang';
		$this->pk6 = 'KdJnsDok';
		$this->pkh = 'matin_no';
		
		$this->load->model($this->pmodul.'/'.$this->pmodul.'_mdl','pmdl');
		$this->load->model($this->modul.'_mdl','mdl');
		
	}
	
	public function index()
	{		
		$data = array(
			'title' 	=> 	$this->title,
			'content' 	=> 	$this->pmodul.'/'.$this->pmodul,
			);		
		$this->load('tpl',$data['content'], $data);
		$this->load->view($this->pmodul.'/'.$this->pmodul.'_cjs');
		$this->load->view($this->pmodul.'/'.$this->pmodul.'2_mjs');
		
	}
	
	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"];
		$NmBarang = $_REQUEST["NmBarang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$kd_cmpy = $_REQUEST["kd_cmpy"];
		$line = $_REQUEST["line"];
		
		$rs = $this->mdl->getAll($page,$rows,$key,$dtdari,$dtsampai,$kd_cmpy,$line);	
		
		if ($cmd=='cari'){
			echo json_encode($rs);
		} else {
			$data = array(
				'title' => 	$this->title,
				'dtdari' => 	$dtdari,
				'dtsampai' => 	$dtsampai,
				'KdBarang' => 	$key,
				'NmBarang' => 	$NmBarang,
				'row' => 	$this->bbmdl->getRow($key),			
				'rs' 	=> 	$rs
			);	
			
			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->pmodul.'/print2',$data);	
		}
				
		
	}
}