<style>
 
    </style>
    <script>
    function liatdetail(isi){
        $('#datadetail').load('<?php echo base_url()?>dashboard/datadetail',{i:isi});
    }
    </script>
<?php

            $start=$_POST['start'];
            $end=$_POST['end'];
            $act=$_POST['act'];
            if($start==NULL && $end==NULL){
                $title=GetMonthFull(date('m')).' '.date('Y');
                $querynyaz="MONTH(tanggal)='".date('m')."' AND YEAR(tanggal)='".date("Y")."'";
            }
            else if($start!=NULL && $end!=NULL){
                
                $title=GetTanggalIndo($start).' - '.GetTanggalIndo(date('Y-m-d'));
                $querynyaz="tanggal>='$start' AND tanggal<='".date('Y-m-d')."'";
            }
            else{
                $title=GetTanggalIndo($start).' - '.GetTanggalIndo($end);
                $querynyaz="tanggal>='$start' AND tanggal<='$end'";
            }
            if($act!=NULL){
                $querynyaz.=" AND jenis_aktivitas='$act'";
            }

$divisnya=GetValue('divisi','sv_master_sales',array('id'=>'where/'.$_POST['m']));
$querynya="SELECT * FROM sv_activity_sales WHERE sales='".$_POST['m']."' AND ($querynyaz) GROUP BY pelanggan ";


$cust=$this->db->query($querynya)->result_array();
//lastq();
$lazz=GetAll('ref_activity',array('status'=>'where/Aktif','type'=>'where/'.$divisnya));
$act=$lazz->result_array();
$spans=$lazz->num_rows();?>
<table border="1px;" cellpadding="1px;" width="100%">
    <thead>
        <tr style="background-color: #E2574C!important; color:white!important;">
        <th colspan="<?php echo (2+$spans)?>" style="text-align: center!important;">Detail Aktivitas <?php echo GetValue('nama_lengkap','master_sales',array('id'=>'where/'.$_POST['m']))?> </th>
        </tr>
        <tr style="background-color: #E2574C!important; color:white!important;">
        <th>No</th>
            <th>Customer</th>
    
        <?php foreach($act as $ak){?>
        <th style="text-align:center!important"><?php echo $ak['notes']?></th><?php }?>
        </tr></thead>
    <?php $ap=1;
    foreach($cust as $plg){
        $judulpelanggan=GetValue('title','master_pelanggan',array('id'=>'where/'.$plg['pelanggan']));
        ?>
    <tr style="background-color: #A9FF96!important;cursor:pointer;" data-toggle="collapse" data-target=".demo<?php echo $ap?>">
        
        <td><?php echo $ap?></td>
        <td><?php echo $judulpelanggan?></td><?php foreach($act as $ak){
            $oi=$this->db->query("SELECT * FROM sv_activity_sales WHERE sales='".$_POST['m']."' AND ($querynyaz) AND pelanggan='".$plg['pelanggan']."' AND jenis_aktivitas='".$ak['id']."' ")->num_rows();
            if($oi==0){
                $hasil='';
            }else{
                $hasil=$oi;
            }
            
            ?>
        <td align="center"><?php echo "<strong>".$hasil."</strong>"?></td><?php }?>
    </tr>
    <?php
    $cust_div=$this->db->query("SELECT * FROM sv_master_pelanggan_divisi WHERE pelanggan='".$plg['pelanggan']."'")->result_array();
    foreach($cust_div as $plg){?>
    <tr style="background-color:white;" class="collapse demo<?php echo $ap?>">
        <td style="border-right:0px">&nbsp;</td>
        <td><?php echo $plg['title']?></td>
            <?php foreach($act as $ak){
            $oi=$this->db->query("SELECT * FROM sv_activity_sales WHERE sales='".$_POST['m']."' AND ($querynyaz) AND pelanggan='".$plg['pelanggan']."' AND jenis_aktivitas='".$ak['id']."' AND pelanggan_divisi='".$plg['id']."' ");
            $dis=$this->db->last_query();
            if($oi->num_rows()==0){
                $hasil='';
            }else{
                $hasil=$oi->num_rows();
            }
            $judul=array();
            foreach($oi->result_array() as $obun){
                $judul[]='('.$obun['tanggal'].') '.$obun['catatan'];
            }
            $ssz=implode('
',$judul);
            ?>
        <td align="center"><?php //echo '<a href="#" onclick="liatdetail(\''.json_encode($oi->result_array()).'\')"><strong>'.$hasil.'</strong></a>'?>
        <a href="#datadetail" title='<?php echo $ssz?>' onclick='liatdetail(<?php echo json_encode($oi->result_array())?>)'><strong><?php echo $hasil ?></strong></a>
        </td><?php }?>
    </tr><?php }?><?php $ap++; }?>
    
</table>
    <br/>
    <br/>
    <?php
    
            $bow=$this->db->query("SELECT * FROM sv_activity_sales WHERE sales='".$_POST['m']."' AND ($querynyaz) ")->result_array();
    ?>
    <div id='datadetail'>
    
    </div>
    <script>
        $('.collapse').on('show.bs.collapse', function () {
    $('.collapse.in').collapse('hide');
});
        </script>