> For the complete documentation index, see [llms.txt](https://docs.maple.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maple.finance/technical-resources/strategies/fixed-term-loan-manager/advance-global-payment-accounting.md).

# Advance Payment Accounting

## Overview

Whenever any interaction is made with a `Fixed Term Loan` from the `FixedTermLoanManager`, `_advanceGlobalPaymentAccounting` is called. The purpose of this function is to account all Loans' outstanding interest and to represent the current state at the current timestamp.

For all of the below examples, the following abbreviations are used:

* $$AI$$: `accountedInterest`
* $$IR$$: `issuanceRate`
* $$DS$$: `domainStart`
* $$DE$$: `domainEnd`

For all of the below examples, $accountedInterest$ starts as the following:

$$
\large \begin{align} \nonumber AI\_{pre-AGPA} = \Big(IR\_1 \times (DE\_0 - DS\_0)\Big) + \Big(IR\_{1+2} \times (DE\_1 - DS\_1)\Big) \end{align}
$$

## Example 1: Call before `domainEnd`

In this example, the payment is made before the `domainEnd`, so no payments are removed from the sorted list.

$$
\large \begin{align} \nonumber AI\_{post-AGPA} = AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (t\_{payment} - DS\_2)\Big) \end{align}
$$

![AGPA 1](https://user-images.githubusercontent.com/44272939/196194337-01360be6-04fb-402f-b064-d21faba1f62d.svg)

## Example 2: Call after `domainEnd`, before Loan 2 Payment Due Date

In this example, the payment is made after the `domainEnd`, so Loan 1 is removed from the sorted list and `domainEnd` is updated.

$$
\large \begin{align} \nonumber AI\_{post-AGPA} = AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \Big(IR\_{2+3} \times (t\_{payment} - DS\_3)\Big) \end{align}
$$

![AGPA 2](https://user-images.githubusercontent.com/44272939/196194336-ce355b53-0cad-445f-a5dd-7cb34ab1865d.svg)

## Example 3: Call after `domainEnd`, before Loan 3 Payment Due Date

In this example, the payment is made after the `domainEnd` and Loan 2's payment due date, so Loans 1 and 2 are removed from the sorted list and `domainEnd` is updated.

$$
\large \begin{align} \nonumber AI\_{post-AGPA} = \&AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \ &\Big(IR\_{2+3} \times (DE\_3 - DS\_3)\Big) + \Big(IR\_{3} \times (t\_{payment} - DS\_4)\Big) \end{align}
$$

![AGPA 3](https://user-images.githubusercontent.com/44272939/196215192-cf45223e-fc8a-4b1e-a412-4c56ea7f9a6e.svg)

## Example 4: Call after `domainEnd`, after Loan 3 Payment Due Date

In this example, the payment is made after the `domainEnd`, Loan 2, and Loan 3's payment due dates, so Loans 1, 2 and 3 are removed from the sorted list and `domainEnd` is updated.

$$
\begin{align} \nonumber AI\_{post-AGPA} = \&AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \Big(IR\_{2+3} \times (DE\_3 - DS\_3)\Big) + \ &\Big(IR\_{3} \times (DE\_4 - DS\_4)\Big) + \Big(0 \times (t\_{payment} - DS\_5)\Big) \end{align}
$$

![AGPA 4](https://user-images.githubusercontent.com/44272939/196194328-a16a052d-f9b0-4897-a0b4-225b9035d6d7.svg)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maple.finance/technical-resources/strategies/fixed-term-loan-manager/advance-global-payment-accounting.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
