<?php
include "../../root.class.php";
$firstOfMonth = date('Y-m-01');
$lastOfMonth = date('Y-m-t');


$dash = new Dashboard();
$db = new db_safeguard();
$order_res = $db->query("orders", "SELECT * FROM orders WHERE `status` = 0");
$orders = $order_res->num_rows;
$stock_take_res = $db->query("stock_takes", "SELECT * FROM stock_takes WHERE date_done = ''");
$stock_take = $stock_take_res->num_rows;


$order_trans_res = $db->query("order_trans", "SELECT SUM(amount) as total FROM order_trans WHERE user_id = {$_SESSION['user_id']} AND amount > 0 AND date_time BETWEEN '{$firstOfMonth}' AND '{$lastOfMonth}'");
if ($order_trans_res->num_rows > 0) {

    $order_trans_rec = $order_trans_res->fetch_assoc();
    $order_trans_rec = $order_trans_rec['total'];
} else {
    $order_trans_rec = 0;
}

$order_trans_res_1 = $db->query("order_trans", "SELECT SUM(amount) as total FROM order_trans WHERE user_id = {$_SESSION['user_id']} AND amount < 0 AND date_time BETWEEN '{$firstOfMonth}' AND '{$lastOfMonth}'");
if ($order_trans_res_1->num_rows > 0) {
    $order_trans_disp = $order_trans_res_1->fetch_assoc();
    $order_trans_disp = $order_trans_disp['total'];
} else {
    $order_trans_disp = 0;
}
if (strlen($order_trans_disp) < 1) {
    $order_trans_disp = 0;
}

?>
<style>
    body {
        font-size: 6em;
        background-color: #ffffffa3;
        text-align: center;
        padding: 5vw;
        color: black;
        margin-top: 15vw;
        display: flex;
        font-weight: 900;
        flex-direction: column;
        align-content: center;
        align-items: center;
    }
</style>
<!-- WELCOME -->
<div class="header">
    WELCOME
</div>
<div style="display: flex
;
    margin-bottom: 5vh;
    flex-wrap: wrap;
    flex-direction: row;
    align-items: center;
    justify-content: center;">
    <?php
    $dash->create_link("small", "ORDERS", "stock_control.php", $orders);
    $dash->create_link("small", "STOCK TAKES", "", $stock_take);
    ?>
</div>
<div class="header">
    PERF. FOR THE MONTH
</div>
<div style="display: flex
;
    margin-bottom: 5vh;
    flex-wrap: wrap;
    flex-direction: row;
    align-items: center;
    justify-content: center;">
    <?php
    $dash->create_link("small", "STOCK RECE.", "stock_control.php", $order_trans_rec);
    $dash->create_link("small", "STOCK DISP.", "1", $order_trans_disp);
    ?>
</div>