<?php
require_once('includes/load.php');
page_require_level(3);

// Mendapatkan data dari oven_schedule dan mengurutkannya dari yang terkecil hingga terbesar (ascending)
$ovenScheduleData = $db->query("SELECT * FROM oven_schedule ORDER BY schedule_date ASC");

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

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Oven Schedule - Gantt Chart View</h3>
            </div>
            <div class="panel-body">
                <!-- Tampilan Gantt Chart menggunakan tabel -->
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>No Order</th>
                            <th>Part Number</th>
                            <th>Name</th>
                            <th>Quantity</th>
                            <th>Start Date</th>
                            <th>End Date</th>
                            <th>Duration</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        while ($ovenRow = $db->fetch_assoc($ovenScheduleData)) {
                            $noOrder = $ovenRow['no_order'];
                            $partNumber = $ovenRow['part_number'];
                            $taskName = $ovenRow['name'];
                            $quantity = $ovenRow['qty'];
                            $startDate = $ovenRow['schedule_date'];
                            $endDate = date('Y-m-d', strtotime($startDate . "+1 day")); // Misalnya, satu hari setelah start date

                            echo '<tr>';
                            echo '<td>' . htmlspecialchars($noOrder) . '</td>';
                            echo '<td>' . htmlspecialchars($partNumber) . '</td>';
                            echo '<td>' . htmlspecialchars($taskName) . '</td>';
                            echo '<td>' . htmlspecialchars($quantity) . '</td>';
                            echo '<td>' . htmlspecialchars($startDate) . '</td>';
                            echo '<td>' . htmlspecialchars($endDate) . '</td>';
                            echo '<td>1 day</td>'; // Durasi tetap satu hari sebagai contoh, bisa diubah sesuai kebutuhan
                            echo '</tr>';
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<style>
    table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 20px;
    }

    th, td {
        border: 1px solid #ddd;
        padding: 8px;
        text-align: left;
    }

    th {
        background-color: #f2f2f2;
    }
</style>

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