# Payment method summary (received)

Dashboard totals for **customer payments received**, grouped by payment method — cash, card, bank transfer, cheque, and online.

Bill payments (money out to vendors) are **not** included.

---

## Endpoint

```
GET /api/v1/reports/payment-method-summary
```

**Auth:** `Bearer` token (Sanctum)  
**Roles:** Any authenticated company user

---

## Query parameters

| Parameter    | Type   | Required | Default | Description                                                                 |
|--------------|--------|----------|---------|-----------------------------------------------------------------------------|
| `period`     | string | No       | `today` | `today`, `week`, `month`, `quarter`, `year`. Ignored when dates are sent.   |
| `start_date` | date   | No       | —       | Inclusive lower bound (`YYYY-MM-DD`). Defaults to the first day of the month containing `end_date` when only `end_date` is sent. |
| `end_date`   | date   | No       | —       | Inclusive upper bound (`YYYY-MM-DD`). Defaults to today when only `start_date` is sent. Must be on or after `start_date`. |

When `start_date` and/or `end_date` is provided, the custom range is used and `period` in the response is `null`. When neither date is sent, `period` controls the window (default `today`).

### Examples

```
GET /api/v1/reports/payment-method-summary?period=month
GET /api/v1/reports/payment-method-summary?start_date=2026-01-01&end_date=2026-06-30
GET /api/v1/reports/payment-method-summary?start_date=2026-06-01
```

---

## Response `200 OK`

```json
{
  "data": {
    "period": "today",
    "start_date": "2026-06-20",
    "end_date": "2026-06-20",
    "total": "650.0000",
    "count": 4,
    "by_method": [
      { "payment_method": "CASH",          "total": "100.0000", "count": 1 },
      { "payment_method": "CARD",          "total": "200.0000", "count": 1 },
      { "payment_method": "BANK_TRANSFER", "total": "300.0000", "count": 1 },
      { "payment_method": "CHEQUE",        "total": "0.0000",   "count": 0 },
      { "payment_method": "ONLINE",        "total": "50.0000",  "count": 1 }
    ]
  }
}
```

### Fields

| Field                    | Type        | Description                                      |
|--------------------------|-------------|--------------------------------------------------|
| `period`                 | string/null | Echo of the requested preset, or `null` for a custom date range |
| `start_date`             | date       | Start of the date range (inclusive)              |
| `end_date`               | date       | End of the date range (inclusive)                |
| `total`                  | decimal(4) | Sum of all customer payment amounts in range     |
| `count`                  | integer    | Number of customer payments in range             |
| `by_method`              | array      | One row per payment method (always all five)     |
| `by_method[].payment_method` | string | `CASH`, `CARD`, `BANK_TRANSFER`, `CHEQUE`, `ONLINE` |
| `by_method[].total`      | decimal(4) | Total received via that method                   |
| `by_method[].count`      | integer    | Number of payments via that method               |

## Response `200 OK` — custom range

```json
{
  "data": {
    "period": null,
    "start_date": "2026-01-01",
    "end_date": "2026-06-30",
    "total": "300.0000",
    "count": 2,
    "by_method": [
      { "payment_method": "CASH",          "total": "100.0000", "count": 1 },
      { "payment_method": "CARD",          "total": "200.0000", "count": 1 },
      { "payment_method": "BANK_TRANSFER", "total": "0.0000",   "count": 0 },
      { "payment_method": "CHEQUE",        "total": "0.0000",   "count": 0 },
      { "payment_method": "ONLINE",        "total": "0.0000",   "count": 0 }
    ]
  }
}
```

---

## Calculation

- Source: `payments` table (customer payments only)
- Filter: `txn_date` within the resolved period, scoped to `company_id`
- Amount: `SUM(total_amount)` per `payment_method`
- Includes advance/unapplied payments (full payment header amount)

---

## Period windows

| `period`  | Window                         |
|-----------|--------------------------------|
| `today`   | Today only                     |
| `week`    | Current calendar week          |
| `month`   | Current calendar month         |
| `quarter` | Current calendar quarter       |
| `year`    | Current calendar year          |

All periods anchor to the server’s current date (`Carbon::now()`).

---

## Error responses

### `422 Unprocessable Entity` — invalid period or dates

```json
{
  "message": "The selected period is invalid.",
  "errors": {
    "period": ["The selected period is invalid."]
  }
}
```

### `401 Unauthorized`

```json
{ "message": "Unauthenticated." }
```
