From 5e2d6933457204af1a556e56ff947ba2d1c9cdd5 Mon Sep 17 00:00:00 2001 From: Christian Steinle Date: Sat, 29 Mar 2025 14:22:24 +0100 Subject: [PATCH] Adjust month view to year view. --- functions/functions.php | 11 +++++++++++ public/css/layout.css | 4 ++++ public/index.php | 42 ++++++++++++++++++++++++++--------------- public/production.php | 2 +- public/year.php | 7 ++++--- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/functions/functions.php b/functions/functions.php index 5e303bc..942e6cc 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -22,6 +22,17 @@ function build_date_dropdown(mysqli $db, string $table): array return $dates; } +function get_month(mysqli $db, string $table): array +{ + $date_query = 'SELECT MIN(date) AS first, MAX(date) AS last FROM ' . $table . ';'; + $date = $db->query($date_query)->fetch_assoc(); + + $first_date = new DateTime($date['first']); + $last_date = new DateTime($date['last']); + + return ['first' => $first_date, 'last' => $last_date]; +} + function get_years(mysqli $db, string $table): array { $years_query = 'SELECT MIN(YEAR(date)) AS first, MAX(YEAR(date)) AS last FROM ' . $table . ';'; diff --git a/public/css/layout.css b/public/css/layout.css index 32e3640..b7dc158 100644 --- a/public/css/layout.css +++ b/public/css/layout.css @@ -4,6 +4,10 @@ body { flex-direction: column; } +input[type="number"] { + font-size: 1.3rem; +} + div > span { text-align: right; } diff --git a/public/index.php b/public/index.php index 76d1fb2..2ea79e9 100644 --- a/public/index.php +++ b/public/index.php @@ -19,8 +19,9 @@ if (isset($_POST['action']) && $_POST['action'] == 'set_values') { $local_db->query($query); } -$dates = build_date_dropdown($local_db, $table_aggregation); -$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $dates[0]; +$actual = new DateTime(); +$dates = get_month($local_db, $table_aggregation); +$chosen_date = (isset($_POST['date'])) ? $_POST['date'] : $actual->format('Y-m'); $data = get_aggregation($local_db, $table_aggregation, $chosen_date); $month_values = get_month_aggregation($local_db, $table_aggregation, $chosen_date); $year_values = get_year_aggregation($local_db, $table_aggregation, $chosen_date); @@ -29,6 +30,7 @@ $month_production = get_month_production($local_db, $table_production, $chosen_d $year_production = get_year_production($local_db, $table_production, $chosen_date); $last_value = get_last_value($local_db, $table_aggregation, $chosen_date); +$chosen_date_time = new DateTime($chosen_date); ?> @@ -37,19 +39,23 @@ $last_value = get_last_value($local_db, $table_aggregation, $chosen_date); -
- - - - Werte setzen - Jahresübersicht + + modify('-1 month')->format('Y-m') . "\")'><"; + } else { + echo ''; + } + echo '' . $chosen_date_time->modify('+1 month')->format('Y-m') . ''; + if ($dates['last'] > $chosen_date_time->modify('+1 month')) { + echo ""; + } else { + echo ''; + } + ?> + Jahr + Werte +
@@ -120,6 +126,12 @@ $last_value = get_last_value($local_db, $table_aggregation, $chosen_date);