---
# (DD13) Business Logic — Loan.returnBook() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `model.Loan` |
| Layer | Model / Domain Object |
| Module | `model` (Package: `model`) |

## 1. Role

### Loan.returnBook()

`Loan.returnBook()` is the domain-level return transaction for a borrowed book record. It finalizes the loan by stamping the current business date into the loan's return date field, marking the loan as returned, and releasing the associated book back to the available inventory. In business terms, this method closes the lifecycle of a loan and restores the book to a borrowable state.

The method implements a straightforward state-transition pattern: it moves a loan from “active borrowing” to “returned” and synchronizes the book’s availability status with that change. It does not branch or route by service type; instead, it performs a single cohesive business action with three sequential state updates. This makes it a shared domain operation that can be invoked by higher-level application services or user interfaces whenever a customer returns a book.

Because the method operates directly on entity state, it serves as a local consistency boundary for the loan and book aggregate. Its role in the larger system is to encapsulate the return-side business rules so that calling code does not need to know the exact fields that must be updated to complete a return.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["returnBook()"])
    STEP1["Set returnDate to LocalDate.now()"]
    STEP2["Set returned flag to true"]
    STEP3["Call book.setAvailable(true)"]
    END_NODE(["Return"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

This method has no parameters. It acts entirely on instance state and external time via `LocalDate.now()`. The method reads and updates the following instance fields: `returnDate`, `returned`, and `book`.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Book.setAvailable` | Book | - | Calls `setAvailable` in `Book` |

Analyze all method calls within this method and classify each as a CRUD operation.
Use the pre-computed evidence above. If SC Code or Entity/DB is missing, try to infer from:
- The **SC Code** (Service Component code, e.g., `EKK0361A010SC`, `EKK1081D010CBS`) — look at the class name of the called method or its containing class.
- The **Entity/DB tables** — search for table name constants (often `KK_T_*` pattern), SQL references, or entity names in the called method's source code.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `Book.setAvailable` | Book | `model.Book` | Updates the availability state of the loaned book so it can be borrowed again. |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 3 methods.
Terminal operations from this method: `setAvailable` [-]

Trace who calls this method and what this method ultimately calls.
Use the pre-computed evidence and caller search results from Step 2 above.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Service: `LoanService` | `ConsoleUI.returnBook()` -> `LoanService.returnBook(String)` -> `Loan.returnBook()` | `Book.setAvailable(true) [U] model.Book` |
| 2 | UI: `ConsoleUI` | `ConsoleUI.returnBook()` -> `LoanService.returnBook(String)` -> `Loan.returnBook()` | `Book.setAvailable(true) [U] model.Book` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(returnBook())` (L21)

> Finalizes the loan and restores the book to available status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `this.returnDate = LocalDate.now();` |
| 2 | SET | `this.returned = true;` |
| 3 | EXEC | `this.book.setAvailable(true);` |
| 4 | RETURN | `void` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Loan` | Domain object | Represents a borrowing transaction for a book. |
| `returnBook` | Business action | Completes a loan by recording the return date, marking the loan returned, and making the book available again. |
| `returnDate` | Field | The date the borrowed book was returned. |
| `returned` | Field | Flag indicating whether the loan has been closed by a return. |
| `book` | Field | The borrowed book associated with the loan. |
| `member` | Field | The customer or library user who borrowed the book. |
| `LocalDate.now()` | Technical function | Returns the current business/system date used as the return date. |
| `available` | Field | Book availability flag showing whether the book can be borrowed. |
| `Book` | Domain object | Book master/transaction object whose availability is synchronized with the loan state. |
| `setAvailable` | Method | Updates a book’s availability status. |
