# Business Logic — FUW02701SFLogic.getPayFlg() [27 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.FUW02701SF.FUW02701SFLogic` |
| Layer | Service / Web View Logic (Controller-adjacent service layer handling screen business rules) |
| Module | `FUW02701SF` (Package: `eo.web.webview.FUW02701SF`) |

## 1. Role

### FUW02701SFLogic.getPayFlg()

This method determines whether a user's bandwidth upgrade selection on the service contract screen triggers a paid (有料) charge or remains free (無料). It is invoked during screen initialization (`init()`) and confirmation processing (`back()`) of the FUW02701SF screen — a web view screen for managing internet service contract bandwidth upgrades. The method evaluates three data values pulled from the request-scoped data bean: the free bandwidth allowance, the maximum incremental bandwidth amount the user has selected for addition, and the fixed unit price from the pricing plan. If the selected incremental bandwidth exceeds the free allowance and the unit price is positive, the method returns `true` indicating the user must pay; otherwise, it returns `false`. This is a pure computation method with no side effects, no database interaction, and no external service calls — it functions as a business rule evaluator that gates downstream charge display and payment confirmation logic on the screen.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getPayFlg(bean)"])
    READ_FREE["Read freeValue from bean.MRYO_CAPA"]
    READ_END["Read endValue from bean.ADD_CAPA_ZOUBUN_UPPL_VALUE"]
    READ_TANKA["Read tanka from bean.PPLAN_KOTEI_AMNT"]
    INIT_FLG["Set payFlg = false"]
    COND1{"endValue != 0 AND freeValue != 0"}
    COND2{"endValue > freeValue AND tanka > 0"}
    SET_TRUE["Set payFlg = true"]
    SET_FALSE["Set payFlg = false"]
    RETURN_FLG(["Return payFlg"])

    START --> READ_FREE --> READ_END --> READ_TANKA --> INIT_FLG --> COND1
    COND1 -- true --> COND2
    COND1 -- false --> SET_FALSE
    COND2 -- true --> SET_TRUE
    COND2 -- false --> SET_FALSE
    SET_TRUE --> RETURN_FLG
    SET_FALSE --> RETURN_FLG
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `FUW02701SFConst.MRYO_CAPA` | `"無効容量"` (Free Capacity) | The free-tier bandwidth allowance available to the user |
| `FUW02701SFConst.ADD_CAPA_ZOUBUN_UPPL_VALUE` | `"追加容量増分上限値"` (Additional Bandwidth Increment Upper Limit) | The maximum incremental bandwidth amount the user has selected |
| `FUW02701SFConst.PPLAN_KOTEI_AMNT` | `"料金プラン固定金額"` (Pricing Plan Fixed Amount) | The unit price (fixed amount) for the selected pricing plan |
| `X31CWebConst.DATABEAN_GET_VALUE` | (internal enum/constant) | Data bean accessor for retrieving stored values |

The business rule is straightforward: the user is charged **only when** both (1) the selected bandwidth increment upper limit is greater than the free allowance, AND (2) the pricing plan's fixed unit amount is greater than zero. If either the free capacity or the increment limit is zero, or if the selected increment does not exceed the free allowance, the result is free.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `bean` | `X31SDataBeanAccess` | The request-scoped data transfer object carrying the user's bandwidth selection and pricing plan information. It contains the free capacity allowance (`MRYO_CAPA`), the additional bandwidth increment upper limit (`ADD_CAPA_ZOUBUN_UPPL_VALUE`), and the pricing plan fixed amount (`PPLAN_KOTEI_AMNT`). This bean is populated earlier in the screen lifecycle by the initialization flow and represents the user's current selection state. |

**Instance fields read:** None. This method is stateless and reads no instance-level fields.

## 4. CRUD Operations / Called Services

This method performs **no CRUD operations** and calls **no external services, SC codes, or CBS components**. It is a pure in-memory computation that reads values from the data bean and evaluates a conditional expression.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| *(none)* | — | — | — | This method contains no data access, no service calls, and no persistence operations. It is a pure business rule evaluation. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: -

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen: FUW02701SF (`init()`) | `FUW02701SFLogic.init()` → `getPayFlg(bean)` | — |
| 2 | Screen: FUW02701SF (`back()`) | `FUW02701SFLogic.back()` → `getPayFlg(bean)` | — |

**Caller context:**
- **`init()` (line ~238)**: Called during screen initialization. The return value is immediately written to the bean at key `FUW02701SFConst.PAY_FLG` (有料フラグ, "Pay Flag") so the screen can render paid/free indicators to the user.
- **`back()` (line ~547)**: Called when the user presses the confirmation back button. The result is again set into the bean under `PAY_FLG` to refresh the display state after parameter changes.

Both callers follow the same pattern: `bean.sendMessageBoolean(FUW02701SFConst.PAY_FLG, X31CWebConst.DATABEAN_SET_VALUE, getPayFlg(bean))` — passing the boolean result as the value to set on the `PAY_FLG` key.

## 6. Per-Branch Detail Blocks

**Block 1** — SET (L918)

> Retrieves the free bandwidth allowance from the data bean.

| # | Type | Code |
|---|------|------|
| 1 | SET | `freeValue = bean.sendMessageLong(FUW02701SFConst.MRYO_CAPA, X31CWebConst.DATABEAN_GET_VALUE).intValue()` // Free capacity value [-> MRYO_CAPA="無効容量"] |

**Block 2** — SET (L920)

> Retrieves the additional bandwidth increment upper limit from the data bean.

| # | Type | Code |
|---|------|------|
| 1 | SET | `endValue = bean.sendMessageLong(FUW02701SFConst.ADD_CAPA_ZOUBUN_UPPL_VALUE, X31CWebConst.DATABEAN_GET_VALUE).intValue()` // Upper limit of incremental bandwidth amount [-> ADD_CAPA_ZOUBUN_UPPL_VALUE="追加容量増分上限値"] |

**Block 3** — SET (L922)

> Retrieves the pricing plan fixed amount (unit price) from the data bean.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tanka = bean.sendMessageLong(FUW02701SFConst.PPLAN_KOTEI_AMNT, X31CWebConst.DATABEAN_GET_VALUE).intValue()` // Fixed amount per additional bandwidth increment [-> PPLAN_KOTEI_AMNT="料金プラン固定金額"] |

**Block 4** — SET (L924)

> Initializes the paid flag to `false` (default: free).

| # | Type | Code |
|---|------|------|
| 1 | SET | `payFlg = false` // Default to free (無料) |

**Block 5** — IF (condition: `0 != endValue && 0 != freeValue`) (L927)

> Checks that both the incremental bandwidth upper limit and the free capacity are non-zero. If either value is zero, the user is considered free (no charge scenario).

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (0 != endValue && 0 != freeValue)` [Both increment limit and free capacity must be non-zero] |

**Block 5.1** — IF-ELSE-IF (nested condition: `endValue > freeValue && tanka > 0`) (L928)

> Within the non-zero branch, checks whether the user has selected an incremental bandwidth that exceeds the free allowance AND the pricing plan has a positive unit price. Both conditions must hold for the charge to apply.

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (endValue > freeValue && tanka > 0)` [Incremental limit exceeds free allowance AND unit price is positive] |
| 2 | SET | `payFlg = true` // Mark as paid (有料) [L930] |

**Block 5.1.1** — ELSE (L932)

> If the incremental limit does not exceed the free allowance or the unit price is not positive, the result remains free.

| # | Type | Code |
|---|------|------|
| 1 | SET | `payFlg = false` // Explicitly free (無料) [L933] |

**Block 5.2** — ELSE (L932)

> If either `endValue` or `freeValue` is zero, the result is free. This covers scenarios such as: zero free capacity (entire usage is paid, but handled elsewhere) or zero incremental bandwidth (no upgrade selected).

| # | Type | Code |
|---|------|------|
| 1 | SET | `payFlg = false` // Free (無料) [L933] |

**Block 6** — RETURN (L936)

> Returns the computed paid flag to the caller.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return payFlg` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-----------------|
| `getPayFlg` | Method | Pay flag getter — determines whether a bandwidth upgrade selection incurs a charge |
| `payFlg` | Field | Paid flag — `true` means the user must pay (有料), `false` means free (無料) |
| `freeValue` | Local var | Free bandwidth capacity — the amount of bandwidth included at no charge in the user's current plan |
| `endValue` | Local var | Additional bandwidth increment upper limit — the maximum extra bandwidth the user has selected to add |
| `tanka` | Local var | Unit price (fixed amount) — the cost per unit from the pricing plan's fixed fee structure |
| `MRYO_CAPA` | Constant Key | Free capacity — data bean key for the free-tier bandwidth allowance [無効容量] |
| `ADD_CAPA_ZOUBUN_UPPL_VALUE` | Constant Key | Additional bandwidth increment upper limit — data bean key for the maximum selectable incremental bandwidth [追加容量増分上限値] |
| `PPLAN_KOTEI_AMNT` | Constant Key | Pricing plan fixed amount — data bean key for the fixed fee/unit price of the selected plan [料金プラン固定金額] |
| `PAY_FLG` | Constant Key | Pay flag — data bean key used to store and retrieve the paid/free determination result [有料フラグ] |
| `X31SDataBeanAccess` | Class | Request-scoped data access bean — carries screen state and user selections between initialization, validation, and response phases |
| `X31CWebConst.DATABEAN_GET_VALUE` | Constant | Data bean accessor — instructs the bean to retrieve a stored value by key |
| `X31CWebConst.DATABEAN_SET_VALUE` | Constant | Data bean mutator — instructs the bean to store a value under a key |
| `FUW02701SF` | Module | Web screen module for internet service contract bandwidth upgrade management |
| 有料 (Yuryo) | Japanese term | Paid — the user must pay for the selected service/bandwidth |
| 無料 (Muryo) | Japanese term | Free — the selected service/bandwidth is included at no charge |
| 追加容量 (Tsuika Yoryo) | Japanese term | Additional bandwidth — bandwidth beyond the base/free allowance that the user can purchase |
| 料金プラン (Ryokin Plan) | Japanese term | Pricing plan — the billing tier/plan that determines the fixed fee and unit rates |
