- Mitglied wählen -'; if ($suggestions !== []) { $html .= ''; foreach ($suggestions as $suggestion) { $id = (int)$suggestion['participant_id']; $html .= ''; } $html .= ''; } $html .= ''; foreach ($members as $member) { $id = (int)$member['participant_id']; if (isset($suggestedIds[$id])) { continue; } $html .= ''; } $html .= ''; return $html; } function paypal_payment_matches_query(array $payment, string $query): bool { $query = imports_normalize_match_text($query); if ($query === '') { return true; } $text = imports_normalize_match_text( (string)$payment['payer_name'] . ' ' . (string)($payment['note'] ?? '') . ' ' . (string)($payment['transaction_code'] ?? '') ); return str_contains($text, $query); } if ($hasAccess && $_SERVER['REQUEST_METHOD'] === 'POST') { $aktion = (string)($_POST['aktion'] ?? ''); $paymentId = (int)($_POST['payment_id'] ?? 0); $actorUserId = $saasUser['user_id'] ?? null; if ($aktion === 'zuordnen') { $participantId = (int)($_POST['participant_id'] ?? 0); if ($participantId <= 0) { $flash = ['type' => 'error', 'text' => 'Bitte ein Mitglied auswählen.']; } else { $result = paypal_assign_payment($pdo, $tenantId, $paymentId, $participantId, $actorUserId); $flash = $result['ok'] ? ['type' => 'success', 'text' => 'Zahlung wurde zugeordnet und als Einzahlung gebucht.'] : ['type' => 'error', 'text' => $result['error'] ?? 'Die Zuordnung ist fehlgeschlagen.']; } } elseif ($aktion === 'ignorieren') { $result = paypal_ignore_payment($pdo, $tenantId, $paymentId, $actorUserId); $flash = $result['ok'] ? ['type' => 'success', 'text' => 'Zahlung wurde als erledigt markiert.'] : ['type' => 'error', 'text' => $result['error'] ?? 'Die Aktion ist fehlgeschlagen.']; } // Post-Redirect-Get gegen Doppelbuchung per Refresh. $_SESSION['flash_paypal'] = $flash; header('Location: paypal-zuordnung.php' . $returnQuery); exit; } $inboxAddress = null; $offene = []; $mitglieder = []; if ($hasAccess) { $token = paypal_inbox_ensure_token($pdo, $tenantId); $inboxAddress = paypal_inbox_address_for_token($token); $offene = paypal_fetch_unmatched($pdo, $tenantId); $mitglieder = ledger_fetch_participant_summaries($pdo, $tenantId, ['active_only' => true]); } $offeneGefiltert = array_values(array_filter($offene, static fn(array $payment): bool => paypal_payment_matches_query($payment, $suchbegriff))); include "header.php"; include "headerline.php"; include "nav.php"; ?>