<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller 
{
	var $template_data = array();
	var $update = array();
	var $title = '..: FSI :..';
	public $em;
	/**
	 * Constructor of MY Controller
     */
	function __construct()
	{
		parent::__construct();
		$this->CI =& get_instance();
		if (!$this->is_logged_in()) {
			echo "<SCRIPT>parent.location='".site_url('login')."'</SCRIPT>";
		}
		
		$this->url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
		$this->folder 	= site_url('assets/images/folder.png');
		$this->file 		= site_url('assets/images/file.png');
		$this->menuSize = "width:7%; height:7%;"; 

		$titleTab='';

		$this->default_title = " DO-ERP CORINTHIANS";
		// Master Data Titles
		if($this->url == site_url('company')) 								{	$this->titleTab = "All Company List | ".$default_title;																		}
		else if($this->url == site_url('company_customer')) 	{	$this->titleTab = "All Customer List | ".$default_title;																	}
		else if($this->url == site_url('company_supplier')) 	{	$this->titleTab = "All Supplier List | ".$default_title;																	}
		else if($this->url == site_url('bahanbaku')) 					{	$this->titleTab = "Item Master List | ".$default_title;																		}
		else if($this->url == site_url('uplbahanbaku')) 			{	$this->titleTab = "Upload Item Master | ".$default_title;																	}
		else if($this->url == site_url('line')) 							{	$this->titleTab = "Production Line List | ".$default_title;																}
		else if($this->url == site_url('matcons')) 						{	$this->titleTab = "BOM FG List | ".$default_title;																				}
		else if($this->url == site_url('matcons_smt')) 				{	$this->titleTab = "BOM SMT List | ".$default_title;																				}
		else if($this->url == site_url('matcons_cb')) 				{	$this->titleTab = "BOM CB List | ".$default_title;																				}
		else if($this->url == site_url('matcons_ml')) 				{	$this->titleTab = "BOM ML List | ".$default_title;																				}
		else if($this->url == site_url('uplbom'))			 				{	$this->titleTab = "Upload All BOM | ".$default_title;																			}
		else if($this->url == site_url('valuta'))			 				{	$this->titleTab = "Valuta List | ".$default_title;																				}

		// Transactions Titles (SO & PO)
		else if($this->url == site_url('so'))			 						{	$this->titleTab = "Sales Order List | ".$default_title;																		}
		else if($this->url == site_url('uplso'))			 				{	$this->titleTab = "Upload Sales Order | ".$default_title;																	}
		else if($this->url == site_url('po'))					 				{	$this->titleTab = "Purchase Order | ".$default_title;																			}
		else if($this->url == site_url('uplpo'))			 				{	$this->titleTab = "Upload Purchase Order | ".$default_title;															}						
		
		// Transactions Titles (Incoming)
		else if($this->url == site_url('matin')) 							{	$this->titleTab = "Incoming Material | ".$default_title;																	}
		else if($this->url == site_url('matinsk')) 						{	$this->titleTab = "Incoming Sub Kontrak | ".$default_title;																}
		else if($this->url == site_url('fgin')) 							{	$this->titleTab = "Incoming Finished Good | ".$default_title;															}
		else if($this->url == site_url('macin')) 							{	$this->titleTab = "Incoming Machine and Equipment | ".$default_title;											}
		else if($this->url == site_url('scin')) 							{	$this->titleTab = "Incoming Scrap | ".$default_title;																			}
		else if($this->url == site_url('wipin'))							{	$this->titleTab = "Incoming WIP | ".$default_title;																				}
		else if($this->url == site_url('uplin')) 							{	$this->titleTab = "Upload Incoming | ".$default_title;																		}
		
		// Transactions Titles (Outgoing)
		else if($this->url == site_url('matout')) 						{	$this->titleTab = "Outgoing Material List | ".$default_title;															}
		else if($this->url == site_url('fgout')) 							{	$this->titleTab = "Outgoing Finished Good List | ".$default_title;												}
		else if($this->url == site_url('macout')) 						{	$this->titleTab = "Outgoing Machine and Equipment | ".$default_title;											}
		else if($this->url == site_url('scout')) 							{	$this->titleTab = "Outgoing Scrap | ".$default_title;																			}
		else if($this->url == site_url('wipout'))							{	$this->titleTab = "Outgoing WIP | ".$default_title;																				}
		else if($this->url == site_url('uplout')) 						{	$this->titleTab = "Upload Outgoing | ".$default_title;																		}

		// Transactions Titles (Stock Opname)
		else if($this->url == site_url('matopn')) 						{	$this->titleTab = "Stock Opname Material List | ".$default_title;													}
		else if($this->url == site_url('fgopn')) 							{	$this->titleTab = "Stock Opname Finished Good List | ".$default_title;										}
		else if($this->url == site_url('macopn')) 						{	$this->titleTab = "Stock Opname Machine and Equipment | ".$default_title;									}
		else if($this->url == site_url('scopn')) 							{	$this->titleTab = "Stock Opname Scrap | ".$default_title;																	}
		else if($this->url == site_url('wipopn'))							{	$this->titleTab = "Stock Opname WIP | ".$default_title;																		}
		else if($this->url == site_url('uplopn')) 						{	$this->titleTab = "Upload Stock Opname | ".$default_title;																}
		
		// Transactions Titles (AR & AP)
		else if($this->url == site_url('ar')) 								{	$this->titleTab = "Account Receivable List | ".$default_title;														}
		else if($this->url == site_url('arotm')) 							{	$this->titleTab = "Account Receivable (OTM) List | ".$default_title;											}
		else if($this->url == site_url('ap')) 								{	$this->titleTab = "Account Payable List | ".$default_title;																}
		
		// Reports (Stock Card)
		else if($this->url == site_url('ksmat')) 							{	$this->titleTab = "Stock Card Material List | ".$default_title;														}
		else if($this->url == site_url('ksfg')) 							{	$this->titleTab = "Stock Card Finished Good List | ".$default_title;											}
		else if($this->url == site_url('ksmac')) 							{	$this->titleTab = "Stock Card Machine and Equipment | ".$default_title;										}
		else if($this->url == site_url('kssc')) 							{	$this->titleTab = "Stock Card Scrap | ".$default_title;																		}
		else if($this->url == site_url('kswip'))							{	$this->titleTab = "Stock Card WIP | ".$default_title;																			}
		
		// Reports (Mutation)
		else if($this->url == site_url('mumat')) 							{	$this->titleTab = "Mutation Report Material List | ".$default_title;											}
		else if($this->url == site_url('mufg')) 							{	$this->titleTab = "Mutation Report Finished Good List | ".$default_title;									}
		else if($this->url == site_url('mumac')) 							{	$this->titleTab = "Mutation Report Machine and Equipment | ".$default_title;							}
		else if($this->url == site_url('musc')) 							{	$this->titleTab = "Mutation Report Scrap | ".$default_title;															}
		else if($this->url == site_url('rmonwip'))						{	$this->titleTab = "Mutation Report WIP | ".$default_title;																}

		// Reports (Bea Cukai Report)
		else if($this->url == site_url('brpt_masukrm')) 			{	$this->titleTab = "Laporan Pemasukan Barang Per Dokumen Pabean  | ".$default_title;				}
		else if($this->url == site_url('brpt_keluarbarang')) 	{	$this->titleTab = "Laporan Pengeluaran Barang Per Dokumen Pabean | ".$default_title;			}
		else if($this->url == site_url('mumat')) 							{	$this->titleTab = "Laporan Mutasi Bahan Baku | ".$default_title;													}
		else if($this->url == site_url('rmuwip')) 						{	$this->titleTab = "Laporan WIP | ".$default_title;																				}
		else if($this->url == site_url('mufg')) 							{	$this->titleTab = "Laporan Mutasi Barang Jadi | ".$default_title;													}
		else if($this->url == site_url('musc'))								{	$this->titleTab = "Laporan Mutasi Scrap | ".$default_title;																}
		else if($this->url == site_url('mumac'))							{	$this->titleTab = "Laporan Mutasi Mesin | ".$default_title;																}
		else if($this->url == site_url('brpt_rekapbcp'))			{	$this->titleTab = "Laporan Pengeluaran Barang Per Dokumen Pabean | ".$default_title;			}

		// User
		else if($this->url == site_url('user'))								{	$this->titleTab = "User List | ".$default_title;																					}
		else if($this->url == site_url('log'))								{	$this->titleTab = "User Activity History | ".$default_title;															}

		// $rs = $this->mdl->menu();
		// foreach ($rs as $rs) {
		// 	$menu = $rs->menu_name;
		// }
	}
		
	function set($name, $value)
	{
		$this->template_data[$name] = $value;
	}
	function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
	{               
		//if (!isset($view_data['title'])
		//	$view_data['title'] = $this->title;
			
		$this->CI =& get_instance();
		$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));			
		return $this->CI->load->view($template, $this->template_data, $return);
	}
		
	public function is_logged_in()
	{
		
		$loggedin = false;
		if ($this->CI->session->userdata('username')) {
			$loggedin = TRUE;
		}
		return $loggedin;
	}
	
	function success($msg='')
	{
		$this->update['error']='';
		$this->update['message']=$msg;
		echo json_encode($this->update);
	}
	
	function error($err)
	{
		$this->update['error']=$err;
		$this->update['message']='';
		echo json_encode($this->update);
		exit;
	}
	
	function gen_paging($page_data=array())
	{
		//$page_result = '<div class="row"><div class="span6"><div class="dataTables_info" id="dt_gal_info">'.$page_data['count_row'].' row</div></div>';
		$page_result = '<div class="row"><div class="span6"></div>';
		$count = ceil($page_data['count_row'] / $page_data['limit']) ;
		$page_result .= '<div class="span6"><div class="dataTables_paginate  pagination"><ul><li class="prev '.($page_data['current']==1?'active':'').'"><a href="javascript:void(0)" '.($page_data['current']==1?'':'onclick="pageLoad(1)"').'>&lt; First</a></li>';
		
		$paging_show = 3;
		$page_start = $page_data['current'] - $paging_show;
		$page_start = $page_start<1?1:$page_start;
		//$page_end	= $count;
		$page_end = $page_data['current'] + $paging_show;
		$page_end = $count > $page_end ? $page_end : $count;
		$page_end = $count > 1 ? $page_end : 1;
		$func = 'pageLoad';
		if (isset($page_data['func']))
			$func = $page_data['func'];
		//
		if ($page_start > 1)
		{
			$page_result .= '<li class="active")><a href="javascript:void(0)" >...</a></li>';
		}
		// before current
		for($i=$page_start; $i<=$page_end; $i++)
		{ 
			$page_result .= '<li '.($page_data['current']==$i?'class="active"':'').'>'
							.'<a href="javascript:void(0)" '.($page_data['current']==$i?'':'onclick="'.$func.'('.$i.')"').'>'.$i.'</a>'
							.'</li>';
		}
		// after current
		if ($page_end < $count)
		{
			$page_result .= '<li class="active")><a href="javascript:void(0)" >...</a></li>';
		}
		
		$page_result .= '<li class="next '.($page_data['current']==$page_end?'active':'').'"><a href="javascript:void(0)" onclick="'.$func.'('.$count.')">Last &gt; </a></li></ul></div>';
		$page_result .= '</div></div>';
		return $page_result;
	}
	
	/*
	 * untuk mencari no transaksi yang baru	
	 */
	function _get_tr_no($pref=null,$model=null,$date=true)
	{
		if (!$pref)
			$pref = '';
		else
			$pref .= '.';			
		
		if ($date)
			$pref .= date('ym').'.';
			
		$pref_ln = strlen($pref);
		
		$tr_no = '';
		$no_last = $model->get_last_no($pref);
		$no_next = 1;
		if ($no_last)
		{
			$no_next = substr($no_last,$pref_ln,5)+1;
		}
		$tr_no = $pref.sprintf('%05s', $no_next);
		return $tr_no;
	}
	
	function gridHdrDets(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$rs = $this->mdl->getHdrDets($page,$rows,$key);
		
		echo json_encode($rs);
	}
	
	function add($data){			
		$success = $this->mdl->add($data);	
		
		if ($success){				
			$bol=true;
			$msg="Tambah data berhasil.";
		} else {
			$bol=false;
			$msg="Tambah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function addDet($data){			
		$success = $this->mdl->addDet($data);	
		
		if ($success){				
			$bol=true;
			$msg="Tambah data berhasil.";
		} else {
			$bol=false;
			$msg="Tambah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function addHdrDet($data){			
		$rs = $this->mdl->addHdrDet($data);
		
		echo json_encode($rs); 
	}
	
	function edit($data,$pk){
		$success = $this->mdl->edit($data,$pk);	
		
		if ($success){				
			$bol=true;
			$msg="Ubah data berhasil.";
		} else {
			$bol=false;
			$msg="Ubah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}

	function editarap($data,$pk){
		$success = $this->mdl->editarap($data,$pk);	
		
		if ($success){				
			$bol=true;
			$msg="Ubah data berhasil.";
		} else {
			$bol=false;
			$msg="Ubah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}

	function editbrbp($data,$pk){
		$success = $this->mdl->editbrbp($data,$pk);	
		
		if ($success){				
			$bol=true;
			$msg="Ubah data berhasil.";
		} else {
			$bol=false;
			$msg="Ubah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function editDet($data,$pk){
		$success = $this->mdl->editDet($data,$pk);	
		
		if ($success){				
			$bol=true;
			$msg="Ubah data berhasil.";
		} else {
			$bol=false;
			$msg="Ubah data gagal.";		
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function editHdrDet($data){			
		$rs = $this->mdl->editHdrDet($data);
		
		echo json_encode($rs); 
	}
	
	function dmys2ymd($date){
		if ($date!=""){
			list($day, $month, $year) = explode('/', $date);		
			return $year."-".str_pad($month, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT);
		} else {
			return "0000-00-00";
		}
	}
	
	function wims_currency($number,$dec_point) { 
	   if ($number < 0) { 
		 $print_number = "(" . str_replace('-', '', number_format ($number, $dec_point)) . ")"; 
		} else { 
		 $print_number = number_format ($number, $dec_point); 
	   } 
	   return $print_number; 
	} 
	
	function del(){
		$id=$_REQUEST['id'];
		$po_id=$_REQUEST['po_id'];
		$partial=$_REQUEST['partial'];
		$success = $this->mdl->del($id,$po_id,$partial);
		
		if ($success == "success"){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else if ($success == "reject ap") {
			$bol=false;
			$msg="Data sudah masuk di Account Payable! Tidak bisa dihapus!";
		} else if ($success == "reject ar") {
			$bol=false;
			$msg="Data sudah masuk di Account Receivable! Tidak bisa dihapus!";
		} else if ($success == "failed") {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	function delPo(){
		$id=$_REQUEST['id'];
		$success = $this->mdl->delPo($id);
		
		if ($success == "success"){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else if ($success == "reject trxin") {
			$bol=false;
			$msg="Data sudah masuk di Transaksi Incoming! Tidak bisa dihapus!";
		} else if ($success == "failed") {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	function delSo(){
		$id=$_REQUEST['id'];
		$success = $this->mdl->delSo($id);
		
		if ($success == "success"){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else if ($success == "reject trxout") {
			$bol=false;
			$msg="Data sudah masuk di Transaksi Outgoing! Tidak bisa dihapus!";
		} else if ($success == "failed") {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function delDet(){
		$id=$_REQUEST['id'];
		$child_no=$_REQUEST['child_no'];
		$success = $this->mdl->delDet($id,$child_no);
		
		if ($success){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function delDet2(){
		$id=$_REQUEST['id'];
		$child_no=$_REQUEST['child_no'];
		$success = $this->mdl->delDet2($id,$child_no);
		
		if ($success){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	function delDet1(){
		$id=$_REQUEST['id'];
		$success = $this->mdl->delDet1($id);
		
		if ($success){				
			$bol=true;
			$msg="Hapus data berhasil.";
		} else {
			$bol=false;
			$msg="Hapus data GAGAL.";
		}
		
		echo json_encode(array('success'=>$bol,'msg'=>$msg)); 
	}
	
	function getStockIns(){
		$data=array(
			'aksi' => $_REQUEST["aksi"],
			'date' => $_REQUEST["date"],
			'prodcard_id' => $_REQUEST["prodcard_id"],
			'lot_no' => $_REQUEST["lot_no"],
			'color' => $_REQUEST["color"],
			'size' => $_REQUEST["size"],
			'qty' => $_REQUEST["qty"]
		);
		$rs = $this->mdl->getStockIns($data);
		
		echo $rs;
	}
	
	function gridKstok(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$rs = $this->mdl->getKstok($page,$rows,$key,$dtdari,$dtsampai,$color,$size);
		
		echo json_encode($rs);
	}
	
	function cetakKstok()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'row' => 	$this->pcmdl->getRow($key),			
			'rs' 	=> 	$this->mdl->getKstok($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);	
		
		$this->load->view($this->modul.'/print',$data);
		
	}
	
	function excelKstok()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'kd_barang' => 	$key,
			'nm_barang' => 	$nm_barang,
			'row' => 	$this->pcmdl->getRow($key),
			'rs' 	=> 	$this->mdl->getKstok($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);
		
		$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);
	}
	
	function gridKstokQc(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$rs = $this->mdl->getKstokQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size);
		
		echo json_encode($rs);
	}
	
	function cetakKstokQc()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'row' => 	$this->pcmdl->getRow($key),			
			'rs' 	=> 	$this->mdl->getKstokQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);	
		
		$this->load->view($this->modul.'/print',$data);
		
	}
	
	function excelKstokQc()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'kd_barang' => 	$key,
			'nm_barang' => 	$nm_barang,
			'row' => 	$this->pcmdl->getRow($key),
			'rs' 	=> 	$this->mdl->getKstokQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);
		
		$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);
	}
	
	function gridKstokSi(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$rs = $this->mdl->getKstokSi($page,$rows,$key,$dtdari,$dtsampai,$color,$size);
		
		echo json_encode($rs);
	}
	
	function cetakKstokSi()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'row' => 	$this->pcmdl->getRow($key),			
			'color' => 	$color,
			'size' => 	$size,
			'rs' 	=> 	$this->mdl->getKstokSi($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);	
		
		$this->load->view($this->modul_parent.'/print',$data);
		
	}
	
	function excelKstokSi()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'kd_barang' => 	$key,
			'nm_barang' => 	$nm_barang,
			'row' => 	$this->pcmdl->getRow($key),		
			'color' => 	$color,
			'size' => 	$size,
			'rs' 	=> 	$this->mdl->getKstokSi($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);
		
		$filename =$this->title.date('Ymd').".xls";
		header('Content-type: application/ms-excel');
		header('Content-Disposition: attachment; filename='.$filename);
		$this->load->view($this->modul_parent.'/print',$data);
	}
	
	function gridKstokSiQc(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		$rs = $this->mdl->getKstokSiQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size);
		
		echo json_encode($rs);
	}
	
	function cetakKstokSiQc()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'row' => 	$this->pcmdl->getRow($key),					
			'color' => 	$color,
			'size' => 	$size,
			'rs' 	=> 	$this->mdl->getKstokSiQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);	
		
		$this->load->view($this->modul_parent.'/print',$data);
		
	}
	
	function excelKstokSiQc()
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;	
		$key = $_REQUEST["q"];
		$color = $_REQUEST["color"];
		$size = $_REQUEST["size"];
		$nm_barang = $_REQUEST["nm_barang"];
		$dtdari = $_REQUEST["dtdari"];
		$dtsampai = $_REQUEST["dtsampai"];
		
		$data = array(
			'title' => 	$this->title,
			'dtdari' => 	$dtdari,
			'dtsampai' => 	$dtsampai,
			'kd_barang' => 	$key,
			'nm_barang' => 	$nm_barang,
			'row' => 	$this->pcmdl->getRow($key),		
			'color' => 	$color,
			'size' => 	$size,
			'rs' 	=> 	$this->mdl->getKstokSiQc($page,$rows,$key,$dtdari,$dtsampai,$color,$size)
		);
		
		$filename =$this->title.date('Ymd').".xls";
		header('Content-type: application/ms-excel');
		header('Content-Disposition: attachment; filename='.$filename);
		$this->load->view($this->modul_parent.'/print',$data);
	}
	
} 