0, 'buchungen' => []], JSON_UNESCAPED_UNICODE); exit; } try { $matchParams = [ 'von' => $validated['von'], 'bis' => $validated['bis'], 'betrag' => $validated['betrag'], 'toleranz' => $validated['toleranz'], ]; $countStmt = $pdo->prepare(' SELECT COUNT(*) FROM entries e WHERE e.date BETWEEN :von AND :bis AND ABS((-1 * e.amount) - :betrag) <= :toleranz '); $countStmt->execute($matchParams); $anzahl = (int)$countStmt->fetchColumn(); $selectStmt = $pdo->prepare(' SELECT e.id, e.date AS datum, e.amount AS betrag, e.subject AS zweck, c.name AS kategorie, pm.name AS konto FROM entries e LEFT JOIN categories c ON e.category = c.category_id LEFT JOIN payment_methods pm ON e.payment_method = pm.payment_method_id WHERE e.date BETWEEN :von AND :bis AND ABS((-1 * e.amount) - :betrag) <= :toleranz ORDER BY e.date DESC, e.id DESC LIMIT :limit '); $selectStmt->bindValue(':von', $validated['von']); $selectStmt->bindValue(':bis', $validated['bis']); $selectStmt->bindValue(':betrag', $validated['betrag']); $selectStmt->bindValue(':toleranz', $validated['toleranz']); $selectStmt->bindValue(':limit', $validated['limit'], PDO::PARAM_INT); $selectStmt->execute(); $rows = $selectStmt->fetchAll(); echo json_encode([ 'anzahl' => $anzahl, 'buchungen' => array_map('fscash_format_buchung', $rows), ], JSON_UNESCAPED_UNICODE); } catch (PDOException $e) { http_response_code(500); echo json_encode( fscash_api_error('Interner Fehler bei der Buchungssuche.'), JSON_UNESCAPED_UNICODE ); }