# Phase 8: Orders History & Filtering

## Objective
Provide the vendor with a filterable, paginated order history (the "My Orders" screen from the app).

---

## Context from Screenshots

**My Orders screen:**
- **Filters button** with badge showing active filter count
- **Filter sheet** with:
  - DATE: All, Today, 7D, 30D
  - Customer: Dropdown with avatar + name, "Clear customer" link
  - ORDER TYPE: All (expandable)
- **Order list:**
  - Order number (short hash, e.g., #571f58)
  - Date + time
  - Status badge (Paid)
  - "CUSTOMER" label + first product name truncated
  - Item count + type label (e.g., "1 item | Product")
  - Total amount

---

## Tasks

### 8.1 List Vendor Orders Controller

**Controller:** `app/Http/Controllers/Api/Employee/ShopManager/ListOrdersController.php`

- `GET /v1/places/{place}/shop/orders`
- Query params:
  - `period` (all|today|7d|30d) - Date filter
  - `customer_id` (public_id, optional) - Filter by customer
  - `type` (all|product|service|course|pack|...) - Order type filter
  - `status` (all|paid|pending) - Status filter
  - `page`, `size` - Pagination
- Returns paginated list:

```json
{
  "data": [
    {
      "id": "order_public_id",
      "order_number": "571f58",
      "date": "Mar 09, 2026 at 1:33 PM",
      "status": "paid",
      "customer": {
        "id": "user_public_id",
        "name": "member cs",
        "avatar_url": "..."
      },
      "first_item_name": "Kore PVC 16 Kg Home Gym Set With One 3...",
      "items_count": 1,
      "type_label": "Product",
      "total": { "amount": 1100, "currency": "USD" }
    }
  ],
  "totalItems": 42,
  "totalPages": 5
}
```

**Logic:**
- Query orders where `place_id` = place AND `employee_id` = current employee
- Apply filters
- `order_number` = first 6 chars of `public_id`
- `type_label` = dominant orderable type from items
- Paginate with standard format

### 8.2 Show Order Detail Controller

**Controller:** `app/Http/Controllers/Api/Employee/ShopManager/ShowOrderController.php`

- `GET /v1/places/{place}/shop/orders/{order}`
- Returns full order with items, customer, payment info, invoice link

### 8.3 Vendor Order Resource

**File:** `app/Http/Resources/ShopManager/VendorOrderResource.php`

### 8.4 Tests

**File:** `tests/Feature/Controllers/ShopManager/OrdersHistoryTest.php`

Test cases:
- [ ] List orders returns only this employee's orders at this place
- [ ] Date filter works (today, 7d, 30d)
- [ ] Customer filter works
- [ ] Type filter works
- [ ] Pagination works correctly
- [ ] Order detail returns full information
- [ ] Order number is derived from public_id

---

## Files Created/Modified

| Action | File |
|---|---|
| Create | `app/Http/Controllers/Api/Employee/ShopManager/ListOrdersController.php` |
| Create | `app/Http/Controllers/Api/Employee/ShopManager/ShowOrderController.php` |
| Create | `app/Http/Resources/ShopManager/VendorOrderResource.php` |
| Modify | `routes/api.php` |
| Create | `tests/Feature/Controllers/ShopManager/OrdersHistoryTest.php` |

---

## Acceptance Criteria

- [ ] Orders list is filterable by date, customer, and type
- [ ] Pagination follows project standard (data/totalItems/totalPages)
- [ ] Order detail is complete with items and payment info
- [ ] Only vendor's own orders are visible
- [ ] Swagger annotations on all controllers
- [ ] All tests pass
- [ ] `./gitCheck.sh` passes
