diff --git a/src/UcpManager.php b/src/UcpManager.php index 6230835..09134fa 100644 --- a/src/UcpManager.php +++ b/src/UcpManager.php @@ -607,10 +607,16 @@ class UcpManager return ['calls' => [], 'stats' => ['total' => 0, 'answered' => 0, 'missed' => 0]]; } + $rawDisp = strtoupper(trim((string)($filters['disposition'] ?? 'all'))); + $cdrDisp = match ($rawDisp) { + 'ANSWERED' => 'answered', + default => 'all', + }; + $res = CdrManager::getCalls($db, [ 'limit' => 500, 'direction' => (string)($filters['direction'] ?? 'all'), - 'disposition' => (string)($filters['disposition'] ?? 'all'), + 'disposition' => $cdrDisp, 'period' => (string)($filters['period'] ?? 'all'), 'search' => (string)($filters['search'] ?? ''), ]); @@ -619,17 +625,39 @@ class UcpManager $answered = 0; $missed = 0; + $extractExt = static function (string $chan): string { + if (preg_match('/^(?:PJSIP|SIP)\/([^-\/@]+)/i', trim($chan), $m)) { + return (string)$m[1]; + } + return ''; + }; + foreach ($res['calls'] as $call) { - $srcMatch = in_array((string)($call['src'] ?? ''), $extSet, true); - $dstMatch = in_array((string)($call['dst'] ?? ''), $extSet, true); - if (!$srcMatch && !$dstMatch) { + $callerNum = (string)($call['caller_number'] ?? $call['src'] ?? ''); + $calleeNum = (string)($call['callee_number'] ?? $call['dst'] ?? ''); + $srcChanEp = $extractExt((string)($call['channel'] ?? '')); + $dstChanEp = $extractExt((string)($call['dstchannel'] ?? '')); + + $isMine = in_array($callerNum, $extSet, true) + || in_array($calleeNum, $extSet, true) + || ($srcChanEp !== '' && in_array($srcChanEp, $extSet, true)) + || ($dstChanEp !== '' && in_array($dstChanEp, $extSet, true)); + + if (!$isMine) { continue; } - if (($call['disposition'] ?? '') === 'ANSWERED') { + + $disp = strtoupper((string)($call['disposition'] ?? 'NO ANSWER')); + if ($rawDisp === 'MISSED' && $disp === 'ANSWERED') { + continue; + } + + if ($disp === 'ANSWERED') { $answered++; } else { $missed++; } + $filtered[] = $call; if (count($filtered) >= 120) { break; diff --git a/ucp/assets/ucp.js b/ucp/assets/ucp.js index df9b61a..d8249f6 100644 --- a/ucp/assets/ucp.js +++ b/ucp/assets/ucp.js @@ -633,16 +633,28 @@ async function loadPersonalCdr() { }; const ok = c.disposition === 'ANSWERED'; const stBadge = ok - ? 'Répondu' - : 'Manqué'; + ? `${escapeHtml(c.status_label || 'Répondu')}` + : `${escapeHtml(c.status_label || 'Manqué')}`; + + const srcNum = String(c.caller_number ?? c.src ?? ''); + const srcName = String(c.caller_name ?? ''); + const dstNum = String(c.callee_number ?? c.dst ?? ''); + const dstName = String(c.callee_name ?? ''); + + const formatParty = (name, num) => { + if (name && num && name !== num) { + return `