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

/*************************************
  * Created :December 2014
  * Creator : Fauzan Rabbani
  * Email   : jhanojan@gmail.com
  * Framework ver. : CI ver.2.2
*************************************/	

class dashboard extends CI_Controller {
	var $utama ='dashboard';
	var $title ='Analysis';
	function __construct()
	{ 
		parent::__construct();
                error_reporting(0);
		 permissionz();
                $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
                $this->output->set_header('Pragma: no-cache');
                $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                
	}
	
	function index()
	{
		$this->inventoryanalysis();
	}
	
	function main()
	{
		//Migrasi 1 Feb 14
		permissionz();
		//Set Global
		//permission();
		//$data = GetHeaderFooter();
		$data['content'] = 'contents/'.$this->utama.'/view';
		//End Global
		
		//Attendance 
		
		$this->load->view('layout/main',$data);
	}
        function visitors(){
            $charts='<chart caption="Temperature Monitoring (in degree C) on on 7/9/2013" xaxisname="Time" yaxismaxvalue="100" linecolor="008ee4" anchorsides="3" anchorradius="5" plotgradientcolor=" " bgcolor="FFFFFF" showalternatehgridcolor="0" showplotborder="0" showvalues="0" divlinecolor="666666" showcanvasborder="0" canvasborderalpha="0" >
            <set label="0" value="34" />
            <set label="3" value="27" />
            <set label="6" value="42" />
            <set label="9" value="50" />
            <set label="12" value="68" />
            <set label="15" value="56" />
            <set label="18" value="48" />
            <set label="21" value="34" />
            <set label="24" value="30" />
            <trendlines>
            <line startvalue="80" endvalue="100" displayvalue="Critical" color="008ee4" istrendzone="1" showontop="0" alpha="35" valueonright="1" />
            <line startvalue="60" endvalue="80" displayvalue="Warning" color="33bdda" istrendzone="1" showontop="0" alpha="35" valueonright="1" />
            </trendlines>
            </chart>';	
            echo $charts;
        }	
        function chart_marketing(){
            $this->load->view('contents/dashboard/chart_marketing');
        }	
        function chart_yearly(){
            $this->load->view('contents/dashboard/chart_yearly');
        }	
        function chart_pelanggan(){
            $this->load->view('contents/dashboard/chart_pelanggan');
        }	
        function chart_pelanggan_bidang(){
            $this->load->view('contents/dashboard/chart_pelanggan_bidang');
        }		
        function chart_sales_plan(){
            $this->load->view('contents/dashboard/chart_sales_plan');
        }	
        function chart_sales_plan_monthly(){
            $this->load->view('contents/dashboard/chart_sales_plan_monthly');
        }	
        function chart_customer_analysis(){
            $this->load->view('contents/dashboard/chart_customer_analysis');
        }	
        function chart_customer_po(){
            $this->load->view('contents/dashboard/chart_customer_po');
        }	
        function chart_customer_by_po(){
            $this->load->view('contents/dashboard/chart_customer_by_po');
        }	
        function chart_customer_po_target(){
            $this->load->view('contents/dashboard/chart_customer_po_target');
        }	
        function chart_customer_by_po_target(){
            $this->load->view('contents/dashboard/chart_customer_by_po_target');
        }	
        	
        function chart_customer_by_po_major(){
            $this->load->view('contents/dashboard/chart_customer_by_po_major');
        }	
        function chart_customer_major(){
            $this->load->view('contents/dashboard/chart_customer_major');
        }
        function chart_min_stok(){
            $this->load->view('contents/dashboard/chart_min_stok');
        }
        function chart_mutasi_stok(){
            $this->load->view('contents/dashboard/chart_mutasi_stok');
        }
        function chart_total_stok(){
            $this->load->view('contents/dashboard/chart_total_stok');
        }
        function chart_umur_stok(){
            $this->load->view('contents/dashboard/chart_umur_stok');
        }
        function chart_fast_stok(){
            $this->load->view('contents/dashboard/chart_fast_stok');
        }
        function chart_exp_stok(){
            $this->load->view('contents/dashboard/chart_exp_stok');
        }
        function data_marketing(){
            $this->load->view('contents/dashboard/data_marketing');
        }   
        function data_monthly(){
            $this->load->view('contents/dashboard/data_monthly');
        }  
        function datadetail(){
            $data['bow']=$_POST['i'];
            $this->load->view('contents/dashboard/datadetail',$data);
        }
        function data_customer(){
            $data['cust']=GetAll('master_pelanggan',array('perusahaan'=>'where/'.$_POST['m']))->result_array();
            $this->load->view('contents/dashboard/data_customer',$data);
        }
        function data_customer_po(){
            $qz='';
            $qbz='';

            if($this->input->post('marketing')){
                $qz=" AND sales='".$this->input->post('marketing')."'";
            }
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                $qbz.=" AND (c.divisi='".$this->session->userdata('divisi')."' AND b.groups='".$this->session->userdata('groups')."' )";
            }
            else{
                    if($this->session->userdata('divisi')){
                        $qbz.=" AND c.divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qbz.=" AND c.groups='".$this->session->userdata('groups')."'";
                    }
            }
            
            if(!diaadmin()){
                $anaknya=anaknya();
                $anak=implode(',',$anaknya);
                
                $qz=" AND (c.`id` =  '".$this->session->userdata('webmaster_marketing')."' OR c.`leader` IN ($anak))";
                
                
            }
            //$data['cust']=GetAll('activity_sales',array('pelanggan'=>'where/'.$_POST['m'],'nilai_po >'=>'where/0'))->result_array();
            $data['cust']=$this->db->query("SELECT a.id id,a.pelanggan pelanggan,a.sales sales,a.catatan catatan,a.nilai_po nilai_po,a.created_on created_on FROM sv_activity_sales a LEFT JOIN sv_master_pelanggan b ON a.pelanggan=b.id LEFT JOIN sv_master_sales c ON a.sales=c.id WHERE b.perusahaan='".$_POST['m']."' $qz $qbz AND a.nilai_po >'0' AND YEAR(a.created_on)='".date('Y')."' ORDER BY a.nilai_po DESC")->result_array();
            
            $this->load->view('contents/dashboard/data_customer_by_bidang',$data);
        }
        function data_customer_by_po(){
            error_reporting(0);
            if(diaadmin()){
            
            }
            else{
                $qbz='';
            }
            
            $qz='';
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                    $qz=" AND (b.divisi='".$this->session->userdata('divisi')."' AND b.groups='".$this->session->userdata('groups')."' )";
                }
            else{
                    if($this->session->userdata('divisi')){
                        $qz=" AND b.divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qz=" AND b.groups='".$this->session->userdata('groups')."'";
                    }
            }
            
            if($this->input->post('marketing')){
                $qz.=" AND sales='".$this->input->post('marketing')."'";
            }
            if(!diaadmin()){
                $anaknya=anaknya();
                $anak=implode(',',$anaknya);
                
                $qz.=" AND (b.`id` =  '".$this->session->userdata('webmaster_marketing')."' OR b.`leader` IN ($anak))";
                
                
            }
            $t=$this->input->post('t');
            $data['qz']=$qz;
            //$data['cust']=GetAll('activity_sales',array('pelanggan'=>'where/'.$_POST['m'],'nilai_po >'=>'where/0'))->result_array();
            $data['cust']=$this->db->query("SELECT a.id id,a.pelanggan pelanggan,a.created_on created_on,a.sales sales,a.catatan catatan, a.nilai_po nilai_po FROM sv_activity_sales a LEFT JOIN sv_master_sales b ON a.sales=b.id  WHERE a.pelanggan='".$_POST['m']."' $qz AND a.nilai_po >'0' AND $t ORDER BY a.nilai_po DESC")->result_array();
            
            $this->load->view('contents/dashboard/data_customer_by_po',$data);
        }
        function data_customer_by_po_major(){
            error_reporting(0);
            if(diaadmin()){
                
            }
            else{
                $qbz='';
            }
            
            $qz='';
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                    $qz=" AND (b.divisi='".$this->session->userdata('divisi')."' AND b.groups='".$this->session->userdata('groups')."' )";
                }
            else{
                    if($this->session->userdata('divisi')){
                        $qz=" AND b.divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qz=" AND b.groups='".$this->session->userdata('groups')."'";
                    }
            }
            
            if($this->input->post('marketing_major')){
                $qz.=" AND sales='".$this->input->post('marketing_major')."'";
            }
            if(!diaadmin()){
               // $anaknya=anaknya();
                //$anak=implode(',',$anaknya);
                //
                //$qz.=" AND (b.`id` =  '".$this->session->userdata('webmaster_marketing')."' OR b.`leader` IN ($anak))";
                
                
            }
            $data['qz']=$qz;
            //$data['cust']=GetAll('activity_sales',array('pelanggan'=>'where/'.$_POST['m'],'nilai_po >'=>'where/0'))->result_array();
            $data['cust']=$this->db->query("SELECT * FROM sv_activity_sales a LEFT JOIN sv_master_sales b ON a.sales=b.id  WHERE a.pelanggan='".$_POST['m']."' $qz AND a.nilai_po >'0' AND YEAR(a.created_on)='".date('Y')."' ORDER BY a.nilai_po DESC")->result_array();
            
            $this->load->view('contents/dashboard/data_customer_by_po',$data);
        }
        function data_po_pelanggan(){
            error_reporting(0);
            $qz='';
            $qbz='';

            if($this->input->post('marketing')!=NULL){
                $qz=" AND a.sales='".$this->input->post('marketing')."'";
            }
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                $qbz.=" AND (c.divisi='".$this->session->userdata('divisi')."' AND b.groups='".$this->session->userdata('groups')."' )";
            }
            else{
                    if($this->session->userdata('divisi')){ 
                        $qbz.=" AND c.divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qbz.=" AND c.groups='".$this->session->userdata('groups')."'";
                    }
            }
            $start=$_POST['start'];
            $end=$_POST['end'];
            if($start==NULL && $end==NULL){
                $title=GetMonthFull(date('m')).' '.date('Y');
                $querynyaz="MONTH(a.tanggal)='".date('m')."' AND YEAR(a.tanggal)='".date("Y")."'";
                
            }else{
                if($end==NULL){
                    $end=date('Y-m-d');
                }
                $title=GetTanggalIndo($start).' - '.GetTanggalIndo($end);
                $querynyaz="a.tanggal>='$start' AND a.tanggal<='$end'";
            }
            
            if(!diaadmin()){
                $anaknya=anaknya();
                $anak=implode(',',$anaknya); 
                
                //$qz=" AND (c.`id` =  '".$this->session->userdata('webmaster_marketing')."' OR c.`leader` IN ($anak))";
                
            }
            //$data['cust']=GetAll('activity_sales',array('pelanggan'=>'where/'.$_POST['m'],'nilai_po >'=>'where/0'))->result_array();
            $data['cust']=$this->db->query("SELECT a.id id,a.pelanggan pelanggan,a.sales sales,a.catatan catatan,a.nilai_po nilai_po,a.created_on created_on FROM sv_activity_sales a LEFT JOIN sv_master_pelanggan b ON a.pelanggan=b.id LEFT JOIN sv_master_sales c ON a.sales=c.id WHERE a.pelanggan='".$_POST['m']."' $qz $qbz AND a.nilai_po >'0' AND ($querynyaz) ORDER BY a.nilai_po DESC")->result_array();
            
            $this->load->view('contents/dashboard/data_customer_by_bidang',$data);
        }
        function data_po_pelanggan_bidang(){ 
            error_reporting(0);
            $qz='';
            $qbz='';

            if($this->input->post('marketing')!=NULL){
                $qz=" AND a.sales='".$this->input->post('marketing')."'";
            }
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                $qbz.=" AND (c.divisi='".$this->session->userdata('divisi')."' AND b.groups='".$this->session->userdata('groups')."' )";
            }
            else{
                    if($this->session->userdata('divisi')){
                        $qbz.=" AND c.divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qbz.=" AND c.groups='".$this->session->userdata('groups')."'";
                    }
            }
            $start=$_POST['start'];
            $end=$_POST['end'];
            if($start==NULL && $end==NULL){
                $title=GetMonthFull(date('m')).' '.date('Y');
                $querynyaz="MONTH(a.tanggal)='".date('m')."' AND YEAR(a.tanggal)='".date("Y")."'";
                
            }else{
                if($end==NULL){
                    $end=date('Y-m-d');
                }
                $title=GetTanggalIndo($start).' - '.GetTanggalIndo($end);
                $querynyaz="a.tanggal>='$start' AND a.tanggal<='$end'";
            }
            
            
            if(!diaadmin()){
                $anaknya=anaknya();
                $anak=implode(',',$anaknya);
                
                //$qz=" AND (c.`id` =  '".$this->session->userdata('webmaster_marketing')."' OR c.`leader` IN ($anak))";
                
                
            }
            //$data['cust']=GetAll('activity_sales',array('pelanggan'=>'where/'.$_POST['m'],'nilai_po >'=>'where/0'))->result_array();
            $data['cust']=$this->db->query("SELECT a.id id,a.pelanggan pelanggan,a.sales sales,a.catatan catatan,a.nilai_po nilai_po,a.created_on created_on FROM sv_activity_sales a LEFT JOIN sv_master_pelanggan b ON a.pelanggan=b.id LEFT JOIN sv_master_sales c ON a.sales=c.id WHERE b.perusahaan='".$_POST['m']."' $qz $qbz AND a.nilai_po >'0' AND ($querynyaz) ORDER BY a.nilai_po DESC")->result_array();
            
            $this->load->view('contents/dashboard/data_customer_by_bidang_perusahaan',$data);
        }
        function targetanalysis(){
                $data['group']=1;
                error_reporting(E_ALL);
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		 
		$this->load->view('layout/main',$data);
        }
        function activityanalysis(){
                $data['group']=2;
                error_reporting(E_ALL); 
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		
		$this->load->view('layout/main',$data);
            
        }
        function customeranalysis(){
            
            $data['group']=3;
                error_reporting(E_ALL);
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		
		$this->load->view('layout/main',$data);
        }
        function stockanalysis(){
            $data['group']=4;
                error_reporting(E_ALL);
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		
		$this->load->view('layout/main',$data);
            
        }
        function solutionforceanalysis(){
            $data['group']=5;
                error_reporting(E_ALL);
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		
		$this->load->view('layout/main',$data);
        }
        function inventoryanalysis(){
            $data['group']=6;
            $data['type']='Inventory Analysis';
                error_reporting(0);
		$data['content'] = 'contents/'.$this->utama.'/viewbaru';
		
		$this->load->view('layout/main',$data);
            
        }
        function loadjenis(){
            $ids=rand(111,9999);
            $bag=$this->input->post('bg');
            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 jenis".$ids."' id='jp'");
            echo"<script>
                    $(document).ready(function(e){ 
                        $('.jenis".$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>";
        }
}
?>