<?= $this->session->flashdata('pesan'); ?>
<div class="card shadow-sm border-bottom-primary">
    <div class="card-header bg-white py-3">
        <div class="row">
            <div class="col">
                <h4 class="h5 align-middle m-0 font-weight-bold text-primary">
                    Data <?= $title; ?>
                </h4>
            </div>
        </div>
    </div>
    <div class="card-body">
        
        <div class="table-responsive mb-3">
            <table class="table table-striped" id="dataTable">
                <thead>
                    <tr>
                        <th rowspan="2">No.</th>
                        <th rowspan="2">Tanggal</th>
                        <th rowspan="2">Username</th>
                        <th rowspan="2">Lokasi</th>
                        <th colspan="7" class="text-left">Detail Barang</th>
                        <th rowspan="2">Status</th>
                        <th rowspan="2">Movement</th>
                        <th rowspan="2">Ket. Tambahan</th>
                    </tr>
                    <tr>
                        <th>ID Barang</th>
                        <th>Nama Barang</th>
                        <th>Jumlah</th>
                        <th>Merk</th>
                        <th>Spesifikasi</th>
                        <th>Barcode</th>
                        <th>Serial Number</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $no = 1;
                    if ($dt_res) :
                        foreach ($dt_res->dt_impor as $group) : ?>
                            <?php $rowspan = count($group->dt_array); ?>
                            <?php $i = 0; ?>
                            <?php foreach ($group->dt_array as $row) : ?>
                                    <tr>
                                        <?php if ($i == 0) : ?>
                                            <td rowspan="<?= $rowspan; ?>"><?= $no++; ?></td>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->tgl; ?></td>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->username; ?></td>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->nama_cabang; ?></td>
                                        <?php endif; ?>

                                        <td><?= $row->id_barang; ?></td>
                                        <td><?= $row->nama_barang; ?></td>
                                        <td><?= $row->jumlah; ?></td>
                                        <td><?= $row->merk; ?></td>
                                        <td><?= $row->spesifikasi; ?></td>
                                        <td><?= $row->barcode; ?></td>
                                        <td><?= $row->sn; ?></td>

                                        <?php if ($i == 0) : ?>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->status; ?></td>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->movement; ?></td>
                                            <td rowspan="<?= $rowspan; ?>"><?= $group->ket; ?></td>
                                        <?php endif; ?>
                                    </tr>
                                <?php $i++; ?>
                            <?php endforeach; ?>
                        <?php endforeach; ?>
                    <?php else : ?>
                        <tr>
                            <td colspan="14" class="text-center">
                                Data Kosong
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        
        <?= form_open(); ?>
        <input type="hidden" name="tgl_save" id="tgl_save" value="<?= $now; ?>">
        <div class="row form-group">
            <div class="col-md-9">
                <button type="submit" class="btn btn-primary">Proses Impor</button>
            </div>
        </div>
        <?= form_close(); ?>
    </div>
</div>