# Admin API: Get All Agents with Today's Receipt Entries

## Endpoint
`GET /admin/agents-with-receipts`

## Description
Returns all agents with their today's receipt entries. Supports filtering by line, status, and date.

## Authentication
Requires admin authentication via Bearer token.

## Query Parameters
- `line` (optional): Filter agents by line (e.g., "Line 1", "Line 2")
- `status` (optional): Filter agents by status (e.g., "Active", "Inactive")
- `date` (optional): Filter receipts by date (format: YYYY-MM-DD). Defaults to today if not provided.

## cURL Examples

### 1. Get All Agents with Today's Receipts
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

### 2. Filter by Line
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts?line=Line%202" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

### 3. Filter by Status
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts?status=Active" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

### 4. Filter by Date (Specific Date)
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts?date=2025-12-06" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

### 5. Multiple Filters (Line + Status)
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts?line=Line%202&status=Active" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

### 6. All Filters (Line + Status + Date)
```bash
curl -X GET "http://localhost:3000/admin/agents-with-receipts?line=Line%202&status=Active&date=2025-12-06" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_AUTH_TOKEN" \
  -H "Content-Type: application/json"
```

## Response Format

### Success Response (200 OK)
```json
{
  "status": "success",
  "message": "Agents with today's receipts retrieved successfully",
  "data": {
    "filters": {
      "company_id": 15,
      "line": "Line 2",
      "status": "Active",
      "date": "2025-12-06"
    },
    "summary": {
      "total_agents": 5,
      "agents_with_receipts": 3,
      "agents_without_receipts": 2,
      "total_receipts_today": 10,
      "total_collected_amount": 2500.00
    },
    "agents": [
      {
        "agent": {
          "id": 5,
          "name": "Raja",
          "mobile_no": "8825948300",
          "line": "Line 2",
          "status": "Active",
          "address": "Erode",
          "aadhar_no": "882594830012",
          "created_at": "2025-12-03T17:31:14.000Z"
        },
        "today_receipts": {
          "date": "2025-12-06",
          "total_receipts": 3,
          "total_collected_amount": 920.00,
          "total_dues": 3,
          "total_paid_dues": 3,
          "receipts": [
            {
              "id": 56,
              "rec_no": "REC1764939408896",
              "rec_date": "2025-12-06",
              "loan_id": "DL2025001",
              "cust_id": 8,
              "cust_name": "Pavithra",
              "cust_mobile": "5346876764",
              "num_dues": 1,
              "due_amnt": 92,
              "paid_amnt": 92,
              "paid_dues": 1,
              "balance_dues": 0,
              "pending_dues": 0,
              "next_date": "2025-12-07",
              "remark": "Payment received",
              "created_at": "2025-12-06T06:30:00.000Z"
            }
          ]
        }
      }
    ],
    "timestamp": "2025-12-06T12:00:00.000Z"
  }
}
```

### Error Response (401 Unauthorized)
```json
{
  "status": "error",
  "message": "Admin authentication required"
}
```

### Error Response (500 Internal Server Error)
```json
{
  "status": "error",
  "message": "Failed to fetch agents with today's receipts",
  "error": "Error message details"
}
```

## Notes

1. **Authentication**: Replace `YOUR_ADMIN_AUTH_TOKEN` with a valid admin authentication token obtained from `/admin/login`.

2. **Date Format**: Use `YYYY-MM-DD` format for the date parameter (e.g., `2025-12-06`).

3. **URL Encoding**: When using query parameters with spaces, URL encode them (e.g., `Line%202` for "Line 2").

4. **Default Date**: If no date is provided, the API uses today's date.

5. **Agent Matching**: Receipts are matched to agents by comparing the `agent` field in receipts with the agent's `name` field (case-insensitive).

6. **Summary Statistics**: The response includes summary statistics showing:
   - Total agents
   - Agents with receipts today
   - Agents without receipts today
   - Total receipts for the day
   - Total collected amount for the day

## Example with Real Server URL

```bash
curl -X GET "http://192.168.1.3:3000/admin/agents-with-receipts" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer 64d4f1c242d4a71671d6397757555bb0df2f39b11281f58b6f13af6c274b8bb5" \
  -H "Content-Type: application/json"
```















