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

class Popup_pr_inv extends CI_Controller {

	/*Limit Paging*/
	var $limit = 20;
	function __construct()
	{
		parent::__construct();
		$this->load->model('branch/branch_model', '', TRUE);
		$this->load->model('branch/cabang_model', '', TRUE);
	}

	function index()
	{
			//$this->fungsi->fungsi();
			$this->list_pr_inv();
	}

//$detail = $this->Cabang_model-> get_total_harga_bycab($this->uri->segment(4))->result();

/*List PR*/
function list_pr_inv()
{
//Default
if($this->session->userdata('txt_cari')=='')
{
$this->session->set_userdata('txt_cari', '');
$this->session->set_userdata('preq_no');
}
//$this->fungsi->menu_auth();	
  $data['title'] ='.::PT WGI Web Application::. | Popup List Purchase Requisition Invoice';
  $data['sub_title'] = 'POPUP PURCHASE REQUISITION';
  $data['content'] = 'popup/popup_pr_inv';	
  $data['form_action']= site_url('popup/popup_pr/');

//Otorisasi menu

		
		$this->fungsi->trans_auth($this->session->userdata('view'));
		$data['form_action']= site_url('popup/popup_pr/popup_pr_inv');
	
if(isset($_POST['button']))
			{
				$data['txt_cari'] = $this->input->post('txt_cari'); // -> ini null jadi error
				//set session user data untuk pencarian, untuk paging pencarian
				$this->session->set_userdata('txt_cari', $data['txt_cari']);
				
			} 
			else 
			{
				$data['txt_cari'] = $this->session->userdata('txt_cari');
				
			}
			

/* Setting Parameter Untuk Paging */
$uri_segment = 4;
$this->fungsi->format_idr($this->fungsi->get_pc_bal($this->session->userdata('idcab')));
$offset =    $this->uri->segment($uri_segment);
$preq = $this->branch_model->search_pr($this->limit, $offset,$data['txt_cari'])->result();
//$num_rows = $this->branch_model->count_all_pr($data['txt_cari']);
$num_rows = 5;
$config['base_url'] = site_url('popup/popup_pr/list_pr/');
if ($num_rows > 0) // Jika query menghasilkan data
		{
			// Membuat pagination			
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $this->limit;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$i = 0 + $offset;
			
			$tmpl = array( 'table_open'    => '<table border="0" cellpadding="1" cellspacing="1" id="list">',
						  'row_alt_start'  => '<tr class="zebra">',
						  'row_alt_end'    => '</tr>'
						  );
			$this->table->set_template($tmpl);

			// Set heading untuk tabel
			$this->table->set_empty("0;");
			$this->table->set_heading('PR Number', 'Quantity', 'Price', 'Total', 'Vol Available', 'Option');
		    //print_r($preq);
			foreach ($preq  as $preqs)
			{

			$total = $preqs->quantity * $preqs->c_amt_bapi;
			
			$available = $preqs->quantity - $this->fungsi->get_vol($preqs->preq_no, $preqs->year);
			
			//$avail = $available - $pur;
			
$this->table->add_row($preqs->preq_no, number_format($preqs->quantity), $this->fungsi->format_idr($preqs->c_amt_bapi), $this->fungsi->format_idr($total), number_format($available), anchor('#','Select',array('class' => 'ok','onclick' => 'sendValue('.'\''.$preqs->preq_no.'\''.','.'\''.number_format($preqs->quantity).'\''.','.'\''. $this->fungsi->format_idr($preqs->c_amt_bapi).'\''.','.'\''. $this->fungsi->format_idr($total).'\''.','.'\''.number_format($available).'\''.');')));

			}
			$data['table'] = $this->table->generate();
			$data['message']= '';
			}
			else
			{
			$data['message']= 'DATA EMPTY.';
			}		
		//$data['link'] = array('link_add' => anchor('branch/branch_pr/add_pr_proc','Add Purchase Requisition', array('class' => 'add','target' => '_blank')));
		$this->load->view('templates/theme01/template_popup', $data);


}



}

