<?php
if(!empty($data[0]) && isset($data[0])){
  $keys2 = array_keys($data[0]);

  $keys = array();
  foreach($keys2 as $r){
      $keys[] = ucwords(str_replace("_", " ",$r));
  }
}
?>
<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>
                <a href="<?php echo site_url('inventaris/bahan_kimia/create_edit'); ?>" class="btn btn-primary">Tambah Data</a>
                <hr>
            </div>
            <?php if(!empty($data[0]) && isset($data[0])){ ?>
            <div class="panel panel-body table-responsive">
                <table class="table table-bordered table-hover table-striped">
                    <thead class="text-center">
                        <tr class="inverse">
                            <!-- <?php foreach ($keys as $key) {?>
                                <?php if($key != 'Id Bahan') { ?>
                                  <th class="text-center"><?php echo $key ?></th>
                                <?php } ?>
                            <?php } ?> -->
                            <th rowspan="3">No.</th>
                            <th rowspan="3">Aksi</th>
                            <th rowspan="3">Nama&nbsp;Bahan Kimia</th>
                            <th rowspan="3">Rumus Kimia</th>
                            <th rowspan="3">Bentuk</th>
                            <th colspan="5">Spesifikasi</th>
                            <th rowspan="3">Lot & Tanggal Kadaluarsa</th>
                            <th rowspan="3">Jenis Kemasan</th>
                            <th colspan="2">Jumlah</th>
                            <th rowspan="3">Total</th>
                            <th rowspan="3">Lokasi</th>
                            <th rowspan="3">Nomor Katalog</th>
                            <th rowspan="3">Lot</th>
                            <th rowspan="3">Keterangan</th>
                        </tr>
                        <tr class="inverse">
                          <th rowspan="2">PA</th>
                          <th rowspan="2">Teknis</th>
                          <th rowspan="2">Merek</th>
                          <th colspan="2">Volume Kemasan</th>
                          <th rowspan="2">Dipakai</th>
                          <th rowspan="2">Stok</th>
                        </tr>
                        <tr class="inverse">
                          <th>(gram)</th>
                          <th>(liter)</th>
                        </tr>
                    </thead>
                    <tbody>
                      <?php $i=0; foreach($data as $r){ $i++ ?>
                        <tr>
                          <td><?php echo intval($this->uri->segment(3)+ $i); ?></td>
                          <td>
                              <?php echo aksi_button('start') ?>
                                  <li>
                                      <a href="#modal-alert2" data-toggle="modal">Tambahkan Lot</a>
                                  </li>
                                  <li>
                                      <a href="<?php echo site_url('inventaris/bahan_kimia/create_edit/'.$r['id']); ?>">Edit</a>
                                  </li>
                                  <li>
                                      <a href="<?php echo site_url('inventaris/bahan_kimia/hapus/'.$r['id']) ?>">Hapus</a>
                                  </li>
                              <?php echo aksi_button('end') ?>
                          </td>

                          <td><?php echo $r['nama_bahan_kimia']; ?></td>
                          <td><?php echo $r['rumus_kimia']; ?></td>
                          <td><?php echo $r['bentuk']; ?></td>
                          <td><?php echo ($r['spesifikasi'] == 'PA') ? '√' : '-'; ?></td>
                          <td><?php echo ($r['spesifikasi'] == 'Teknis') ? '√' : '-'; ?></td>
                          <td><?php echo $r['merek']; ?></td>
                          <td><?php echo ($r['satuan_kemasan'] == 'gram') ? $r['volume_kemasan'] : '-'; ?></td>
                          <td><?php echo ($r['satuan_kemasan'] == 'liter') ? $r['volume_kemasan'] : '-'; ?></td>
                          <td>
                            <!-- <?php echo set_indo_date_from_timestemp((is_null($r['tanggal_kadaluarsa'])) ? null : $r['tanggal_kadaluarsa'].' 00:00'); ?> -->
                            <?php
                              $lot = $this->model->get_lot($r['id']);
                              foreach ($lot as $l) {
                                echo $l['nomor_lot'].'&nbsp;['.(set_indo_date_from_timestemp((is_null($l['tanggal_kadaluarsa'])) ? null : $r['tanggal_kadaluarsa'].' 00:00')).']<br>';
                              }
                             ?>
                          </td>
                          <td><?php echo $r['jenis_kemasan']; ?></td>
                          <td><?php echo $r['jumlah_dipakai']; ?></td>
                          <td><?php echo $r['jumlah_stok']; ?></td>
                          <td><?php echo $r['jumlah_total']; ?></td>
                          <td><?php echo $r['lokasi']; ?></td>
                          <td><?php echo $r['nomor_katalog']; ?></td>
                          <td><?php echo $r['lot']; ?></td>
                          <td><?php echo $r['keterangan']; ?></td>
                        </tr>

                        <div class="modal fade" id="modal-alert2" style="display: none;" aria-hidden="true">
                        		<div class="modal-dialog">
                        				<div class="modal-content">
                        					<form action="<?php echo site_url('inventaris/bahan_kimia/set_lot'); ?>" method="get">
                        						<div class="modal-body">
                        								<div class="alert alert-info m-b-0">
                                          <input type="hidden" name='id_kimia' value="<?php echo $r['id']; ?>">
                        									<b>Masukkan Lot:</b>
                        									<input class="form-control" type="text" name="nomor_lot" required>
                                          <b>Masukkan Tanggal Kadaluarsa:</b>
                        									<input class="form-control datepicker-default" type="text" name="tanggal_kadaluarsa" value="ket_<?php echo '';?>" required>
                        								</div>
                        						</div>
                        						<div class="modal-footer">
                        								<button type="submit" class="btn btn-info btn-sm">Simpan Lot</button>
                        								<a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Batal</a>
                        						</div>
                        					</form>
                        				</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 -->

      <?php } else{ ?>
          <div class="panel">
              <div class="panel-body">
                  Data Kosong
              </div>
          </div>
      <?php } ?>
    </div>
</div>
