> For the complete documentation index, see [llms.txt](https://apidocs.d6plus.co.za/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.d6plus.co.za/reference/finance+/debt-management/age-analysis-report.md).

# Age Analysis Report

## Get a school's age analysis report

<mark style="color:blue;">`GET`</mark> `https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/ageanalysis/{school_login_id}`

Use this endpoint to generate an age analysis report for the specified school.

By default, only active accounts (current learners or accounts with an outstanding balance) will be returned. You can use the `all_accounts` query parameter to generate the report for all accounts (includes left learners and 0 balance accounts).

The report, by default, will be grouped by family and parent. Use the `per_learner` or `per_category` query parameter to group the data accordingly. If the `per_learner` and the `per_category` parameters are used in combination, the results will be grouped per learner, per category.

Additionally it is possible to filter on a specific `debtor_code` , `learner_id` , `accountable_person_id` and/or `category_id`.

#### Path Parameters

<table><thead><tr><th>Name</th><th width="152">Type</th><th>Description</th></tr></thead><tbody><tr><td>school_login_id<mark style="color:red;">*</mark></td><td>Integer</td><td>The login ID of the school to retrieve data from</td></tr></tbody></table>

#### Headers

| Name                                              | Type   | Description       |
| ------------------------------------------------- | ------ | ----------------- |
| HTTP-X-USERNAME<mark style="color:red;">\*</mark> | String | As provided by d6 |
| HTTP-X-PASSWORD<mark style="color:red;">\*</mark> | String | As provided by d6 |

#### Query Parameters

<table><thead><tr><th>Name</th><th width="151">Type</th><th>Description</th></tr></thead><tbody><tr><td>all_accounts</td><td>Boolean</td><td>Whether to include all accounts</td></tr><tr><td>per_learner</td><td>Boolean</td><td>Whether to group the data per learner</td></tr><tr><td>per_category</td><td>Boolean</td><td>Whether to group the data per category (can be used in conjunction with per_learner)</td></tr><tr><td>debtor_code</td><td>Integer</td><td>To filter on a specific Debtor Code</td></tr><tr><td>learner_id</td><td>Integer</td><td>To filter on a specific Learner ID</td></tr><tr><td>accountable_person_id</td><td>Integer</td><td>To filter on a specific Accountable Person ID</td></tr><tr><td>category_id</td><td>Integer</td><td>To filter on a specific Category ID</td></tr></tbody></table>

#### Response Examples

{% tabs %}
{% tab title="200: Per family and parent" %}

```json
[
    {
        "debtor_code": "1001",
        "accountable_person_id": "40",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "4500.00",
        "balance_total": "25200.00"
    },
    {
        "debtor_code": "1002",
        "accountable_person_id": "3",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "20000.00",
        "balance_total": "40700.00"
    }
]
```

{% endtab %}

{% tab title="200: Per Learner" %}

```json
[
    {
        "debtor_code": "1001",
        "accountable_person_id": "40",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "4500.00",
        "balance_total": "25200.00",
        "learners": [
            {
                "learner_id": "1",
                "learner_first_name": "Jordan",
                "learner_last_name": "Smith",
                "balance_current": "1750.00",
                "balance_30days": "1750.00",
                "balance_60days": "1750.00",
                "balance_90days": "1750.00",
                "balance_120days": "0.00",
                "balance_150days": "850.00",
                "balance_180days": "4500.00",
                "balance_total": "12350.00"
            },
            {
                "learner_id": "2",
                "learner_first_name": "Samantha",
                "learner_last_name": "Smith",
                "balance_current": "1750.00",
                "balance_30days": "1750.00",
                "balance_60days": "1750.00",
                "balance_90days": "1750.00",
                "balance_120days": "850.00",
                "balance_150days": "5000.00",
                "balance_180days": "0.00",
                "balance_total": "12850.00"
            }
        ]
    },
    {
        "family_code": "1002",
        "accountable_person_id": "3",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "20000.00",
        "balance_total": "40700.00",
        "learners": [
            {
                "learner_id": "3",
                "learner_first_name": "Nick",
                "learner_last_name": "Webster",
                "balance_current": "3500.00",
                "balance_30days": "3500.00",
                "balance_60days": "3500.00",
                "balance_90days": "3500.00",
                "balance_120days": "850.00",
                "balance_150days": "5850.00",
                "balance_180days": "20000.00",
                "balance_total": "40700.00",
            }
        ]
    }
]
```

{% endtab %}

{% tab title="200: Per Category" %}

<pre class="language-json"><code class="lang-json">[
    {
        "debtor_code": "1001",
        "accountable_person_id": "40",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "4500.00",
        "balance_total": "25200.00",
        "categories": [
<strong>            {
</strong>                "category_id": "1",
                "category_name": "School Fees",
                "balance_current": "2750.00",
                "balance_30days": "2750.00",
                "balance_60days": "2750.00",
                "balance_90days": "2750.00",
                "balance_120days": "0.00",
                "balance_150days": "4500.00",
                "balance_180days": "4500.00",
                "balance_total": "20000.00"
            },
            {
                "category_id": "6",
                "category_name": "Hostel Fees",
                "balance_current": "500.00",
                "balance_30days": "500.00",
                "balance_60days": "500.00",
                "balance_90days": "500.00",
                "balance_120days": "500.00",
                "balance_150days": "500.00",
                "balance_180days": "0.00",
                "balance_total": "3000.00"
            },
            {
                "category_id": "8",
                "category_name": "Sport",
                "balance_current": "250.00",
                "balance_30days": "250.00",
                "balance_60days": "250.00",
                "balance_90days": "250.00",
                "balance_120days": "250.00",
                "balance_150days": "850.00",
                "balance_180days": "0.00",
                "balance_total": "2100.00"
            }
        ]
    },
    {
        "family_code": "1002",
        "accountable_person_id": "3",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "20000.00",
        "balance_total": "40700.00",
        "categories": [
            {
                "category_id": "1",
                "category_name": "School Fees",
                "balance_current": "3500.00",
                "balance_30days": "3500.00",
                "balance_60days": "3500.00",
                "balance_90days": "3500.00",
                "balance_120days": "850.00",
                "balance_150days": "5850.00",
                "balance_180days": "20000.00",
                "balance_total": "40700.00",
            }
        ]
    }
]
</code></pre>

{% endtab %}

{% tab title="200: Per learner, per category" %}

```json
[
    {
        "debtor_code": "1001",
        "accountable_person_id": "40",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "4500.00",
        "balance_total": "25200.00",
        "learners": [
            {
                "learner_id": "1",
                "learner_first_name": "Jordan",
                "learner_last_name": "Smith",
                "balance_current": "1750.00",
                "balance_30days": "1750.00",
                "balance_60days": "1750.00",
                "balance_90days": "1750.00",
                "balance_120days": "0.00",
                "balance_150days": "850.00",
                "balance_180days": "4500.00",
                "balance_total": "12350.00",
                "categories": [
                    {
                        "category_id": "1",
                        "category_name": "School Fees",
                        "balance_current": "1000.00",
                        "balance_30days": "1000.00",
                        "balance_60days": "1000.00",
                        "balance_90days": "1000.00",
                        "balance_120days": "0.00",
                        "balance_150days": "0.00",
                        "balance_180days": "4500.00",
                        "balance_total": "8500.00"
                    },
                    {
                        "category_id": "6",
                        "category_name": "Hostel Fees",
                        "balance_current": "500.00",
                        "balance_30days": "500.00",
                        "balance_60days": "500.00",
                        "balance_90days": "500.00",
                        "balance_120days": "0.00",
                        "balance_150days": "500.00",
                        "balance_180days": "0.00",
                        "balance_total": "2500.00"
                    },
                    {
                        "category_id": "8",
                        "category_name": "Sport",
                        "balance_current": "250.00",
                        "balance_30days": "250.00",
                        "balance_60days": "250.00",
                        "balance_90days": "250.00",
                        "balance_120days": "0.00",
                        "balance_150days": "350.00",
                        "balance_180days": "0.00",
                        "balance_total": "1350.00"
                    }
                ]
            },
            {
                "learner_id": "2",
                "learner_first_name": "Samantha",
                "learner_last_name": "Smith",
                "balance_current": "1750.00",
                "balance_30days": "1750.00",
                "balance_60days": "1750.00",
                "balance_90days": "1750.00",
                "balance_120days": "850.00",
                "balance_150days": "5000.00",
                "balance_180days": "0.00",
                "balance_total": "12850.00",
                "categories": [
                    {
                        "category_id": "1",
                        "category_name": "School Fees",
                        "balance_current": "1000.00",
                        "balance_30days": "1000.00",
                        "balance_60days": "1000.00",
                        "balance_90days": "1000.00",
                        "balance_120days": "0.00",
                        "balance_150days": "4500.00",
                        "balance_180days": "0.00",
                        "balance_total": "8500.00"
                    },
                    {
                        "category_id": "6",
                        "category_name": "Hostel Fees",
                        "balance_current": "500.00",
                        "balance_30days": "500.00",
                        "balance_60days": "500.00",
                        "balance_90days": "500.00",
                        "balance_120days": "500.00",
                        "balance_150days": "500.00",
                        "balance_180days": "0.00",
                        "balance_total": "3000.00"
                    },
                    {
                        "category_id": "8",
                        "category_name": "Sport",
                        "balance_current": "250.00",
                        "balance_30days": "250.00",
                        "balance_60days": "250.00",
                        "balance_90days": "250.00",
                        "balance_120days": "350.00",
                        "balance_150days": "0.00",
                        "balance_180days": "0.00",
                        "balance_total": "1350.00"
                    }
                ]
            }
        ]
    },
    {
        "family_code": "1002",
        "accountable_person_id": "3",
        "date": "2024-04-10",
        "balance_current": "3500.00",
        "balance_30days": "3500.00",
        "balance_60days": "3500.00",
        "balance_90days": "3500.00",
        "balance_120days": "850.00",
        "balance_150days": "5850.00",
        "balance_180days": "20000.00",
        "balance_total": "40700.00",
        "learners": [
            {
                "learner_id": "3",
                "learner_first_name": "Nick",
                "learner_last_name": "Webster",
                "balance_current": "3500.00",
                "balance_30days": "3500.00",
                "balance_60days": "3500.00",
                "balance_90days": "3500.00",
                "balance_120days": "850.00",
                "balance_150days": "5850.00",
                "balance_180days": "20000.00",
                "balance_total": "40700.00",
                "categories": [
                    {
                        "category_id": "1",
                        "category_name": "School Fees",
                        "balance_current": "3500.00",
                        "balance_30days": "3500.00",
                        "balance_60days": "3500.00",
                        "balance_90days": "3500.00",
                        "balance_120days": "850.00",
                        "balance_150days": "5850.00",
                        "balance_180days": "20000.00",
                        "balance_total": "40700.00",
                    }
                ]
            }
        ]
    }
]
```

{% endtab %}

{% tab title="204: No Content" %}

```json
```

{% endtab %}

{% tab title="401: Unauthorized The server understood the request, but is refusing it or access is not allowed." %}

```json
{
    "error": "Unauthorized",
    "error_description": "Client access not authorised"
}
```

{% endtab %}

{% tab title="403: Forbidden The server understood the request, but the requested action is not allowed." %}

```json
{
    "error": "Integration not activated",
    "error_description": "Please activate the Finance+ API for this client before making this request"
}
```

{% endtab %}
{% endtabs %}

## Code Samples

{% tabs %}
{% tab title="PHP" %}

```php
<?php

const BASE_URL = 'https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/ageanalysis';
const SCHOOL_LOGIN_ID = '1000';
const PARAMS = [
    'per_learner' => 1, 
    'all_accounts' => 1,
    'debtor_code' => 1001,
    'learner_id' => 2,
    'accountable_person_id' => 3
    ];
const API_USERNAME = getenv('API_USERNAME'); // Assuming you have these environment variables set
const API_PASSWORD = getenv('API_PASSWORD');

$curl = curl_init();

$query = http_build_query(PARAMS);

$options = [
    CURLOPT_URL => BASE_URL . '/' . SCHOOL_LOGIN_ID . '?' . $query,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        "HTTP-X-USERNAME: " . API_USERNAME,
        "HTTP-X-PASSWORD: " . API_PASSWORD
    ],
];

curl_setopt_array($curl, $options);

$response = curl_exec($curl);

if (curl_errno($curl)) {
    throw new Exception('Curl error: ' . curl_error($curl));
}

curl_close($curl);

echo $response;
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --location 'https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/ageanalysis/1000?per_learner=1&all_accounts=1&debtor_code=1001&learner_id=2&accountable_person_id=3' \
--header 'HTTP-X-USERNAME: your_username' \
--header 'HTTP-X-PASSWORD: your_password'
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.d6plus.co.za/reference/finance+/debt-management/age-analysis-report.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
