<?php 
/*
Fungsi : Controller untuk Cabang report
*/

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

class Branch_report extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
/*-------------Inisialisasi variabel--------------*/ 
	
	//Menu ID utk keperluan otorisasi
	
	
	//var $menu_pusat_stb_rpt
	var $menu_branch_op_periode  = 116;
	
	var $menu_branch_po_periode = 117;
	
	var $menu_branch_stb_rpt = 99;
	
	var $menu_branch_dn_rpt = 118;
	
	var $menu_branch_mutasi_stok_rpt = 163;
	
	var $menu_branch_supp_report = 168;
	
/*-------------Inisialisasi variabel--------------*/ 	

/*------------Fungsi lokal------------------------*/
	


/*------------Fungsi local------------------------*/	
	function __construct()
	{
		parent::__construct();
		
		$this->load->model('admin/branch_report_model', '', TRUE);
		$this->fungsi->check_login();
	}
	
	
	public function index()
	{	
		$this->admin_branch_report();
		
	}

/*========================================= REPORT LIST SUPPLIER ===================================*/
function branch_supp_report()
{
	//Otorisasi menu
	$this->fungsi->menu_auth($this->menu_branch_supp_report);
	
	$data['menu_path'] = 'ADMINISTRATOR > REPORT BRANCH > REPORT LIST SUPPLIER';
		
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		
	$data['form_action']= site_url('admin/branch_report/branch_supp_report_disp');
	$this->load->view('admin/branch_report_form_supp_rpt', $data);	
		
}

function branch_supp_report_disp()
{
	
	$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
	foreach ($cab  as $cabs);
	
	$data['menu_path'] = 'ADMINISTRATOR > REPORT BRANCH > REPORT LIST SUPPLIER > DISPLAY SUPPLIER '.strtoupper($cabs->cabname);
	
	$data['supp'] = $this->db->query("SELECT m_supp.idsupp, m_supp.suppname, m_supp.addr, m_supp.city,m_supp.prov,m_supp.phone, m_supp.fax, m_supp.codevendor, m_supp.ppn, m_top.desc 
	FROM m_supp INNER JOIN m_top ON m_top.idtop = m_supp.idtop
	WHERE  m_supp.idcab = '".$this->input->post('cb_idcab')."' 
	AND m_supp.idtop = '".$this->input->post('cb_idtop')."' 
	AND m_supp.ppn = '".$this->input->post('cb_ppn')."'")->result();
	
	$data['form_action']= site_url('admin/branch_report/branch_supp_report_disp_xls/'.$this->input->post('cb_idcab').'/'.$this->input->post('cb_idtop').'/'.$this->input->post('cb_ppn').'/'.'xls');
	
	$data['link'] = array('link_back' => anchor('admin/branch_report/branch_supp_report','Back', array('class' => 'back')));	
	$this->load->view('admin/branch_supp_report_disp', $data);	
		
}

function branch_supp_report_disp_xls()
	{
		
		$data['supp'] = $this->db->query("SELECT m_supp.idsupp, m_supp.suppname, m_supp.addr, m_supp.city,m_supp.prov,m_supp.phone, m_supp.fax, m_supp.codevendor, m_supp.ppn, m_top.desc 
	FROM m_supp INNER JOIN m_top ON m_top.idtop = m_supp.idtop
	WHERE  m_supp.idcab = '".$this->uri->segment(4)."' 
	AND m_supp.idtop = '".$this->uri->segment(5)."' 
	AND m_supp.ppn = '".$this->uri->segment(6)."'")->result();
	
		$data['xls'] = 1;
		$this->load->view('admin/branch_supp_report_disp', $data);	
		
	}
	
/*========================================= REPORT LIST SUPPLIER ===================================*/

/*====================================REPORT MUTASI STOK======================================*/
function branch_mutasi_stok()
{
	//Otorisasi menu
	$this->fungsi->menu_auth($this->menu_branch_mutasi_stok_rpt);
	
	$data['menu_path'] = 'ADMINISTRATOR > REPORT BRANCH > REPORT MUTASI STOK';
		
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		
	$data['form_action']= site_url('admin/branch_report/branch_mutasi_stok_disp');
	$this->load->view('admin/branch_report_form_mutasi_stok', $data);	
		
}

function branch_mutasi_stok_disp()
{
	$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
		foreach ($cab  as $cabs);
		
	$data['menu_path'] = 'ADMINISTRATOR > REPORT BRANCH > REPORT MUTASI STOK > '.strtoupper($cabs->cabname).' FROM : '.$this->input->post('txt_date1').' TO : '.$this->input->post('txt_date2');
		
	$data['mutasi'] = $this->db->query("select * from v_stb_sj WHERE  idcab = '".$this->input->post('cb_idcab')."' AND posting BETWEEN '".date("Y-m-d", strtotime($this->input->post('txt_date1')))."' AND '".date("Y-m-d", strtotime($this->input->post('txt_date2')))."' order by posting")->result();
		
		$data['form_action']= site_url('admin/branch_report/branch_mutasi_stok_disp_xls/'.$this->input->post('cb_idcab').'/'.$this->input->post('txt_date1').'/'.$this->input->post('txt_date2').'/'.'xls');
		
	$data['link'] = array('link_back' => anchor('admin/branch_report/branch_mutasi_stok','Back', array('class' => 'back')));
	$this->load->view('admin/branch_report_form_mutasi_stok_disp', $data);	
		
}
function branch_mutasi_stok_disp_xls()
{
	$data['mutasi'] = $this->db->query("select * from v_stb_sj WHERE  idcab = '".$this->uri->segment(4)."' AND posting BETWEEN '".date("Y-m-d", strtotime($this->uri->segment(5)))."' AND '".date("Y-m-d", strtotime($this->uri->segment(6)))."'  order by posting")->result();
	$data['xls']  =1;
	$this->load->view('admin/branch_report_form_mutasi_stok_disp', $data);	
	
}
/*====================================REPORT MUTASI STOK======================================*/
	
/*========================================= REPORT PO PERIODE ===================================*/
	function branch_po_periode()
	{
		//Otorisasi menu
		$this->fungsi->menu_auth($this->menu_branch_po_periode);
		
		$data['menu_path'] = 'ADMIN > BRANCH PURCHASE ORDER REPORT PERIODE';
		
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		$data['form_action']= site_url('admin/branch_report/branch_po_periode_disp');
		$this->load->view('admin/branch_report_form_po', $data);	
		
	}
	
	function branch_po_periode_disp()
	{
		$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
		foreach ($cab  as $cabs);
		
		$data['menu_path'] = 'ADMIN > BRANCH PURCHASE ORDER REPORT > '.strtoupper($cabs->cabname).' FROM : '.$this->input->post('txt_date1').' TO : '.$this->input->post('txt_date2');
		
		$data['po'] = $this->branch_report_model->get_po_byidcab(date("Y-m-d", strtotime($this->input->post('txt_date1'))),date("Y-m-d", strtotime($this->input->post('txt_date2'))),$this->input->post('cb_idcab'))->result();
		$data['link'] = array('link_back' => anchor('admin/branch_report/branch_po_periode','Back', array('class' => 'back')));
		
		$data['form_action']= site_url('admin/branch_report/branch_po_periode_disp_xls/'.$this->input->post('txt_date1').'/'.$this->input->post('txt_date2').'/'.$this->input->post('cb_idcab').'/'.'xls');
		
		$this->load->view('admin/branch_report_disp_form_po', $data);	
	}

function branch_po_periode_disp_xls()
	{
		
		$data['po'] = $this->branch_report_model->get_po_byidcab(date("Y-m-d", strtotime($this->uri->segment(4))),date("Y-m-d", strtotime($this->uri->segment(5))),$this->uri->segment(6))->result();
		$data['xls'] = 1;
		$this->load->view('admin/branch_report_disp_form_po', $data);	
		
	}

/*==========================================	REPORT PO PERIODE end===================================*/

/*==========================================	REPORT OP PERIODE ===================================*/
	function branch_op_periode()
	{
		//Otorisasi menu
		$this->fungsi->menu_auth($this->menu_branch_op_periode);
		
		$data['menu_path'] = 'ADMIN > BRANCH OIL PURCHASE REPORT PERIODE';
		
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		$data['form_action']= site_url('admin/branch_report/branch_op_periode_disp');
		$this->load->view('admin/branch_report_form_op', $data);	
		
	}
	
	function branch_op_periode_disp()
	{
		$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
		foreach ($cab  as $cabs);
		
		$data['menu_path'] = 'ADMIN > BRANCH OIL PURCHASE REPORT > '.strtoupper($cabs->cabname).' FROM : '.$this->input->post('txt_date1').' TO : '.$this->input->post('txt_date2');
		
		$data['op'] = $this->branch_report_model->get_op_byidcab(date("Y-m-d", strtotime($this->input->post('txt_date1'))),date("Y-m-d", strtotime($this->input->post('txt_date2'))),$this->input->post('cb_idcab'))->result();
		$data['link'] = array('link_back' => anchor('admin/branch_report/branch_op_periode','Back', array('class' => 'back')));
		
		$data['form_action']= site_url('admin/branch_report/branch_report_disp_form_op_xls/'.$this->input->post('txt_date1').'/'.$this->input->post('txt_date2').'/'.$this->input->post('cb_idcab').'/'.'xls');
		
		$this->load->view('admin/branch_report_disp_form_op', $data);	
	}

function branch_report_disp_form_op_xls()
	{
		
		$data['op'] = $this->branch_report_model->get_op_byidcab(date("Y-m-d", strtotime($this->uri->segment(4))),date("Y-m-d", strtotime($this->uri->segment(5))),$this->uri->segment(6))->result();
		$data['xls'] = 1;
		$this->load->view('admin/branch_report_disp_form_op', $data);	
		
	}
/*==========================================	REPORT OP PERIODE end===================================*/

/*================================= Stok Report History cabang ======================== */
	
	function admin_stb_report()
	
	
	
	{
		//Otorisasi menu
		$this->fungsi->menu_auth($this->menu_branch_stb_rpt);
		
		$data['menu_path'] = 'ADMIN > BRANCH REPORT STB';
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		$data['form_action']= site_url('admin/branch_report/branch_report_periode_disp');
		$this->load->view('admin/branch_report_form_stb', $data);	
		
	}
	
	
	
	function branch_report_periode_disp()
	{
		$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
		foreach ($cab  as $cabs);
		
		$data['menu_path'] = 'ADMIN > BRANCH REPORT STB >'.strtoupper($cabs->cabname).' FROM DATE : '.$this->input->post('txt_date1').' TO : '.$this->input->post('txt_date2');
		
		$data['cpv_data'] = $this->branch_report_model->get_stb_pusat_bydate(date("Y-m-d", strtotime($this->input->post('txt_date1'))),date("Y-m-d", strtotime($this->input->post('txt_date2'))),$this->input->post('cb_idcab'))->result();
		
		$data['link'] = array('link_back' => anchor('admin/branch_report/admin_stb_report','Back', array('class' => 'back')));
		
		$data['form_action']= site_url('admin/branch_report/branch_report_periode_disp_xls/'.$this->input->post('txt_date1').'/'.$this->input->post('txt_date2').'/'.$this->input->post('cb_idcab').'/'.'xls');
		
		$this->load->view('admin/branch_report_disp_form_stb', $data);
			
	}
	
	function branch_report_periode_disp_xls()
	{
		
		$data['cpv_data'] = $this->branch_report_model->get_stb_pusat_bydate(date("Y-m-d", strtotime($this->uri->segment(4))),date("Y-m-d", strtotime($this->uri->segment(5))),$this->uri->segment(6))->result();
		$data['xls'] = 1;
		$this->load->view('admin/branch_report_disp_form_stb', $data);	
		
	}

/*============================================================ Stok STB Report Pusat end=================================*/	
	
	
	/*================================= Stok Delivery note History cabang ======================== */
	
	function admin_dn_report()
	
	
	{
		//Otorisasi menu
		$this->fungsi->menu_auth($this->menu_branch_dn_rpt);
		
		$data['menu_path'] = 'ADMIN > BRANCH REPORT DELIVERY NOTE';
		if($this->session->userdata('idcab')==1)
		{
			$data['cab'] =   $this->branch_report_model->get_cabang()->result();
		}
		else
		{
			$data['cab'] =   $this->branch_report_model->get_cabang_byidcab($this->session->userdata('idcab'))->result();
		}
		$data['form_action']= site_url('admin/branch_report/branch_report_dn_disp');
		$this->load->view('admin/branch_report_form_dn', $data);	
		
	}
	
	
	
	function branch_report_dn_disp()
	{
		$cab = $this->branch_report_model->get_cabang_byidcab($this->input->post('cb_idcab'))->result();
		foreach ($cab  as $cabs);
		
		$data['menu_path'] = 'ADMIN > BRANCH REPORT DELIVERY NOTE >'.strtoupper($cabs->cabname).' FROM DATE : '.$this->input->post('txt_date1').' TO : '.$this->input->post('txt_date2');
		
		$data['cpv_data'] = $this->branch_report_model->get_dn_pusat_bydate(date("Y-m-d", strtotime($this->input->post('txt_date1'))),date("Y-m-d", strtotime($this->input->post('txt_date2'))),$this->input->post('cb_idcab'))->result();
		
		$data['link'] = array('link_back' => anchor('admin/branch_report/admin_dn_report','Back', array('class' => 'back')));
		
		$data['form_action']= site_url('admin/branch_report/branch_report_dn_disp_xls/'.$this->input->post('txt_date1').'/'.$this->input->post('txt_date2').'/'.$this->input->post('cb_idcab').'/'.'xls');
		
		$this->load->view('admin/branch_report_disp_form_dn', $data);
			
	}
	
	function branch_report_dn_disp_xls()
	{
		
		$data['cpv_data'] = $this->branch_report_model->get_dn_pusat_bydate(date("Y-m-d", strtotime($this->uri->segment(4))),date("Y-m-d", strtotime($this->uri->segment(5))),$this->uri->segment(6))->result();
		$data['xls'] = 1;
		$this->load->view('admin/branch_report_disp_form_dn', $data);	
		
	}

/*============================================================ Stok STB Report Pusat end=================================*/	
	
	
}