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.
This commit is contained in:
Jeppe Bundgaard
2026-01-22 12:53:38 +01:00
parent e0e479a15d
commit 29c53c3b70
2 changed files with 8 additions and 8 deletions
+7 -7
View File
@@ -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();
+1 -1
View File
@@ -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).' ]);