# New API Endpoints Documentation

This document lists all the new and updated API endpoints implemented for Table Order Timers and the Expense Management (Accounting) module.

## 1. Table Order Timers (Updated)

### `GET /api/tables`
*   **Description:** Fetches all active tables.
*   **Update:** Now includes `current_order_started_at` field.
*   **Response Field:**
    *   `current_order_started_at`: `DATETIME` | `null` (ISO string format from MySQL). Represents when the table status first moved to 'Running'.

---

## 2. Accounting Module (`/api/accounting`)

### `GET /api/accounting/dashboard`
*   **Description:** Aggregated financial data for a specific date.
*   **Query Parameters:**
    *   `date`: (Optional) `YYYY-MM-DD`. Defaults to today.
*   **Response:**
    ```json
    {
      "success": true,
      "data": {
        "date": "2026-04-14",
        "total_revenue": 45230.00,
        "total_expenses": 8150.00,
        "net_profit": 37080.00,
        "cash_in_drawer": 12450.00,
        "recent_transactions": [
          { "tx_id": "TX-1001", "type": "Sale", "method": "UPI", "amount": 1250.00, "details": "Table 4" },
          { "tx_id": "EXP-20260414-A1B2C3", "type": "Expense", "method": "Cash", "amount": -400.00, "details": "Groceries" }
        ]
      }
    }
    ```

### `GET /api/accounting/drawer`
*   **Description:** Detailed cash breakdown for the till.
*   **Query Parameters:**
    *   `date`: (Optional) `YYYY-MM-DD`.
*   **Response:**
    ```json
    {
      "success": true,
      "data": {
        "date": "2026-04-14",
        "starting_cash": 5000.00,
        "cash_sales": 8000.00,
        "cash_expenses": 550.00,
        "expected_cash_in_till": 12450.00,
        "is_closed": false
      }
    }
    ```

### `POST /api/accounting/drawer/close`
*   **Description:** Closes the cash drawer and logs physical cash count.
*   **Payload:**
    ```json
    {
      "date": "2026-04-14",
      "actual_cash": 12400.00,
      "starting_cash": 5000.00,
      "notes": "Short by 50 rupees, possibly wrong change."
    }
    ```

---

## 3. Expense Management (`/api/expenses`)

### `GET /api/expenses/categories`
*   **Description:** List of available expense categories.
*   **Response:**
    ```json
    {
      "success": true,
      "data": [
        { "id": 1, "name": "Groceries/Ingredients" },
        { "id": 2, "name": "Utilities" }
      ]
    }
    ```

### `GET /api/expenses`
*   **Description:** Paginated list of logged expenses.
*   **Query Parameters:**
    *   `date_from`: `YYYY-MM-DD`
    *   `date_to`: `YYYY-MM-DD`
    *   `category_id`: `INT`
    *   `page`: `INT` (Default: 1)
*   **Response:** Includes pagination object and data array with `category_name`.

### `POST /api/expenses`
*   **Description:** Log a new operation expense.
*   **Payload:**
    ```json
    {
      "category_id": 1,
      "amount": 400.00,
      "payment_method": "Cash",
      "description": "Sugar and Tea stock",
      "date": "2026-04-14",
      "time": "14:15:00"
    }
    ```
*   **Response:** Returns the created expense object including the generated `txn_id`.
