<div class="row">
  <!-- begin col-8 -->
  <div class="col-sm-12">
      <!-- begin panel -->
      <div class="panel panel-grey">
          <div class="panel-heading">
            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-expand"><i class="fa fa-expand"></i></a>
            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-remove"><i class="fa fa-times"></i></a>
          </div>
          <div class="panel panel-body table-responsive">
              <table class="table table-bordered table-hover table-striped table-td-valign-middle">
                  <thead>
                  <tr class="inverse">
                    <th rowspan="3" class="text-center">No.</th>
                    <!-- <th rowspan="3" class="text-center">Aksi</th> -->
                    <th rowspan="3" class="text-center">Status</th>
                    <th rowspan="3" class="text-center">Nomor Sampel</th>
                    <th colspan="2" rowspan="2" class="text-center">Kualitas</th>
                    <th rowspan="3" class="text-center">Kemasan</th>
                    <th colspan="3" rowspan="2" class="text-center">Penanganan Sampel</th>
                    <th colspan="3" rowspan="2" class="text-center">Berat (gram)</th>
                    <th colspan="12" class="text-center">Parameter Uji</th>
                    <th colspan="6" class="text-center">Penyimpanan Sampel</th>
                    <th rowspan="3" class="text-center">Keterangan</th>
                  </tr>
                  <tr class="inverse">
                    <th colspan="5" class="text-center">Proksimat</th>
                    <th colspan="2" class="text-center"></th>
                    <th rowspan="2" class="text-center">TDN</th>
                    <th colspan="2" class="text-center"></th>
                    <th colspan="2" class="text-center"></th>
                    <th colspan="3" class="text-center">Sampel Kerja</th>
                    <th colspan="3" class="text-center">Sampel Arsip</th>
                  </tr>
                  <tr class="inverse">
                    <th class="text-center">Baik</th>
                    <th class="text-center">Tidak&nbsp;Baik</th>
                    <th class="text-center">B</th>
                    <th class="text-center">L</th>
                    <th class="text-center">K</th>
                    <th class="text-center">B</th>
                    <th class="text-center">K</th>
                    <th class="text-center">KA1</th>
                    <th class="text-center">Air</th>
                    <th class="text-center">Abu</th>
                    <th class="text-center">PK</th>
                    <th class="text-center">LK</th>
                    <th class="text-center">SK</th>
                    <th class="text-center">Ca</th>
                    <th class="text-center">P</th>
                    <th class="text-center">Ur</th>
                    <th class="text-center">Af</th>
                    <th class="text-center">NDF</th>
                    <th class="text-center">MBM</th>
                    <th class="text-center">Fz</th>
                    <th class="text-center">Rf</th>
                    <th class="text-center">R.AC</th>
                    <th class="text-center">Fz</th>
                    <th class="text-center">Rf</th>
                    <th class="text-center">R.AC</th>
                  </tr>
                  </thead>
                  <tbody>
                    <?php
                        $id_uji = array();
                        $i=0;
                        foreach($data as $r){
                          $id_uji[$i] = $r['id_uji'];
                          $i++;
                        }
                        $id_uji = array_unique($id_uji);
                        $row = array();

                        foreach($id_uji as $k){
                          $row[$k]['id_uji']= array();
                          $row[$k]['id_status']= array();
                          $row[$k]['status_sampel']= array();
                          $row[$k]['keterangan']= array();
                          $row[$k]['detail']= array();
                          foreach($data as $r){
                            if($r['id_uji'] == $k){
                              $row[$k]['id_uji'][] = $r['id_uji'];
                              $row[$k]['id_status'][] = $r['id_status'];
                              $row[$k]['status_sampel'][] = $r['status_sampel'];
                              $row[$k]['keterangan'][] = $r['keterangan'];
                              $row[$k]['detail'][] = $r['detail'];
                              $row[$k]['data_sampel'][] = $r;
                            }
                          }
                        }
                    ?>
                      <?php $z = 1; foreach($row as $r){ ?>
                        <tr>
                          <?php $tr = false; ?>
                          <td class="text-center" <?php echo 'rowspan="' . count($r['id_uji']) . '"' ?>>
                            <?php echo $this->uri->segment(4) + $z++ ?>
                          </td>
                          <td class="text-center" <?php echo 'rowspan="' . count($r['id_uji']) . '"' ?>>
                            <?php echo str_replace('Status','',$r['status_sampel'][0]).'<br>['. str_replace(' ', '&nbsp;', $r['detail'][0]).']'; ?>
                            <?php echo isset($r['keterangan'][0]) && $r['status_sampel'][0] === 'Status III' ? '<br>'.$r['keterangan'][0] : '' ?>
                          </td>

                          <?php foreach ($r['data_sampel'] as $s) {?>

                          <?php if ($tr) { ?>
                              <tr>
                          <?php }$tr = true ?>
                          <td class="text-center">
                              <?php $pk = strlen($s['id_sampel']);
                                if($pk == 3) $idsm = '0'.$s['id_sampel'];
                                else if($pk == 2) $idsm = '00'.$s['id_sampel'];
                                else if($pk == 1) $idsm = '000'.$s['id_sampel'];

                                echo $idsm;
                              ?>
                          </td>
                          <td><?php echo $s['kualitas']=='Baik' ?'√':'-'?></td>
                          <td><?php echo $s['kualitas']=='Tidak Baik' ?'√':'-'?></td>
                          <td><?php echo $s['kemasan'] ?></td>
                          <td><?php echo $s['jenis_penanganan']=='Basah'?'√':'-' ?></td>
                          <td><?php echo $s['jenis_penanganan']=='Lembab'?'√':'-' ?></td>
                          <td><?php echo $s['jenis_penanganan']=='Kering'?'√':'-' ?></td>
                          <td><?php echo $s['jenis_berat']=='Basah'?$s['berat_sampel']:'-' ?></td>
                          <td><?php echo $s['jenis_berat']=='Kering'?$s['berat_sampel']:'-' ?></td>
                          <td><?php echo $s['jenis_berat']=='Kadar Air 1'?$s['berat_sampel']:'-' ?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '1|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '2|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '3|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '4|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '5|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '6|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '7|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '8|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '9|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '10|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '11|') !== false ? '√' : '-'?></td>
                          <td><?php echo strpos($s['jenis_pengujian'], '12|') !== false ? '√' : '-'?></td>
                          <td><?php echo $s['sampel_kerja']=='1'?'√':'-' ?></td>
                          <td><?php echo $s['sampel_kerja']=='2'?'√':'-' ?></td>
                          <td><?php echo $s['sampel_kerja']=='3'?'√':'-' ?></td>
                          <td><?php echo $s['sampel_arsip']=='1'?'√':'-' ?></td>
                          <td><?php echo $s['sampel_arsip']=='2'?'√':'-' ?></td>
                          <td><?php echo $s['sampel_arsip']=='3'?'√':'-' ?></td>
                          <td><?php echo $s['jenis_klasifikasi'] ?></td>
                        </tr>
                        <?php } ?>

                      <?php } ?>
                  </tbody>
              </table>
          </div>
          <div class="row">
            <div class="col-sm-12" style="margin-top: 10px;">
                <?php if($link_paging){?>
                    <ul class="pagination pagination-sm no-margin">
                        <?php echo $link_paging; ?>
                    </ul>
                <?php } ?>
            </div>
        </div>
      </div>
      <!-- end panel -->
  </div>
</div>
