> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vinmake.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Loans and treasury

> One lifecycle for every facility shape, a balance derived from movements, and the recourse distinction that decides whether a receivable stays on the books.

# Loans and treasury

Sub-ledger 4, migration `0006`.

## One lifecycle, every facility shape

A term loan, a revolving facility, an owner loan and a factoring line are different products with the same shape: money is drawn, interest accrues, principal is repaid, fees are charged.

So there is one lifecycle, and the facility's own attributes carry the differences.

| Operation                   | Entry                                                                           |
| --------------------------- | ------------------------------------------------------------------------------- |
| drawdown                    | `Dr <rail>` / `Cr 2400` (VAS 341 facility loan)                                 |
| interest accrual            | `Dr 6210` (VAS 635 finance cost) / `Cr 2400` - added to what is owed            |
| principal repayment         | `Dr 2400` / `Cr <rail>`                                                         |
| interest payment            | `Dr 2400` / `Cr <rail>`                                                         |
| fee                         | `Dr 6210` / `Cr <rail>`                                                         |
| factoring, **recourse**     | `Dr <rail>` / `Cr 2400` - the receivable **stays** on the books                 |
| factoring, **non-recourse** | `Dr <rail>` / `Dr 6210` fee / `Cr 1100` AR - the receivable is **derecognised** |

## Currency and base evidence

Every drawdown, accrual, repayment, fee and factoring event states the facility/document currency on its journal lines.
The ledger resolves the dated FX rate inside the transaction; a missing rate rolls the whole event back instead of storing a movement at par.

Each new loan movement keeps its native amount and currency plus the exact base amount, journal entry and journal line that the immutable posting established.
Books and Close use that journal-line evidence.
Historical movements without it remain explicitly unresolved; GreatBook does not backfill them from a current rate or assume base currency.

Factoring also keeps four facts separate: cash advance, finance fee, receivable derecognition and any recourse borrowing.
The settlement row is the cash component in its real currency and links to the exact journal entry; a non-recourse purchase derecognises only the authoritative purchased receivable amount, while recourse leaves AR open and records the facility debt.

## The balance is derived

```
facility balance = drawdown + interest accrued - principal repaid - interest paid
```

There is no `balance` column.
`FACILITY-BAL` then checks that the balance derived from the movements equals the facility's GL loan-account balance, which is two independent paths that must agree.

That check exists to catch precisely the thing a stored balance invites: a keyed or pasted figure drifting from the movement ledger.

## Recourse is the interesting distinction

Factoring a receivable can be two completely different accounting events, and which one it is depends on who carries the risk if the customer does not pay.

|                            | Recourse              | Non-recourse                 |
| -------------------------- | --------------------- | ---------------------------- |
| Who bears the default risk | you do                | the factor does              |
| What it economically is    | **secured borrowing** | a **sale** of the receivable |
| The receivable             | stays on the books    | derecognised                 |
| The liability              | a facility balance    | none                         |
| `obligation.due`           | unchanged             | goes to zero                 |

Getting this wrong in the recourse direction understates both assets and liabilities, which flatters every leverage ratio a lender looks at.

The Close list polices it from both ends: `NONRECOURSE-NODEBT` asserts that a non-recourse facility carries no loan debt, and the factoring derecognition checks read `obligation.due` from [sub-ledger 1](/greatbook/capabilities/subledgers/settlement) to confirm the receivable moved the way the recourse flag says it should.

## The checks

| Code                 | What it catches                                              |
| -------------------- | ------------------------------------------------------------ |
| `FACILITY-BAL:<id>`  | a facility balance that has drifted from its movements       |
| `HEADROOM`           | drawn amount exceeding the credit limit                      |
| `INTEREST-OVERPAID`  | a facility that paid more interest than it accrued           |
| `FLOAT-FACILITY-TIE` | the employee-float facility and the float ledger net to zero |
| `LOAN-MV-CATALOG`    | a movement type outside the catalog                          |
| `NONRECOURSE-NODEBT` | a non-recourse factoring line carrying loan debt             |
| `FACILITY-OWED:<id>` | *explainable*: what each facility owes                       |

Facility-scoped checks expand per facility, so this family's size depends on the book.

## Where it is enforced

| Concern                                      | Code                                                        |
| -------------------------------------------- | ----------------------------------------------------------- |
| the lifecycle and the legs                   | `backend/app/logics/finance/loans.py`                       |
| the schema and exact base-evidence extension | migrations `0006_loans_treasury`, `0052_loan_base_evidence` |
| the derived balances                         | `derive.facility_balance`, `derive.facility_gl_balance`     |
| the checks                                   | `close_checks.run_loan_checks`                              |

Facilities settle on [rails](/greatbook/capabilities/subledgers/settlement) like anything else, so a drawdown that hit the bank reconciles against the bank statement rather than being taken on trust.

## The test that would fail if it broke

`backend/tests/test_loans.py` covers the lifecycle and both factoring shapes against the v12 worked data: a recourse buyout where the receivable stays, and a non-recourse one where it is derecognised together with the factor's fee.

## What goes wrong without it

Two failures, in order of how often they happen.

**A keyed facility balance.**
Somebody types the number from the bank's statement into a field.
It is right on the day and drifts thereafter, and because it is also what the balance sheet reports, the drift is invisible until a reconciliation nobody has done.

**Recourse treated as sale.**
The receivable comes off the books, the liability never goes on, and the balance sheet shows a business with less leverage and better working capital than it has.
This is a well-known audit finding class, and it is the reason the recourse flag is a first-class attribute here rather than a note in a description field.

## Related

* [Settlement, rails and the AP/AR spine](/greatbook/capabilities/subledgers/settlement) - the rails facilities move on, and the AR they derecognise
* [Nothing stored that can be derived](/greatbook/capabilities/derived-balances) - why the facility balance has no column
* [The Close checksums](/greatbook/capabilities/close-list) - the loans family in the full surface
