<?php
include("../../classes/manager.class.php");
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
$m = new Manager();
$output = '';
if (!isset($_SESSION['sess_userid'])) {
    header("Location: " . PROJECT_ADMIN_URL);
    exit();
}
$name = "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include('../includes/inc_head.php'); ?>
</head>
<body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<div id="container">
    <?php include('../includes/inc_top.php'); ?>
    <div class="row">
        <div class="col s12 m12">
            <div class="">
                <h3>Product Stock Setup</h3>
            </div>
            <hr>
            <?php if ($_SESSION['sess_role'] == 'VEC') {
                if (isset($_GET['view'])) { ?>
                    
                <?php }
            } ?>
            <br/>
            <?php
            if (isset($_GET['view'])) {
                ?>
                <div class="table-datatables">
                    <table id="sorted-data-table" class="responsive-table striped highlight">
                        <thead>
                        <tr>
                            <th>Product Name</th>
                            <th>Available Carton</th>
                            <th>Available Quantity</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                           <th>Product Name</th>
                            <th>Available Carton</th>
                            <th>Available Quantity</th>
                        </tr>
                        </tfoot>
                        <tbody>
                        <?php
                            $productSummary = ProducedProducts::GetProductStockSummary();
             
                            if ($productSummary) {
                                foreach ($productSummary as $qery) {
                                    $availableCarton = round($qery->total_remaining_quantity / $qery->carton_pieces, 2);
                                    if ($availableCarton > 0) { // Only display if available carton is greater than 0
                                        ?>
                                        <tr>
                                            <td><?php echo ucwords($qery->product_name); ?></td>
                                            <td><?php echo $availableCarton; ?></td>
                                            <td><?php echo $qery->total_remaining_quantity; ?></td>
                                        </tr>
                                        <?php
                                    }
                                }
                            } ?>
                        </tbody>
                    </table>
                </div>
                <?php
            } // close view
           ?>
        </div>
    </div>
</div>
</div>
<?php include('../includes/inc_footer.php'); ?>

<?php include('../includes/inc_js.php'); ?>
<script type="application/javascript">
   
</script>
</body>
</html>
