<?php

session_start();

// Check if the user is logged in, if not then redirect him to login page
require_once "../Config/session_check.php";

$_SESSION["last_Active"] = time();
$Table = '<table class="table table-hover" style="width:100%;" >
                        <a class="btn btn-dark btn-block" style=" padding-bottom: 14px"  href="AddInvoice.php" >Add new Invoice</a>
                        <thead>
                        <tr>
                        <th>Invoice ID</th>
                        <th>Supplier ID</th>
                        <th>Total Quantity</th>
                        <th>Billed</th>
                        <th>Date Ordered</th>
                        <th>Date Recived</th>
                        </tr>
                        </thead>
                        <tbody>';


require_once "../Config/config.php";

$SQL = "select * from invoces";
$stmt = mysqli_query($link, $SQL);


while ($row = mysqli_fetch_array($stmt)) {

    $linkerS = "window.location='DetailView.php?ID=" . $row[0] . "';";


    $Table = $Table . '<tr style="cursor: pointer" onclick=" ' . $linkerS . '" >
                        <td>' . $row[0] . '</td>
                        <td>' . $row[1] . '</td>
                        <td>' . $row[2] . '</td>
                        <td>' . $row[3] . '</td>
                        <td>' . $row[4] . '</td>
                        <td>' . $row[5] . '</td>
                        </tr>';
}
$Table = $Table . "</tbody></table>";


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include "../Templates/Header.php"; ?>
    <title>Dashboard</title>
</head>
<body>

<div id="page-container">

    <div id="content-wrap">
        <?php include "../Templates/navBar.php"; ?>
        <div class="container-fluid">
            <div class="row">
                <?php include "../Templates/SideBar.php"; ?>

                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                    <h1>Invoices:</h1>
                    <?php echo $Table; ?>

                </main>
            </div>
        </div>


    </div>
    <?php include "../Templates/Footer.php"; ?>

</div>

</body>
</html>
