feat(search): Buchungssuche nach Buchungs- und Rechnungsnummer
booking_search() erkennt '148', '#148', 'Nr. 148', 'Buchung 148' und Rechnungsnummern wie 'RE2026054' zusätzlich zu Name/Straße/Ort; der exakte Nummerntreffer steht oben. Hinweise in Suchmaske, Anleitung und README angepasst, ROADMAP Feature 22 ergänzt.
This commit is contained in:
parent
f207f4f013
commit
6daecf7d41
5 changed files with 44 additions and 8 deletions
34
app/data.php
34
app/data.php
|
|
@ -98,6 +98,10 @@ function booking_list(string $from, string $to, bool $includeCancelled = false,
|
|||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sucht Buchungen nach Name, Straße, Ort sowie nach Buchungsnummer
|
||||
* ("148", "#148", "Nr. 148", "Buchung 148") und Rechnungsnummer (RE2026054).
|
||||
*/
|
||||
function booking_search(string $query, int $limit = 100): array
|
||||
{
|
||||
$query = trim($query);
|
||||
|
|
@ -105,12 +109,36 @@ function booking_search(string $query, int $limit = 100): array
|
|||
return [];
|
||||
}
|
||||
$like = '%' . addcslashes($query, '%_\\') . '%';
|
||||
$conditions = ['b.customer_name LIKE ?', 'b.city LIKE ?', 'b.street LIKE ?'];
|
||||
$params = [$like, $like, $like];
|
||||
|
||||
$numberMatch = null;
|
||||
if (preg_match('/^(?:#|nr\.?|buchung|nummer)?\s*(\d{1,9})$/iu', $query, $match) === 1) {
|
||||
$numberMatch = (int) $match[1];
|
||||
$conditions[] = 'b.id = ?';
|
||||
$params[] = $numberMatch;
|
||||
}
|
||||
if (preg_match('/^[a-z]{1,6}[\s-]?\d{3,}$/i', $query) === 1) {
|
||||
$conditions[] = 'b.invoice_no LIKE ?';
|
||||
$params[] = $like;
|
||||
}
|
||||
|
||||
$stmt = db()->prepare(
|
||||
BOOKING_SELECT . ' WHERE b.customer_name LIKE ? OR b.city LIKE ? OR b.street LIKE ?
|
||||
BOOKING_SELECT . ' WHERE ' . implode(' OR ', $conditions) . '
|
||||
ORDER BY b.start_date DESC, b.id DESC LIMIT ' . max(1, min(200, $limit))
|
||||
);
|
||||
$stmt->execute([$like, $like, $like]);
|
||||
return $stmt->fetchAll();
|
||||
$stmt->execute($params);
|
||||
$results = $stmt->fetchAll();
|
||||
|
||||
// Exakter Nummerntreffer steht oben.
|
||||
if ($numberMatch !== null) {
|
||||
usort($results, static function (array $a, array $b) use ($numberMatch): int {
|
||||
$aHit = (int) $a['id'] === $numberMatch ? 0 : 1;
|
||||
$bHit = (int) $b['id'] === $numberMatch ? 0 : 1;
|
||||
return $aHit <=> $bHit;
|
||||
});
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
function booking_conflicts(int $trailerId, string $start, string $end, int $excludeId = 0): array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue