<?php 
            
            $where_in=array();
            $where['nama_lengkap']='order/asc';
            $anaknya=anaknya();
            if(!diaadmin()){
            $where_in['leader']=$anaknya;
            $where['id']='or_where/'.$this->session->userdata('webmaster_id');
            }
            if(diasales()){
                //$this->db->or_where('sv_a.created_by',$this->session->userdata('webmaster_id'));
            
            $where['id']='or_where/'.$this->session->userdata('webmaster_id');
            
            }
            if(diaadmin()){
                
        //$wherez['status']='where/Aktif';$qbz='';
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                    $qbz=" WHERE (divisi='".$this->session->userdata('divisi')."' AND groups='".$this->session->userdata('groups')."' )";
                }
                else{
                    if($this->session->userdata('divisi')){
                    $qbz=" WHERE divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qbz=" WHERE groups='".$this->session->userdata('groups')."'";
                    }
                }
                
            $anak=implode(',',$anaknya);
            $q=" SELECT * FROM (`sv_master_sales`) $qbz ORDER BY `nama_lengkap` asc";
            if($this->session->userdata('divisi')) $and.=" AND `divisi`='".$this->session->userdata('divisi')."'";
                $opt_sales=GetOptQuery($q,'-Name-',array(),'nama_lengkap');
            }
            else{
                $qbz='';
            if($this->session->userdata('divisi') && $this->session->userdata('groups')){                
                    $qbz=" AND (divisi='".$this->session->userdata('divisi')."' AND groups='".$this->session->userdata('groups')."' )";
                }
                else{
                    if($this->session->userdata('divisi')){
                    $qbz=" AND divisi='".$this->session->userdata('divisi')."'";
                    }
                    elseif($this->session->userdata('groups')){
                        $qbz=" AND groups='".$this->session->userdata('groups')."'";
                    }
                }
                
            $anak=implode(',',$anaknya);
            $q=" SELECT * FROM (`sv_master_sales`) WHERE (`id` =  '".$this->session->userdata('webmaster_marketing')."' OR `leader` IN ($anak)) $qbz ORDER BY `nama_lengkap` asc";
       if($this->session->userdata('divisi')) $and.=" AND `divisi`='".$this->session->userdata('divisi')."'";
                $opt_sales=GetOptQuery($q,'-Name-',array(),'nama_lengkap');
            }
            //lastq();
           // print_mz($opt_sales);
                //lastq(); 
            
                $opt_year=array(''=>'-Year-');
               for($a=2016;$a<=date('Y');$a++){ 
                   $opt_year[$a]=$a;
               }
                ?>
<script>
    $(document).ready(function(e){
        $('#datapelanggan_bidang').load('<?php echo base_url()?>dashboard/chart_pelanggan_bidang');
    });
    function cari_pelangganzz(){
        var marketingz=$('#marketing_bidang').val();
        var marketing=$('#limit_bidang').val();
        var start=$('#start_bidang').val();
        var end=$('#end_bidang').val();
        $('#datapelanggan_bidang').load('<?php echo base_url()?>dashboard/chart_pelanggan_bidang',{limit:marketing,s:start,e:end,marketing:marketingz});
        //if(start && end){}
    };
    </script>
<style>
    .centerz{
        float:none!important;
        margin:0 auto;
    }
    input[type="text"]{
        padding:0!important;
    }
</style>
<div class="col-md-12">
    <div class="col-md-12 centerz"><center>
            <label></label>&nbsp;&nbsp;&nbsp;<?php echo form_dropdown('marketing_bidang',$opt_sales,$_POST['marketing'],'class="select2" id="marketing_bidang"')?>&nbsp;&nbsp;&nbsp;<?php echo form_dropdown('limit_bidang',array(''=>'-Number-','10'=>'10','20'=>'20','50'=>'50',),$_POST['marketing'],'class="select2" id="limit_bidang"')?>&nbsp;&nbsp;&nbsp;<input type="text" name="start_bidang" id="start_bidang" class="datepicker" data-provide="datepicker" data-date-format="yyyy-mm-dd" style="border-radius: 5px!important;height:26px;text-indent:37px;" placeholder="Periode : Start">&nbsp;-&nbsp;<input type="text" name="end_bidang" id="end_bidang" class="datepicker" data-provide="datepicker" data-date-format="yyyy-mm-dd" style="border-radius: 5px!important;height:26px;text-indent:37px;" placeholder="Periode : End"><?php //echo form_dropdown('year',$opt_year,$_POST['year'],'class="select2" id="year"')?>
        <button type="button" id="search" onclick="cari_pelangganzz()">Search</button></center>
    </div>
</div>
<div id="datapelanggan_bidang"></div>