From 29c53c3b70458ce2bd937636714d7fd1aa830699 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Thu, 22 Jan 2026 12:53:38 +0100 Subject: [PATCH] Improve Slack message formatting and update date handling in department statistics - Apply Markdown formatting to Slack messages for better readability. - Adjust date range to end on the previous day in `workerRoute.php`. - Refactor department loop output for consistent indentation and styling. --- services/nginx/app/objects/departments_o.php | 14 +++++++------- services/nginx/app/routes/workerRoute.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/nginx/app/objects/departments_o.php b/services/nginx/app/objects/departments_o.php index 17bcecc9..185d8e4f 100644 --- a/services/nginx/app/objects/departments_o.php +++ b/services/nginx/app/objects/departments_o.php @@ -719,18 +719,18 @@ class departments_o extends db * ... */ $tmp = "*Weekly results for Truck Wash*\n"; - $tmp .= "Period: " . date('d.m.Y', strtotime($date_start)) . " - " . date('d.m.Y', strtotime($date_end)) . "\n"; + $tmp .= "_Period: " . date('d.m.Y', strtotime($date_start)) . " - " . date('d.m.Y', strtotime($date_end)) . "_\n"; // Washes $total_wash_count = 0; - $tmp .= "Washes:\n"; + $tmp .= "*Washes:*\n"; $orders_o = new orders_o(); foreach ( $department_ids as $department_id ) { $wash_count = $orders_o->countWashesInDateRange($date_start, $date_end, $department_id); $total_wash_count += $wash_count; $department = (new departments_o())->select($department_id); - $tmp .= "{$department->name->value()}: $wash_count\n"; + $tmp .= "> {$department->name->value()}: $wash_count\n"; } - $tmp .= "- Total: {$total_wash_count}\n"; + $tmp .= "> - Total: {$total_wash_count}\n"; // Pre-instantiate products_o to reuse $products_o = new products_o(); @@ -766,7 +766,7 @@ class departments_o extends db default => $products_o->select($product_id)->name->value(), }; } - $tmp .= "\n{$product_name}:\n"; + $tmp .= "\n*{$product_name}:*\n"; $product_key = is_array($product_id) ? implode('_', $product_id) : $product_id; // Loop through each department to get the percentage @@ -776,14 +776,14 @@ class departments_o extends db $percentage = $percentages[$product_key]; $total_count += $max_addons[$product_key]; $total_sold += $sold_addons[$product_key]; - $tmp .= "{$department->name->value()}: {$percentage}% ({$sold_addons[$product_key]}/{$max_addons[$product_key]})\n"; + $tmp .= "> {$department->name->value()}: {$percentage}%\n"; } // Get the total percentage for the product if ($total_count !== 0) { // Prevent division by zero $total_percentage = ($total_sold / $total_count) * 100; } - $tmp .= "- Total: " . number_format($total_percentage, 2) . "% ({$total_sold}/{$total_count})\n"; + $tmp .= "> - Total: " . number_format($total_percentage, 2) . "%\n"; } // Send the message to the internal Slack webhook $slack = new slack(); diff --git a/services/nginx/app/routes/workerRoute.php b/services/nginx/app/routes/workerRoute.php index e04289d9..742af8c9 100644 --- a/services/nginx/app/routes/workerRoute.php +++ b/services/nginx/app/routes/workerRoute.php @@ -44,7 +44,7 @@ class workerRoute $department = (new departments_o())->select((int)6); $days = 7; // The time should be from 00:00:00 of the start date to 23:59:59 of the end date - $date_end = date('Y-m-d 23:59:59'); // Today at 23:59:59 + $date_end = date('Y-m-d 23:59:59', strtotime("-1 days")); // Yesterday (Sunday) at 23:59:59 $date_start = date('Y-m-d 00:00:00', strtotime("-$days days")); // $days ago at 00:00:00 $department->sendSlackInternalStatisticNotification($date_start, $date_end, [1,2,3,4,5,6,7]); $response->success(['message' => 'Test message sent to Slack (not really, this is a placeholder).' ]);