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

/*************************************
  * Created : May 2015
  * Creator : Fauzan Rabbani
  * Email   : jhanojan@gmail.com
  * Framework ver. : CI ver.2.0
*************************************/	

class stok_out extends CI_Controller {
	
		var $utama ='stok_out';
		var $title ='Stok Keluar';
	function __construct()
	{
		parent::__construct();
                
                permissionz();
		$this->load->library('flexigrid');
                $this->load->helper('flexigrid');
                error_reporting(0);
	}
	
	function index()
	{
		$this->main();
	}
	
	function main()
	{
            
            $data['opt_brand']=GetOptAll('master_brand','-Brand-');
		//Migrasi 1 Feb 14
		//permissionz();
		//Set Global
		//permission();
		//$data = GetHeaderFooter();
		$data['content'] = 'contents/'.$this->utama.'/view';
                
		$brand=$this->input->get('brand');
                if(empty($brand))$brand=0;
                $jenis_produk=$this->input->get('jenis_produk');
                if(empty($jenis_produk))$jenis_produk=0;
                $produk=$this->input->get('produk');
                if(empty($produk))$produk=0;
                $gudang=$this->input->get('gudang');
                if(empty($gudang))$gudang=0;
                $tanggal=$this->input->get('tanggal');
                if(empty($tanggal))$tanggal=0;
		$data['js_grid']=$this->get_column($brand,$jenis_produk,$produk,$gudang,$tanggal);
		//$data['list']=GetAll($this->utama);
		//End Global
		
		//Attendance
		
		$this->load->view('layout/main',$data);
	}
        function loadproduknumber(){
            $v=$this->input->post('v');
            echo GetValue('part_number','master_produk',array('id'=>'where/'.$v));
        }
	function listcol(){
		
            $colModel['idnya'] = array('ID',50,TRUE,'left',2,TRUE);
            $colModel['id'] = array('ID',100,TRUE,'left',2,TRUE);
            $colModel['code'] = array('No. SO',110,TRUE,'left',2);
            $colModel['brands'] = array('Merk',110,TRUE,'left',2,TRUE);
            $colModel['jenis_produks'] = array('Jenis Produk',110,TRUE,'left',2,TRUE);
            $colModel['produks'] = array('Produk',110,TRUE,'left',2,TRUE);
            $colModel['part_number'] = array('Part Number',110,TRUE,'left',2,TRUE);
            $colModel['lot_number'] = array('Lot Number',110,TRUE,'left',2,TRUE);
            $colModel['total'] = array('Jumlah Keluar',110,TRUE,'left',2,TRUE);
            $colModel['tgl'] = array('Tanggal Keluar',110,TRUE,'left',2);
            $colModel['tgl_tiba'] = array('Tanggal Tiba',110,TRUE,'left',2,TRUE);
            $colModel['lokasi_gudang'] = array('Gudang',110,TRUE,'left',2,TRUE);
            $colModel['petugas'] = array('Petugas',110,TRUE,'left',2);
            $colModel['pelanggan'] = array('Customer',200,TRUE,'left',2);
            $colModel['created_on'] = array('Tgl Input',200,TRUE,'left',2);
            return $colModel;
	}
	
	function get_column($brand,$jenis_produk,$produk,$gudang,$tanggal){
            $colModel=$this->listcol(); 
	
        
            $gridParams = array(
                'rp' => 25,
                'rpOptions' => '[10,20,30,40]',
                'pagestat' => 'Displaying: {from} to {to} of {total} items.',
                'blockOpacity' => 0.5,
                'title' => '',
                'showTableToggleBtn' => TRUE
		);
        
           $buttons[] = array('select','check','btn');
            $buttons[] = array('deselect','uncheck','btn');
            $buttons[] = array('separator');
            if(izin('c'))$buttons[] = array('add','add','btn');
            $buttons[] = array('separator');
            if(izin('u'))$buttons[] = array('edit','edit','btn');
            if(izin('d'))$buttons[] = array('delete','delete','btn');
            $buttons[] = array('separator');
            $buttons[] = array('surat jalan','print','btn');
		
            return $grid_js = build_grid_js('flex1',site_url($this->utama."/get_record/".$brand.'/'.$jenis_produk.'/'.$produk.'/'.$gudang."/".$tanggal),$colModel,'id','desc',$gridParams,$buttons);
	}
	
	function get_flexigrid($brand,$jenis_produk,$produk,$gudang,$tanggal)
        {

            //Build contents query
		//	$this->db->where("sv_a.param",'in');
            if(!empty($brand)) $this->db->where('sv_a.brand',$brand,FALSE);
            if(!empty($jenis_produk)) $this->db->where('sv_a.jenis_produk',$jenis_produk,FALSE);
            if(!empty($produk)) $this->db->where('sv_a.produk',$produk,FALSE);
            if(!empty($gudang)) $this->db->where('sv_a.gudang',$gudang,FALSE);
            if(!empty($tanggal)) $this->db->where('sv_a.tgl',$tanggal);
            
            $this->db->select("sv_a.*,b.title jenis_produks,c.title brands,d.title lokasi_gudang,e.title produks,f.title pelanggan")->from($this->utama.'_so sv_a');
            $this->db->join('sv_master_jenis_produk b', "sv_a.jenis_produk=b.id", 'left');
            $this->db->join('sv_master_brand c', "sv_a.brand=c.id", 'left');
            $this->db->join('sv_master_gudang d', "sv_a.gudang=d.id", 'left');
            $this->db->join('sv_master_produk e', "sv_a.produk=e.id", 'left');
            $this->db->join('sv_master_pelanggan f', "sv_a.customer=f.id", 'left');
            $this->flexigrid->build_query();

            //Get contents
            $return['records'] = $this->db->get();
           // lastq();
            //Build count query
            //$this->db->where("param",'in');
            if(!empty($brand)) $this->db->where('brand',$brand,FALSE);
            if(!empty($jenis_produk)) $this->db->where('jenis_produk',$jenis_produk,FALSE);
            if(!empty($produk)) $this->db->where('produk',$produk,FALSE);
            if(!empty($gudang)) $this->db->where('gudang',$gudang,FALSE);
            if(!empty($tanggal)) $this->db->where('tgl',$tanggal);
            $this->db->select("count(id) as record_count")->from($this->utama);
            $this->flexigrid->build_query(FALSE);
            $record_count = $this->db->get();
            $row = $record_count->row();

            //Get Record Count
            $return['record_count'] = $row->record_count;

            //Return all
            return $return;
        }
	
	function get_record($brand,$jenis_produk,$produk,$gudang,$tanggal){
		$colModel=$this->listcol();
		$valid_fields = array('id','code','jenis_produk','brand',);

            $this->flexigrid->validate_post('id','DESC',$valid_fields);
            $records = $this->get_flexigrid($brand,$jenis_produk,$produk,$gudang,$tanggal);

            $this->output->set_header($this->config->item('json_header'));

            $record_items = array();
            $a=0;
            foreach ($records['records']->result() as $row)
            {/*
			if($row->status=='y'){$status='Aktif';}
			elseif($row->status=='n'){$status='Tidak Aktif';}
			elseif($row->status=='s'){$status='Suspended';}*/ 
			
				$record_items[$a][]=$row->id;
				$record_items[$a][]=$row->id;
				$record_items[$a][]=$row->id;
				$b=2;
				foreach($colModel as $key=>$cm){
					if($key=='auth'){
                                        $record_items[$a][$b]="<a href='".base_url()."master_sales/auth/$row->id'>Menu</a>";
                                        
                                        }
					elseif($key=='username'){
                                        $record_items[$a][$b]=GetValue('username','sv_admin',array('marketing'=>'where/'.$row->id));
                                        
                                        }
					elseif($key!='idnya' && $key!='id' && $key!='username'){
                                        $record_items[$a][$b]=$row->$key;}
				$b++;
				}
						$a++;
            }
            return $this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));;
	}  

	function deletes($id,$doc){
                $this->db->where('id',$id);
                $this->db->delete('sv_stok_out');
                
                stok_trx('out', $id,null,null,null,null,null,null,null,null,null,'del');
                redirect('stok_out/form/'.$doc);
        }
	function deletec()
	{		
		//return true;
		if(izin('d')){
		$countries_ids_post_array = explode(",",$this->input->post('items'));
		array_pop($countries_ids_post_array);
		foreach($countries_ids_post_array as $index => $country_id){
			/*if (is_numeric($country_id) && $country_id > 0) {
				$this->delete($country_id);}*/
				//$data['status']='InAktif';
				//$this->db->where('id',$country_id);
				//$this->db->update($this->utama,$data);
			$this->db->delete('sv_stok_out_so',array('id'=>$country_id));
                        $isi=$this->db->query("SELECT * FROM sv_stok_out WHERE id_so='$country_id'")->result_array();
                        foreach($isi as $si){
                        
			$this->db->delete($this->utama,array('id'=>$si['id']));
                        stok_trx('out', $si['id'],null,null,null,null,null,null,null,null,null,'del');
                        }
                            
                  }
			echo 'ok';
		}
		else{
			echo 'error';
		}
		//$error = "Selected countries (id's: ".$this->input->post('items').") deleted with success. Disabled for demo";
		//echo "Sukses!";
	}
	
	function form($id=null){
            
                error_reporting(0);
            if($this->session->userdata('webmaster_id')!='270611'){
		//die('Menu Saat Ini Tidak Bisa Diakses');
            }
		if($id!=NULL){
		permissionz('u');
			$filter=array('id'=>'where/'.$id);
			$data['type']='Edit';
			$data['list']=GetAll($this->utama.'_so',$filter)->row_array();
                        $data['opt_jenis']=GetOptAll('master_jenis_produk','-Jenis Produk-',array('brand'=>'where/'.$data['list']['brand']));
                        $data['opt_produk']=GetOptAll('master_produk','-Produk-',array('brand'=>'where/'.$data['list']['brand'],'jenis_produk'=>'where/'.$data['list']['jenis_produk']));
		
                    
                        $data['detail']=GetAll('sv_stok_out',array('id_so'=>'where/'.$id))->result_array();
                }
		else{
			
		permissionz('c');
			$data['type']='New';
                        $data['opt_jenis']=GetOptAll('master_jenis_produk','-Jenis Produk-',array('status'=>'where/abcdefghijkl'));
                        $data['opt_produk']=GetOptAll('master_produk','-Produk-',array('status'=>'where/abcdefghijkl'));
		}
		$data['opt_brand']=GetOptAll('master_brand','-Merk-',array('status'=>'where/Aktif'));
		$data['opt_currency']=GetOptAll('master_currency','-Currency-',array('status'=>'where/Aktif'),'code');
		$data['opt_metric']=GetOptAll('master_metric','-Metric-',array('status'=>'Aktif'),'code');
		$data['opt_klasifikasi']=GetOptAll('sv_ref_produk_klas','-Klasifikasi-');
		$data['opt_satuan']=GetOptAll('sv_ref_satuan','-Satuan-');
		$data['opt_gudang']=GetOptAll('master_gudang','-Gudang-');
		$data['opt_customer']=GetOptAll('master_pelanggan','-Customer-',array('status'=>'where/Aktif'));
		$data['opt_sales']=GetOptAll('master_sales','-Sales-',array('status'=>'where/Aktif'),'nama_lengkap');
		$data['opt_booking']=GetOptAll('sv_stok_booking','-Booking-',array('status'=>'where/unfinished'),'code');
		$data['gdg_br']=GetAll('master_gudang',array())->result_array();
                $data['merk_br']=GetAll('sv_master_brand',array('status'=>'where/Aktif','title'=>'order/asc'))->result_array();
                //print_mz($data['opt_booking']);                
//lastq();
		$data['content'] = 'contents/'.$this->utama.'/edit';
		//End Global
		
		//Attendance
		
		$this->load->view('layout/main',$data);
	}
	
	function submit(){
                if(empty($this->input->post('brand')) || empty($this->input->post('customer'))){
                    echo "<script>"
                    . "alert('Masukkan Minimal 1 Produk');"
                            . "history.go(-1);"
                    . "</script>";
                    exit;
                }
                //print_mz($this->input->post());
		$webmaster_id=$this->session->userdata('webmaster_id');
		$id = $this->input->post('id');
		$GetColumns = GetColumns('sv_'.$this->utama);
		foreach($GetColumns as $r)
		{
			$data[$r['Field']] = $this->input->post($r['Field']);
			$data[$r['Field']."_temp"] = $this->input->post($r['Field']."_temp");
			
			if(!$data[$r['Field']] && !$data[$r['Field']."_temp"]) unset($data[$r['Field']]);
			unset($data[$r['Field']."_temp"]);
		}	
                if($data['booked']=='yes'){
                    $this->db->query("UPDATE sv_stok_booking SET status='finished' WHERE id='".$data['booking_id']."'");
                }
                unset($data['brand']);
                unset($data['jenis_produk']);
                unset($data['produk']);
                unset($data['gudang']);
                unset($data['tgl_tiba']);
                unset($data['lot_number']);
                unset($data['qty']);
                unset($data['satuan']);
		/* if(!$this->input->post('is_active')){$data['is_active']='InActive';}
		else{$data['is_active']='Active';} */
		
		if($id != NULL && $id != '')
		{
			/* if(!$this->input->post('password')){unset($data['password']);}
			else{$data['password']=md5($this->config->item('encryption_key').$this->input->post("password"));} */
			
			if(izin('u')){
			$data['modify_by'] = $webmaster_id;
			$data['modify_on']=date("Y-m-d");
			$this->db->where("id", $id);
			$this->db->update('sv_'.$this->utama.'_so', $data);
                        $id_detail=$this->input->post('id_detail');
                        $brand=$this->input->post('brand');
                        $jenis_produk=$this->input->post('jenis_produk');
                        $produk=$this->input->post('produk');
                        $gudang=$this->input->post('gudang');
                        $tgl_tiba=$this->input->post('tgl_tiba');
                        $lot_number=$this->input->post('lot_number');
                        $qty=$this->input->post('qty');
                        $satuan=$this->input->post('satuan');
                        $i=0;
                        foreach($satuan as $st){
                            
                            $isi=array(
                                'id_so'=>$id,
                                'brand'=>$brand[$i],
                                'jenis_produk'=>$jenis_produk[$i],
                                'brand'=>$brand[$i],
                                'produk'=>$produk[$i],
                                'gudang'=>$gudang[$i],
                                'tgl'=>$data['tgl'],
                                'tgl_tiba'=>$tgl_tiba[$i],
                                'lot_number'=>$lot_number[$i],
                                'total'=>$qty[$i],
                                'param'=>'in',
                                'part_number'=>GetValue('part_number','master_produk',array('id'=>'where/'.$produk[$i])),
                                'satuan'=>$satuan[$i],
                                'petugas'=>$data['petugas'],
                            );
                            if($id_detail[$i]>0){
                                $this->db->where('id',$id_detail[$i]);
                                $this->db->update('sv_stok_out',$isi);
                            }else{  
                                $this->db->insert('sv_stok_out',$isi);
                            }
                                
			//$id_isi = $this->db->insert_id();
                        
			stok_trx('out', $id_detail[$i], $isi['brand'], $isi['jenis_produk'],$isi['produk'], $isi['part_number'], '-'.$isi['total'],  $isi['satuan'], $isi['tgl_tiba'],$isi['exp'], $isi['gudang'],'upd');
                        $i++;
                        }
                        
			$this->session->set_flashdata("message", 'Sukses diedit');}
			else{
				$this->session->set_flashdata("message", 'Anda Tidak Diizinkan Mengedit Data');
			}
		}
		else
		{
			//if($this->input->post('password')){$data['password']=md5($this->config->item('encryption_key').$this->input->post("password"));}
			//if(!$this->input->post('avatar')){$data['avatar']='default.png';}
			
			if(izin('c')){
			$data['created_by'] = $webmaster_id;
			$data['created_on'] = date("Y-m-d H:i:s");
			$this->db->insert('sv_'.$this->utama.'_so', $data);
			$id = $this->db->insert_id();
                        $brand=$this->input->post('brand');
                        $jenis_produk=$this->input->post('jenis_produk');
                        $produk=$this->input->post('produk');
                        $gudang=$this->input->post('gudang');
                        $tgl_tiba=$this->input->post('tgl_tiba');
                        $lot_number=$this->input->post('lot_number');
                        $qty=$this->input->post('qty');
                        $satuan=$this->input->post('satuan');
                        $i=0;
                        foreach($satuan as $st){
                            
                            $isi=array(
                                'id_so'=>$id,
                                'brand'=>$brand[$i],
                                'jenis_produk'=>$jenis_produk[$i],
                                'brand'=>$brand[$i],
                                'produk'=>$produk[$i],
                                'gudang'=>$gudang[$i],
                                'tgl'=>$data['tgl'],
                                'tgl_tiba'=>$tgl_tiba[$i],
                                'lot_number'=>$lot_number[$i],
                                'total'=>$qty[$i],
                                'param'=>'in',
                                'part_number'=>GetValue('part_number','master_produk',array('id'=>'where/'.$produk[$i])),
                                'satuan'=>$satuan[$i],
                                'petugas'=>$data['petugas'],
                            );
                            $this->db->insert('sv_stok_out',$isi);
                        
			$id_isi = $this->db->insert_id();
                        stok_trx('out', $id_isi, $isi['brand'], $isi['jenis_produk'],$isi['produk'], $isi['part_number'], '-'.$isi['total'],  $isi['satuan'], $isi['tgl_tiba'],$data['exp'], $isi['gudang'],'ins');
                        $i++;
                        }
			$this->session->set_flashdata("message", 'Sukses ditambahkan');}
			else{
				$this->session->set_flashdata("message", 'Anda Tidak Diizinkan Menambah Data');
			}
		}
		
		redirect($this->utama);
		
	}
        function loadjenis(){
            $ids=rand(111,9999);
            echo form_dropdown('jenis_produk',GetOptAll('master_jenis_produk','-Jenis Produk-',array('brand'=>'where/'.$_POST['v'])),(isset($val[$nm_f]) ? $val[$nm_f] : ''),"class='select2' onchange='gantijenis(this.value)' id='produk$ids'");
            echo"<script>
                    $(document).ready(function(e){ 
                        $('#produk$ids').css('width','200px').select2({allowClear:true});
				$('#select2-multiple-style .btn').on('click', function(e){
					var target = $(this).find('input[type=radio]');
					var which = parseInt(target.val());
					if(which === 2) $('.select2').addClass('tag-input-style');
					 else $('.select2').removeClass('tag-input-style');
				});});</script>";
        }
        function loadproduk(){
            $ids=rand(111,9999);
            echo form_dropdown('produk',GetOptAll('master_produk','-Produk-',array('jenis_produk'=>'where/'.$_POST['v'])),(isset($val[$nm_f]) ? $val[$nm_f] : ''),"class='select2' onchange='cariexpired()' id='produk'");
            
            echo"<script>
                    $(document).ready(function(e){ 
                        $('#produk').css('width','200px').select2({allowClear:true});
				$('#select2-multiple-style .btn').on('click', function(e){
					var target = $(this).find('input[type=radio]');
					var which = parseInt(target.val());
					if(which === 2) $('.select2').addClass('tag-input-style');
					 else $('.select2').removeClass('tag-input-style');
				});});</script>";
        }
	function load_expired(){
            echo GetValue('tgl','ref_exp',array('produk'=>'where/'.$this->input->post('p')));
        }
        function cari_tanggal($tgl=null){
            $pr=$this->input->post('v');
            $gdg=$this->input->post('g');
            $id=$this->input->post('i');
            $a=$this->db->query("SELECT SUM(total) as stok,produk,gudang,tgl FROM `sv_stok_trx` WHERE produk='$pr' AND gudang='$gdg' AND total>0 GROUP BY produk,gudang,tgl")->result_array();
            $opt[]='-Tanggal Tiba-';
            foreach($a as $b){
                if($b['stok']>0){
                   $opt[$b['tgl']]=$b['tgl'];
                }
            }
            echo form_dropdown('tgl_tiba[]',$opt,$tgl,'class="select2" onchange="caristok('.$id.')" id="tgl_tiba-'.$id.'"');
            echo"<script>
                    $(document).ready(function(e){ 
                        $('#produk').css('width','200px').select2({allowClear:true});
				});</script>";
        }
        function cari_stok(){
            $pr=$this->input->post('v');
            $tgl=$this->input->post('t');
            $gdg=$this->input->post('g');
            $booked=$this->input->post('b');
            //print_mz($this->input->post());
            $a=$this->db->query("SELECT SUM(total) as stok,produk,gudang,tgl,satuan FROM `sv_stok_trx` WHERE produk='$pr' AND tgl='$tgl' AND gudang='$gdg' GROUP BY produk,gudang,tgl")->row_array();
            $b=$this->db->query("SELECT SUM(total) as stok,satuan FROM `sv_stok_booking` WHERE produk='$pr' AND status='unfinished' GROUP BY produk")->row_array();
            if($booked=='yes'){
                $b['stok']=0;
            }
            $data=array(
                'stok'=>$a['stok']-$b['stok'],
                'produk'=>$a['produk'],
                'gudang'=>$a['gudang'],
                'satuan'=>$a['satuan'],
                'st'=>GetValue('title','ref_satuan',array('id'=>'where/'.$a['satuan'])),
                'tgl'=>$a['tgl'] 
            );
            echo json_encode($data);
        }function loadbrand(){
                $nm_f='brand';
		$opt_brand=GetOptAll('master_brand','-Merk-',array('status'=>'Aktif'));
            echo form_dropdown($nm_f,$opt_brand,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" id="'.$nm_f.'" onchange="gantiproduk(this.value)" ');
            echo"<script>
                    $(document).ready(function(e){ 
                        $('#brand').css('width','200px').select2({allowClear:true});
				});</script>";
        }function loadbrandb(){
                $nm_f='brand';
                $bkg=$this->input->post('v');
                $bdata=GetAll('sv_stok_booking',array('id'=>'where/'.$bkg))->row_array();
		$opt_brand=GetOptAll('master_brand','-Merk-',array('status'=>'Aktif'));
            echo form_input($nm_f,$bdata['brand'],'class="select2" id="'.$nm_f.'" onchange="gantiproduk(this.value)"  style="display:none"');
            echo GetValue('title','master_brand',array('id'=>'where/'.$bdata['brand']));
           
        }
        
        function loadjenisb(){
                $ids=rand(111,9999);
                $bkg=$this->input->post('v');
                $bdata=GetAll('sv_stok_booking',array('id'=>'where/'.$bkg))->row_array();
            echo form_input('jenis_produk',$bdata['jenis_produk'],"class='select2' onchange='gantijenis(this.value)' id='produk$ids' style='display:none'");
            echo GetValue('title','master_jenis_produk',array('id'=>'where/'.$bdata['jenis_produk']));
        }
        function loadprodukb(){
                $ids=rand(111,9999);
                $bkg=$this->input->post('v');
                $bdata=GetAll('sv_stok_booking',array('id'=>'where/'.$bkg))->row_array();
            echo form_input('produk',$bdata['produk'],"class='select2' onchange='cariexpired()' id='produk' style='display:none'");
            echo GetValue('title','master_produk',array('id'=>'where/'.$bdata['produk']));
            
        }
        function loadsatuan(){
            
		$opt_satuan=GetOptAll('sv_ref_satuan','-Satuan-');
                $ids=rand(111,9999);
                $bkg=$this->input->post('v');
                $satuan= GetValue('satuan','sv_stok_booking',array('id'=>'where/'.$bkg));
                echo form_dropdown('satuan',$opt_satuan,$satuan,'class="" id="'.$nm_f.'" ');
        }
        function loadjumlah(){
                $bkg=$this->input->post('v');
            echo GetValue('total','sv_stok_booking',array('id'=>'where/'.$bkg));
        }
        function suratjalan($render=false,$id){
            $id_ar=explode('%',$id);
            $id=implode(',',$id_ar);
        $this->load->helper('dompdf');
        $data='';
        $q="SELECT * FROM sv_stok_out_so WHERE id =$id";
        $data['lastq']=$this->db->query($q)->result_array();
        $data['isinya']=$this->db->query("SELECT * FROM sv_stok_out WHERE id_so='$id'")->result_array();
        //foreach($data['lastq'] as $ls){
        //    $on[]=$ls['customer'];
        //}
        //if(count(array_unique($on, SORT_REGULAR)) >1){
        // echo "<script>alert('Silakan Pilh Customer yang sama');history.back();</script>";   
        // die();
        //};
        //lastq();
        if($data['lastq'][0]['no_sj']==''){
            $data['no_sj']= generatenumbering('surat_jalan');
            addnumbering('surat_jalan');
            $this->db->query("UPDATE sv_stok_out_so SET no_sj='".$data['no_sj']."' WHERE id IN($id)");
        }
        else{
            $data['no_sj']=$data['lastq'][0]['no_sj'];
        }
                /*$data['col']=$this->listcol();  
            error_reporting(E_ALL);
		$op = explode("%",$lastq);
                foreach($op as $or){
                    $inz[]="$or";
                }
                $oops=implode($inz,',');
             $q="SELECT * FROM sv_activity_view WHERE id IN (".$oops.")";
                
		$data['lastq']=$this->db->query($q)->result_array();
                 * 
                 */
               // lastq();
        //load content html
        $html = $this->load->view('contents/stok_out/surat_jalan',$data,TRUE);
        // create pdf using dompdf
        $filename = "surat_jalan";
        $paper = 'A4'; 
            $orientation = 'potrait';
            //die("ok");
            $f;
            $l;
        if(headers_sent($f,$l))
        {
            echo $f,'<br/>',$l,'<br/>';
            die('now detect line');
        }if($render){
            pdf_create($html, $filename, $paper, $orientation);}
         else{
          $this->load->view('contents/stok_out/surat_jalan',$data);  
        }
        }
        function surat_jalan(){
            $this->load->view('contents/stok_out/surat_jalan');
        }
        function barang($id){
            $data['id']=$id;
            $this->load->view('contents/stok_out/barang',$data);
        }
        
        function loadjenis_out(){
            $v=$_POST['v'];
            $id=$_POST['id'];
            $opt_brand=GetOptQuery('SELECT a.produk,b.jenis_produk,b.brand,b.title as n_produk,c.title as n_jenis_produk,d.title as n_brand FROM `sv_stok_view` a left join sv_master_produk b ON a.produk=b.id left join sv_master_jenis_produk c ON c.id=b.jenis_produk LEFT JOIN sv_master_brand d ON d.id=b.brand WHERE a.stok>0 AND b.brand='.$v.' group by b.jenis_produk order by c.title asc ','-Jenis Produk-',array(),'n_jenis_produk','jenis_produk');
            echo form_dropdown_('jenis_produk[]',$opt_brand,'',"id='jenis_produk-$id' onchange='gantijenis(this.value,$id)'");
        }
        function loadprodukz_out(){
            $v=$_POST['v'];
            $id=$_POST['id'];
            $opt_brand=GetOptQuery('SELECT a.produk as produk,b.jenis_produk,b.brand,b.title as n_produk,c.title as n_jenis_produk,d.title as n_brand FROM `sv_stok_view` a left join sv_master_produk b ON a.produk=b.id left join sv_master_jenis_produk c ON c.id=b.jenis_produk LEFT JOIN sv_master_brand d ON d.id=b.brand WHERE a.stok>0 AND b.jenis_produk='.$v.' group by a.produk order by b.title asc ','-Produk-',array(),'n_produk','produk');
            echo form_dropdown_('produk[]',$opt_brand,'',"id='produk-$id' onchange='gantiproduk(this.value,$id)'");
            echo "Part Number : <span id='part_number_$id'></span>";
        }
}
?>