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

$products = get_all_products_with_stock();

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">
                <div class="pull-left">
                    <h3>Stock on Hand for Products</h3>
                </div>
            </div>
            <div class="panel-body">
                <?php if (!empty($products)) { ?>
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>Part Number</th>
                                <th>Product Name</th>
                                <th>Total Incoming</th>
                                <th>Total Outgoing</th>
                                <th>In Stock</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($products as $product) : ?>
                                <tr>
                                    <td><?php echo remove_junk($product['part_number']); ?></td>
                                    <td><?php echo remove_junk($product['name']); ?></td>
                                    <td><?php echo get_total_incoming($product['id']); ?></td>
                                    <td><?php echo get_total_outgoing($product['id']); ?></td>
                                    <td><?php echo get_total_incoming($product['id']) - get_total_outgoing($product['id']); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php } else { ?>
                    <p>No products with stock available.</p>
                <?php } ?>
            </div>
        </div>
    </div>
</div>

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