Skip to content

Commit

Permalink
Merge branch 'testing' into Last-pr-before-defense-mamaya
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Seannnnnn authored Jul 4, 2024
2 parents 8628ce3 + 4385cee commit 7bcf2a6
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 225 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ignore
src/includes/error-logs.txt
src/sales-prediction-algorithm/sales_prediction.json

.phpunit.result.cache
src/includes/charts/weekly_sales_data.json
.phpunit.result.cache
21 changes: 10 additions & 11 deletions src/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
<!--Site Icon-->
<link rel="icon" href="images/sweet-avenue-logo.png" type="image/png" />

<!-- Bootstrap JavaScript -->
<script src="../vendor/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<!-- CDN Scripts -->
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.bootstrap5.js"></script>
<!-- Custom JavacScript -->
<script src="javascript/preloader.js" defer></script>
<script src="javascript/accounts.js" defer></script>

<script>
// This will be used to check if an email or username is already taken
const takenEmails = <?php echo json_encode($emails); ?>;
Expand Down Expand Up @@ -287,17 +297,6 @@ class="btn fw-medium btn-medium-brown text-capitalize py-2 px-4">add account</bu
</div>
</div>


<!-- Bootstrap JavaScript -->
<script src="../vendor/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<!-- CDN Scripts -->
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.bootstrap5.js"></script>
<!-- Custom JavacScript -->
<script src="javascript/preloader.js"></script>
<script src="javascript/accounts.js"></script>

</body>
</html>
<?php
Expand Down
22 changes: 11 additions & 11 deletions src/get-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $row['flavor'] . '</span><br> ';
}
echo '</div>';
echo '<div class="col pt-1 ps-4 pe-4">';
echo '<div class="col px-4">';
echo '<img src="' . $image . '" alt="Product Image" class="pt-2 card-img-top rounded-circle">';
echo '</div>';
echo '<div class="pt-1 card-body">';
echo '<div class="card-text text-capitalize">';

echo '<div class="text-center text-carbon-grey text-truncate text-capitalize">';
echo '<span class="fw-medium " style="font-size: 15px;"> ' . $row['item_name'] . ' </span><br>';
echo '<span class="fw-medium font-14"> ' . $row['item_name'] . ' </span><br>';
echo '<span class="fw-bold">' . $row['price'] . '</span>';

echo '</div>';
Expand Down Expand Up @@ -106,14 +106,14 @@
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $row['size'] . 'oz' . '</span><br> ';
}
echo '</div>';
echo '<div class="col pt-1 ps-4 pe-4">';
echo '<div class="col px-4">';
echo '<img src="' . $image . '" alt="Product Image" class="pt-2 card-img-top rounded-circle">';
echo '</div>';
echo '<div class="pt-1 card-body">';
echo '<div class="card-text text-capitalize">';

echo '<div class="text-center text-carbon-grey text-truncate text-capitalize">';
echo '<span class="fw-medium " style="font-size: 15px;"> ' . $row['item_name'] . ' </span><br>';
echo '<span class="fw-medium font-14"> ' . $row['item_name'] . ' </span><br>';
echo '<span class="fw-bold">' . $row['price'] . '</span>';

echo '</div>';
Expand Down Expand Up @@ -149,12 +149,12 @@
</style>

<!-- Modal for Product Variations -->
<div class="modal fade" id="product" tabindex="-1" aria-labelledby="productName" aria-hidden="true">
<div class="modal fade" id="product" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form id="orderForm" method="post">
<div class="modal-header">
<h1 class="modal-title fs-6 fw-semibold text-carbon-grey text-capitalize" id="productName"><!-- Product name will be loaded here --></h1>
<div class="modal-header bg-medium-brown">
<h1 class="modal-title fs-6 fw-semibold text-light text-uppercase" id="productName"><!-- Product name will be loaded here --></h1>
</div>
<div class="modal-body" id="productVariation">
<input type="hidden" name="product_id" id="product_id">
Expand Down Expand Up @@ -188,7 +188,7 @@
<path fill-rule="evenodd" d="M2 8a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11A.5.5 0 0 1 2 8"/>
</svg>
</button>
<input type="number" id="quantityInput" name="quantity" class="form-control text-center border border-carbon-grey bg-white text-carbon-grey fw-medium py-3" value="1" min="1">
<input type="number" id="quantityInput" name="quantity" class="form-control text-center border border-carbon-grey bg-white text-carbon-grey fw-medium py-3 shadow-sm" value="1" min="1">
<button class="btn btn-lg btn-outline-carbon-grey input-group-text fw-bold py-3 px-5" type="button" id="quantityPlus">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-lg" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 2a.5.5 0 0 1 .5.5v5h5a.5.5 0 0 1 0 1h-5v5a.5.5 0 0 1-1 0v-5h-5a.5.5 0 0 1 0-1h5v-5A.5.5 0 0 1 8 2"/>
Expand All @@ -198,7 +198,7 @@
</div>
<div class="col-md mb-2">
<div class="form-floating py-3">
<input type="text" readonly class="form-control fw-bold fs-5 text-carbon-grey border border-carbon-grey bg-white" id="priceDisplay" name="price">
<input type="text" readonly class="form-control fw-bold fs-5 text-carbon-grey border border-carbon-grey bg-white shadow-sm" id="priceDisplay" name="price">
<label for="priceDisplay" class="text-carbon-grey fw-medium fs-5">Price</label>
</div>
</div>
Expand Down Expand Up @@ -260,15 +260,15 @@
$('#servingOrTypeGroup').append('<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + servingOrType + '</button>');
});
} else {
$('#servingOrTypeGroup').append('<span class="text-carbon-grey font-12 fst-italic">No variations available</span>');
$('#servingOrTypeGroup').append('<span class="text-carbon-grey font-13 fst-italic">No variations available</span>');
}

if (flavorOrSizeSet.size > 0) {
flavorOrSizeSet.forEach(function(flavorOrSize) {
$('#flavorOrSizeGroup').append('<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + flavorOrSize + '</button>');
});
} else {
$('#flavorOrSizeGroup').append('<span class="text-carbon-grey font-12 fst-italic">No variations available</span>');
$('#flavorOrSizeGroup').append('<span class="text-carbon-grey font-13 fst-italic">No variations available</span>');
}

$('#defaultServingOrType').val(defaultServingOrType);
Expand Down
43 changes: 26 additions & 17 deletions src/includes/charts/weekly-sales.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
<?php

include_once str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/../file-utilities.php');
require_once FileUtils::normalizeFilePath(__DIR__ . '/../db-connector.php');
include_once FileUtils::normalizeFilePath(__DIR__ . '/../error-reporting.php');
include_once FileUtils::normalizeFilePath(__DIR__ . '/../default-timezone.php');

$sales_data = array();
$weekly_sales = 0;
function fetchAndProcessSalesData($db) {
$prev_week_start = date('Y-m-d', strtotime('monday last week'));
$prev_week_end = date('Y-m-d', strtotime('sunday last week'));

if(date('N') == 7) {

$prev_week_start = date('Y-m-d', strtotime('last Monday'));
$prev_week_end = date('Y-m-d', strtotime('last Saturday'));

// Fetching sales data from the database
$sql = "SELECT DATE(timestamp) AS date, SUM(total_amount) AS total_sales
FROM transaction
WHERE timestamp >= '$prev_week_start' AND timestamp <= '$prev_week_end'
WHERE timestamp >= ? AND timestamp <= ?
GROUP BY DATE(timestamp)";
$result = $db->query($sql);
$stmt = $db->prepare($sql);
$stmt->bind_param('ss', $prev_week_start, $prev_week_end);
$stmt->execute();
$result = $stmt->get_result();

$sales_data = array();
$weekly_sales = 0;

// Process the query result
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Extract date and total sales from the row
$date = $row['date'];
$total_sales = $row['total_sales'];

// Update sales data for the corresponding day
$total_sales = floatval($row['total_sales']);

$sales_data[] = [
'date' => $date,
'total_sales' => floatval($total_sales)
'total_sales' => $total_sales
];
$weekly_sales += $total_sales;
}
}

$stmt->close();

$json_sales_data = json_encode($sales_data);
$json_file = __DIR__ . '/weekly_sales_data.json';
file_put_contents($json_file, $json_sales_data);

return $json_sales_data;
}

// Encode the data as JSON
$json_sales_data = json_encode($sales_data);
// Check if today is monday
if(date('N') == 1) {
$json_sales_data = fetchAndProcessSalesData($db);
} else {
$json_file = __DIR__ . '/weekly_sales_data.json';
$json_sales_data = file_get_contents($json_file);
}

?>

Expand Down
1 change: 1 addition & 0 deletions src/includes/charts/weekly_sales_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"date":"2024-06-24","total_sales":2800},{"date":"2024-06-25","total_sales":2100},{"date":"2024-06-26","total_sales":2710},{"date":"2024-06-27","total_sales":1500},{"date":"2024-06-28","total_sales":1600}]
2 changes: 1 addition & 1 deletion src/includes/login-authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
// If there is no user with the username, display this
else {
$_SESSION['error_message'] = 'User with this username does not exist.';
$_SESSION['error_message'] = 'Username and password mismatched.';
header("Location: ../login.php");
exit();
}
Expand Down
Loading

0 comments on commit 7bcf2a6

Please sign in to comment.