Remove outdated edge gateway object classes, add new agent implementation
Transitioned from obsolete gateway object classes (`edge_gateway_shell_action_jobs_o`, `edge_gateway_shell_events_o`, `edge_gateway_shell_sessions_o`, `edge_gateway_update_jobs_o`) to the new agent implementation (`edge-gateway-agent/agent.php`).
This commit is contained in:
@@ -7,6 +7,8 @@ use classes\db;
|
||||
use classes\email;
|
||||
use classes\gatewayapi;
|
||||
use classes\object_property;
|
||||
use classes\order_bookings_counts_cache;
|
||||
use classes\order_bookings_list_cache;
|
||||
use classes\pdf_generator;
|
||||
use classes\slack;
|
||||
use Exception;
|
||||
@@ -290,7 +292,12 @@ class order_bookings_o extends db
|
||||
|
||||
public function objectChanged(): void
|
||||
{
|
||||
//TODO: Add cache invalidation
|
||||
try {
|
||||
order_bookings_list_cache::clearAll();
|
||||
order_bookings_counts_cache::clearAll();
|
||||
} catch (\Throwable) {
|
||||
// Cache invalidation must never break order-booking writes.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -569,4 +576,68 @@ class order_bookings_o extends db
|
||||
return count($order_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int|string>|null $departmentIds
|
||||
* @return array{past:int,current:int,future:int}
|
||||
*/
|
||||
public function getPendingBookingCounts(?array $departmentIds = null, ?int $customerNumber = null, ?\DateTimeImmutable $reference = null): array
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
|
||||
$normalizedDepartmentIds = [];
|
||||
if (is_array($departmentIds)) {
|
||||
foreach ($departmentIds as $departmentId) {
|
||||
$normalizedDepartmentId = (int)$departmentId;
|
||||
if ($normalizedDepartmentId > 0) {
|
||||
$normalizedDepartmentIds[] = $normalizedDepartmentId;
|
||||
}
|
||||
}
|
||||
$normalizedDepartmentIds = array_values(array_unique($normalizedDepartmentIds));
|
||||
if ($normalizedDepartmentIds === []) {
|
||||
return [
|
||||
'past' => 0,
|
||||
'current' => 0,
|
||||
'future' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$now = $reference ?? new \DateTimeImmutable('now');
|
||||
$todayStart = $now->setTime(0, 0, 0);
|
||||
$todayEnd = $now->setTime(23, 59, 59);
|
||||
|
||||
$todayStartSql = $db->escape_string($todayStart->format('Y-m-d H:i:s'));
|
||||
$todayEndSql = $db->escape_string($todayEnd->format('Y-m-d H:i:s'));
|
||||
|
||||
$whereClauses = [
|
||||
'`deleted_at` IS NULL',
|
||||
"(`order_id` IS NULL OR `order_id` = 0 OR TRIM(CAST(`order_id` AS CHAR)) = '')",
|
||||
];
|
||||
|
||||
if ($normalizedDepartmentIds !== []) {
|
||||
$whereClauses[] = '`department` IN (' . implode(', ', array_map('intval', $normalizedDepartmentIds)) . ')';
|
||||
}
|
||||
|
||||
if ($customerNumber !== null && $customerNumber > 0) {
|
||||
$whereClauses[] = '`customer_number` = ' . (int)$customerNumber;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
COALESCE(SUM(CASE WHEN `datetime` < '{$todayStartSql}' THEN 1 ELSE 0 END), 0) AS `past`,
|
||||
COALESCE(SUM(CASE WHEN `datetime` >= '{$todayStartSql}' AND `datetime` <= '{$todayEndSql}' THEN 1 ELSE 0 END), 0) AS `current`,
|
||||
COALESCE(SUM(CASE WHEN `datetime` > '{$todayEndSql}' THEN 1 ELSE 0 END), 0) AS `future`
|
||||
FROM `order_bookings`
|
||||
WHERE " . implode(' AND ', $whereClauses);
|
||||
|
||||
$result = $db->query($sql);
|
||||
$row = $db->fetch_assoc($result);
|
||||
|
||||
return [
|
||||
'past' => max(0, (int)($row['past'] ?? 0)),
|
||||
'current' => max(0, (int)($row['current'] ?? 0)),
|
||||
'future' => max(0, (int)($row['future'] ?? 0)),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user