<div class="row">
  <!-- begin col-8 -->
  <div class="col-sm-12">
      <!-- begin panel -->
      <div class="panel panel-grey">
          <div class="panel-heading">
            <div class="panel-heading-btn">
                <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>
            <?php echo menu_parameter('disposisi', false, null, $role_analis) ?>
          <div style="margin-top: 5px;">
            <button class="btn btn-primary" id="bt_cari1" onclick="cari1();"><span class="fa fa-search"></span> Pencarian</button>
            <button class="btn btn-primary" id="bt_cari2" onclick="cari2();"><span class="fa fa-search"></span> Pencarian</button>
          </div>

            <hr>
            <?php $this->load->view('pengajuan/filter_disposisi'); ?>

          </div>

          <div class="panel panel-body table-responsive">
              <table class="table table-bordered table-hover table-striped table-td-valign-middle">
                  <thead>
                  <tr>
                    <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>
                    <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>
                    <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 <?php echo 'rowspan="' . count($r['id_uji']) . '"' ?>>
                            <div class="btn-group m-b-5 m-r-5">
                              <a href="javascript:;" class="btn btn-inverse">Aksi</a>
                              <a href="javascript:;" data-toggle="dropdown" class="btn btn-grey dropdown-toggle" aria-expanded="false">
                                  <span class="caret"></span>
                              </a>
                              <ul class="dropdown-menu pull-right" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(70px, 32px, 0px);">
                                  <li>
                                    <a target="_blank" href="<?php echo site_url('download_dok/download_disposisi?id_uji='.$r['id_uji'][0]) ?>">Download Disposisi</a>
                                  </li>

                                  <?php if((int)$r['id_status'][0] == 11) { ?>
                                  <?php if(in_array($idGroup, array('1','4'))) { ?>
                                  <li>
                                    <a target='_blank' href="<?php echo site_url('download_dok/cetak_lhp?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP</a>
                                  </li>
                                  <li>
                                    <a target='_blank' href="<?php echo site_url('download_dok/download_lhp_af?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP Aflatoksin</a>
                                  </li>
                                  <li>
                                    <a target='_blank' href="<?php echo site_url('download_dok/download_lhp_tdn?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP TDN</a>
                                  </li>
                                  <li>
                                    <a href="<?php echo site_url('sampel/asam_amino?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>" class="">Asam Amino</a>
                                  </li>
                                  <li>
                                    <a href="#modal-alert3-<?php echo $r['id_uji'][0] ?>" data-toggle="modal">Download Sertifikat</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 10) { ?>
                                  <?php if(in_array($idGroup, array('1','9', '2'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/lhp?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">ACC LHP</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 9) { ?>
                                  <?php if(in_array($idGroup, array('1','4'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/lhp?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Buat Draft LHP</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 8) { ?>
                                  <?php if(in_array($idGroup, array('1','2'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/lhu?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">ACC LHU</a>
                                  </li>
                                  <li>
                                    <a target="_blank" href="<?php echo site_url('download_dok/download_lhu?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Download LHU</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 7) { ?>
                                  <?php if(in_array($idGroup, array('1','5'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/verifikasi_penyelia?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Verifikasi Penyelia</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 6) { ?>
                                  <?php if(in_array($idGroup, array('1','3'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/mulai_uji_sampel?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Cek Uji Analis</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 5) { ?>
                                  <?php if(in_array($idGroup, array('1','5'))) { ?>
                                  <!-- <li>
                                    <a target="_blank" href="https://view.officeapps.live.com/op/view.aspx?src=<?php //echo base_url('template/Penyiapan-Sampel.doc') ?>">Download Penyiapan Sampel</a>
                                  </li> -->
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/penyiapan_uji?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Cek Penyiapan Uji Sampel</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 4) { ?>
                                  <?php if(in_array($idGroup, array('1','8'))) { ?>
                                  <li>
                                    <a href="<?php echo site_url('sampel/pengajuan/penyiapan_uji?id_uji='.$r['id_uji'][0].'&status='.$r['id_status'][0]) ?>">Penyiapan Uji</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>

                                  <?php if((int)$r['id_status'][0] == 3) { ?>
                                  <?php if(in_array($idGroup, array('1','7'))) { ?>
                                  <li>
                                    <a href="#modal-alert-<?php echo $r['id_uji'][0] ?>" data-toggle="modal">Verifikasi Deputi MT</a>
                                  </li>
                                  <?php } ?>
                                  <?php } ?>
                              </ul>
                            </div>
                          </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 echo nomor_id($s['id_sampel'])?></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 } ?>

                        <div class="modal fade" id="modal-alert-<?php echo $r['id_uji'][0] ?>" style="display: none;" aria-hidden="true">
                          <div class="modal-dialog">
                              <div class="modal-content">
                                  <div class="modal-body">
                                      <div class="alert alert-info m-b-0">
                                          <p>
                                            <b>Peringatan:</b>
                                            <p>Apakah anda yakin akan memverifikasi penyiapan sampel ini?</p>
                                      </div>
                                  </div>
                                  <div class="modal-footer">
                                      <a href="<?php echo site_url('sampel/pengajuan/siapkan_sampel?id_uji='.$r['id_uji'][0].'&status=4') ?>" class="btn width-100 btn-sm btn-primary">Ya</a>
                                      <!-- <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Tidak</a> -->
                                      <a href="#modal-alert2-<?php echo $r['id_uji'][0] ?>" class="btn width-100 btn-sm btn-danger" data-toggle="modal">Tidak</a>
                                  </div>
                              </div>
                          </div>
                      </div>

                      <div class="modal fade" id="modal-alert2-<?php echo $r['id_uji'][0] ?>" style="display: none;" aria-hidden="true">
                          <div class="modal-dialog">
                              <div class="modal-content">
                                <form action="<?php echo site_url("sampel/pengajuan/tolak_deputi") ?>" method="post">
                                  <div class="modal-body">
                                      <div class="alert alert-info m-b-0">
                                        <b>Masukkan Alasan:</b>
                                        <input type="hidden" name="id_uji2" value="<?php echo $r['id_uji'][0]; ?>">
                                        <textarea class="form-control" name="keterangan"></textarea>
                                      </div>
                                  </div>
                                  <div class="modal-footer">
                                      <button type="submit" class="btn btn-info btn-sm">Simpan Alasan</button>
                                      <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Batal</a>
                                  </div>
                                </form>
                              </div>
                          </div>
                      </div>

                      <div class="modal fade" id="modal-alert3-<?php echo $r['id_uji'][0] ?>" style="display: none;" aria-hidden="true">
                          <div class="modal-dialog">
                              <div class="modal-content">
                                <div class="modal-header">
                                <h5 class="modal-title">Download Sertifikat</h5>
                                </div>
                                <div class="modal-body">
                                  <div class="row">
                                    <div class="col-sm-2 text-center">
                                      <label>No. Sampel</label>
                                    </div>
                                    <div class="col-sm-2 text-center">
                                      <label>Sertifikat</label>
                                    </div>
                                  </div>
                                  <?php foreach($r['data_sampel'] as $d) { ?>
                                    <div class="row" style="margin-bottom:3px;">
                                      <div class="col-sm-2 text-center">
                                        <?php echo nomor_id($d['id_sampel']); ?>
                                      </div>
                                      <div class="col-sm-2 text-center">
                                        <a target="_blank" href="<?php echo site_url('download_dok/download_sertifikat?id_sampel='.$d['id_sampel']) ?>" class="btn btn-primary btn-xs">Download</a>
                                      </div>
                                    </div>
                                  <?php } ?>
                                </div> 
                              </div>
                          </div>
                      </div>
                      <?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>

<script> //JS UNTUK ANALIS DAN DISPOSISI FILTER
		$("#edit_analis, #cetak_analis, #tb_cari, #bt_cari2").hide();

    <?php if(!empty($filter) && $filter['filter_cari']) {?>
      $('#tb_cari').show();
    <?php } ?>

		function onEdit(){
			$('#form_edit_analis').submit();
		}

		function onCheck(x) {
			if($('#id_check'+x).is(':checked')){
					$("#edit_analis, #cetak_analis").show();
			}else{
				$("#edit_analis, #cetak_analis").hide();
			}
		}

		function cari1(){
			$("#bt_cari2").show();
			$("#bt_cari1").hide();

			$("#tb_cari").show();
		}

		function cari2(){
			$("#bt_cari2").hide();
			$("#bt_cari1").show();

			$("#tb_cari").hide();
		}
</script>
