# Reservation List Filter by Customer Phone/WhatsApp

**Goal:** Allow owners, employees, and admins to filter reservations by the customer's phone or WhatsApp number.

---

## Design

### Parameter

Add `customer_phone` to `ListReservationsRequest`:

```php
'customer_phone' => ['nullable', 'string', 'max:255'],
```

### Normalization

Create a small helper that strips everything except digits and a variant with leading zeros removed:

```php
private function phoneDigits(string $value): string
{
    return preg_replace('/[^0-9]/', '', $value);
}
```

For a given `customer_phone` value we generate two patterns (when different):
- `digits` → `%<digits>%`
- `digits without leading zeros` → `%<trimmed>%`

Both patterns are matched with `LIKE` against stored numbers, so formatting differences (`+`, `-`, spaces) and leading-zero variants still find the same reservation.

### Query implementation

**Owner/employee inline block in `ReservationController::index`**

When `customer_phone` is present, add a `whereHasMorph` clause on the reservation's `customer` polymorphic relation:

- `Customer::class`:
  - `customer.phone` LIKE pattern
  - `customer.user.whatsapp_number` LIKE pattern
- `PendingCustomer::class`:
  - `pending_customer.phone` LIKE pattern
  - `pending_customer.whatsapp_number` LIKE pattern

**Admin shared filter in `FilterService::applyReservationCommonFilters`**

Same polymorphic `whereHasMorph` logic, applied when `customer_phone` is present.

### Fallback / edge cases

- Empty `customer_phone` is ignored.
- If the normalized string is empty after stripping non-digits, no phone filter is applied.
- Partial matches work (e.g., searching "5550100" matches "+12025550100").

## Testing

- `tests/Feature/Owner/ReservationListFiltersTest.php` / `tests/Feature/Admin/ReservationListTest.php`:
  - Filter registered customer reservations by `customer_phone`.
  - Filter pending-customer (walk-in) reservations by `customer_phone`.
  - Match across formatting differences (`+`, spaces, dashes).
  - Match leading-zero variants.
  - Empty `customer_phone` returns all results.
