Adds a meetings section to the debitor detail page, fetching meeting data from BC OData API with cache control support. Includes timeline UI for upcoming and past meetings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
use MintyPHP\Module\Helpdesk\HelpdeskAuthorizationPolicy;
|
|
use MintyPHP\Module\Helpdesk\Service\DebitorCacheControl;
|
|
use MintyPHP\Module\Helpdesk\Service\DebitorDetailService;
|
|
use MintyPHP\Router;
|
|
use MintyPHP\Support\Guard;
|
|
|
|
Guard::requireLogin();
|
|
Guard::requireAbilityOrForbidden(HelpdeskAuthorizationPolicy::ABILITY_ACCESS);
|
|
|
|
$request = requestInput();
|
|
if ($request->method() !== 'GET') {
|
|
http_response_code(405);
|
|
Router::json(['ok' => false, 'error' => 'method_not_allowed']);
|
|
|
|
return;
|
|
}
|
|
|
|
$customerNo = trim((string) $request->query('customerNo', ''));
|
|
$refreshRequested = DebitorCacheControl::parseRefreshFlag($request->query('refresh', ''));
|
|
|
|
if ($customerNo === '') {
|
|
http_response_code(400);
|
|
Router::json(['ok' => false, 'error' => 'missing_parameters']);
|
|
|
|
return;
|
|
}
|
|
|
|
$sessionStore = app(SessionStoreInterface::class);
|
|
$session = $sessionStore->all();
|
|
$tenantScope = DebitorCacheControl::resolveTenantScope($session);
|
|
if ($refreshRequested) {
|
|
$sessionStore->remove(DebitorCacheControl::meetingsKey($tenantScope, $customerNo));
|
|
}
|
|
|
|
$cacheKey = DebitorCacheControl::meetingsKey($tenantScope, $customerNo);
|
|
$cacheTtl = DebitorCacheControl::TTL_STANDARD_SECONDS;
|
|
$cached = $sessionStore->get($cacheKey);
|
|
$cacheUsed = false;
|
|
|
|
if (!$refreshRequested && is_array($cached) && isset($cached['fetched_at']) && (time() - (int) $cached['fetched_at']) < $cacheTtl) {
|
|
$cacheUsed = true;
|
|
$payload = is_array($cached['payload'] ?? null) ? $cached['payload'] : ['ok' => false];
|
|
$payload['meta'] = [
|
|
'cache_used' => true,
|
|
'cache_bypassed' => false,
|
|
'cache_refreshed' => false,
|
|
];
|
|
Router::json($payload);
|
|
|
|
return;
|
|
}
|
|
|
|
$service = app(DebitorDetailService::class);
|
|
$result = $service->loadMeetings($customerNo);
|
|
|
|
if (($result['ok'] ?? false) === true) {
|
|
$sessionStore->set($cacheKey, [
|
|
'payload' => $result,
|
|
'fetched_at' => time(),
|
|
]);
|
|
}
|
|
|
|
$result['meta'] = [
|
|
'cache_used' => $cacheUsed,
|
|
'cache_bypassed' => $refreshRequested,
|
|
'cache_refreshed' => $refreshRequested,
|
|
];
|
|
|
|
Router::json($result);
|