<?php
// Include file untuk memuat file yang diperlukan
require_once('includes/load.php');
page_require_level(3); // Memastikan level akses sesuai

// Mengambil semua data dari tabel std_time dan bergabung dengan tabel products
$sql  = "SELECT std_time.*, products.name FROM std_time ";
$sql .= "LEFT JOIN products ON std_time.part_number = products.part_number";
$std_times = find_by_sql($sql);

?>
<?php include_once('layouts/header.php'); ?>

<div class="row">
    <div class="col-md-12">
        <?php echo display_msg($msg); ?>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading clearfix">
                <strong>
                    <span class="glyphicon glyphicon-th"></span>
                    <span>Daftar Std Time</span>
                </strong>
                <div class="pull-right">
                    <a href="add_std_time.php" class="btn btn-primary">Tambah Std Time</a>
                    <a href="import_std_time.php" class="btn btn-success">Impor CSV</a>
                </div>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="text-center">#</th>
                            <th>Nomor Bagian</th>
                            <th>Nama Produk</th>
                            <th class="text-center">Waktu Filling</th>
                            <th class="text-center">Waktu Label</th>
                            <th class="text-center">Waktu Seal</th>
                            <th class="text-center">Waktu Packing</th>
                            <th class="text-center">Waktu Shrink</th>
                            <th class="text-center">Total Waktu</th>
                            <th>Deskripsi</th>
                            <th class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($std_times as $std_time): ?>
                            <tr>
                                <td class="text-center"><?php echo count_id(); ?></td>
                                <td><?php echo remove_junk($std_time['part_number']); ?></td>
                                <td><?php echo remove_junk($std_time['name']); ?></td>
                                <td class="text-center"><?php echo remove_junk($std_time['time_filling']); ?></td>
                                <td class="text-center"><?php echo remove_junk($std_time['time_label']); ?></td>
                                <td class="text-center"><?php echo remove_junk($std_time['time_seal']); ?></td>
                                <td class="text-center"><?php echo remove_junk($std_time['time_packing']); ?></td>
                                <td class="text-center"><?php echo remove_junk($std_time['time_shrink']); ?></td>
                                <td class="text-center">
                                    <?php
                                        $total_time = (float)$std_time['time_filling'] + (float)$std_time['time_label'] + 
                                                      (float)$std_time['time_seal'] + (float)$std_time['time_packing'] + 
                                                      (float)$std_time['time_shrink'];
                                        echo number_format($total_time, 2);
                                    ?>
                                </td>
                                <td><?php echo remove_junk($std_time['description']); ?></td>
                                <td class="text-center">
                                    <div class="btn-group">
                                        <a href="edit_std_time.php?id=<?php echo (int)$std_time['id'];?>" class="btn btn-warning btn-xs" title="Edit" data-toggle="tooltip">
                                            <span class="glyphicon glyphicon-edit"></span>
                                        </a>
                                        <a href="delete_std_time.php?id=<?php echo (int)$std_time['id'];?>" class="btn btn-danger btn-xs" title="Hapus" data-toggle="tooltip">
                                            <span class="glyphicon glyphicon-trash"></span>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<?php include_once('layouts/footer.php'); ?>
