<?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();
}

if (isset($_POST) && !empty($_GET['delete'])) {
    $dataP['deleted'] = 1;
    ProductSetup::UpdateProductSetup($_GET['delete'],$dataP);
    header("Location: " . PROJECT_ADMIN_URL . "product_setup.php?view");
    exit();
}

$name = "";
$code = "";
$weight = "";
$unit = "";
$availability = "";
$status = "";
$tp_rate = "";
$carton_pieces = "";
$barcode = "";
?>
<!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>
<!-- End Page Loading -->
<div id="container">
    <?php include('includes/inc_top.php'); ?>
    <div class="row">
        <div class="col s12 m12">
            <div class="">
                <h3>Stock Setup</h3>
            </div>
            <hr>
            <?php if ($_SESSION['sess_role'] == 'VEC') {
                if (isset($_GET['view'])) { ?>
                    <a class="btn waves-effect waves-light" style="float:right;margin-left:5px;" href="stock_history_setup.php?view">History <i
                            class="mdi-content-add-box" style="font-size:12px;"></i></a>
                    <div class="clearfix"></div>
                <?php }
            } ?>
            <br/>
            <?php
            if (isset($_GET['view'])) {

                ?>
                <?php if (isset($_GET['sucess'])) { ?>
                    <div id='card-alert' class='card green lighten-5'>
                        <div class='card-content green-text'>
                            <p>Successfully updated!</p>
                        </div>
                        <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <?php if (isset($_GET['error'])) { ?>
                    <div id='card-alert' class='card orange lighten-5'>
                        <div class='card-content orange-text'>
                            <p>WARNING : <strong>Attention! </strong>Error occurred!</p>
                        </div>
                        <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <div class="table-datatables">
                    <table id="data-table-simple" class="responsive-table display">
                        <thead>
                        <tr>
                            <th>Product Name</th>
                            <th>Availibility</th>
                            <th>Cost Price</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                            <th>Product Name</th>
                            <th>Availibility</th>
                            <th>Cost Price</th>
                        </tr>
                        </tfoot>
                        <tbody>
                        <?php
                        $filterP = " WHERE deleted = 0 AND status <> 'Inactive' ";
                        $qry = ProductSetup::GetProductSetupList($filterP);
                        if ($qry) {
                            $countingSr = 1;
                            foreach ($qry as $qery) { ?>
                                <tr>
                                    <td><?php echo ucwords($qery->name); ?></td>
                                    <td><?php echo $qery->availability; ?></td>
                                    <td><?php echo $qery->cost_price; ?></td>
                                </tr>
                                <?php
                                $countingSr++;
                            }
                        } ?>
                        </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">
    $(document).ready(function () {
        var fewSeconds = 2;
        $('#btnsubmit').click(function () {
            // Ajax request
            var btn = $(this);
            btn.hide();
            setTimeout(function () {
                btn.show();
            }, fewSeconds * 1000);
        });
    });
</script>
</body>
</html>