# Business Logic — FUW01901SFLogic.setPayFlg() [39 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.FUW01901SF.FUW01901SFLogic` |
| Layer | Service Logic (Webview layer — within `eo.web.webview.FUW01901SF` package) |
| Module | `FUW01901SF` (Package: `eo.web.webview.FUW01901SF`) |

## 1. Role

### FUW01901SFLogic.setPayFlg()

The `setPayFlg` method determines whether a customer's service order in the FUW01901SF (Fiber To The Home / FTTH service registration) screen should be classified as **paid (有料)** or **free (無料)** — i.e., whether a payment obligation exists. This is a billing classification method that participates in the service contract confirmation workflow. It evaluates three business conditions in sequence: whether a fixed unit price (固定単価) exists for the service via the `chkPayKoteiTanka` sub-check, the count of free-tier items, and whether the customer holds an active package contract (パック契約). If a fixed unit price exists AND there are no free-tier items, the service is paid. If a fixed unit price exists AND there are free-tier items AND the customer has a package contract, the service is also paid. In all other cases (no fixed unit price, or free-tier items exist without a package contract), the service is free. The method implements a nested conditional routing pattern, delegating the fixed-price verification to `chkPayKoteiTanka` while directly inspecting bean-based data for free count and package flag. It is called from the `init()` method during screen initialization to set the `PAY_FLG` (有料フラグ) field in the data bean, which drives downstream UI rendering and business rules on the confirmation screen.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setPayFlg begins"])

    START --> GET_MURYO["Get muryoCnt = sendMessageLong(MLAD_MRYO_CNT)"]
    GET_MURYO --> GET_PACK["Get packFlg = sendMessageBoolean(PACK_KEI_FLG)"]
    GET_PACK --> CHK_PAY["CALL chkPayKoteiTanka(outputMap)"]

    CHK_PAY --> COND_PAY{"Fixed unit price exists?"}

    COND_PAY -->|"false: 固定単価なし (no fixed unit price)"| SET_FALSE_1["res = false"]
    SET_FALSE_1 --> END_RET(["return res (false: 無料)"])

    COND_PAY -->|"true: 固定単価あり (fixed unit price exists)"| COND_MURYO{"muryoCnt <= 0?"}

    COND_MURYO -->|"true: 無料数なし (no free items)"| SET_TRUE_1["res = true"]
    SET_TRUE_1 --> END_RET_TRUE(["return res (true: 有料)"])

    COND_MURYO -->|"false: 無料数あり (free items exist)"| COND_PACK{"packFlg?"}

    COND_PACK -->|"true: パック契約中 (package contract active)"| SET_TRUE_2["res = true"]
    SET_TRUE_2 --> END_RET_TRUE

    COND_PACK -->|"false: パック未契約 (no package contract)"| SET_FALSE_2["res = false"]
    SET_FALSE_2 --> END_RET
```

**CRITICAL — Constant Resolution:**
- `FUW01901SFConst.MLAD_MRYO_CNT = "メールアドレス無料数"` (Mail address free count — the count of free-tier mail add-on items)
- `FUW01901SFConst.PACK_KEI_FLG = "パック契約フラグ"` (Package contract flag — whether the customer has an active package plan)
- `X31CWebConst.DATABEAN_GET_VALUE` — standard data bean getter operation code
- `chkPayKoteiTanka` returns `true` if any pricing plan entry has a fixed unit price (`PPLAN_KOTEI_AMNT`) greater than 0 yen; `false` otherwise.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `bean` | `X31SDataBeanAccess` | The screen's data transfer object that carries business data between the presentation layer and this logic layer. It provides access to the mail address free count (`MLAD_MRYO_CNT` — メールアドレス無料数) and the package contract flag (`PACK_KEI_FLG` — パック契約フラグ) via `sendMessage` accessor methods. |
| 2 | `outputMap` | `HashMap<String, Object>` | A shared output map containing pre-populated pricing plan data. Specifically, it holds the parent map keyed by `FUSV005303SC`, which in turn contains the `EKK0601B001CBSMSG1LIST` (料金プラン固定単価 (オプション申込料金) 明細 — pricing plan fixed unit price (option application charge) details) list. This data is populated by prior CBS (Call Back Service) calls and is used by `chkPayKoteiTanka` to determine if a fixed unit price exists. |

**Instance fields / external state read:**
- None directly — all data is obtained via `bean.sendMessage*()` calls and the `outputMap` parameter.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `FUW01901SFLogic.chkPayKoteiTanka` | FUW01901SFLogic | - | Calls `chkPayKoteiTanka` in `FUW01901SFLogic` — inspects pricing plan fixed unit price data in `outputMap` to determine if any plan has a non-zero fixed charge |

### Called method analysis — `chkPayKoteiTanka` (lines 833–872):

This method performs an **R (Read)** operation on in-memory data structures:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `chkPayKoteiTanka` | FUW01901SFLogic | `EKK0601B001CBSMsg1List` (in-memory pricing plan data) | Reads the pricing plan fixed unit price details from `outputMap` under the `FUSV005303SC` key, iterates over the `EKK0601B001CBSMsg1List` entries, and checks if any `PPLAN_KOTEI_AMNT` (料金プラン固定金額 — pricing plan fixed amount) exceeds 0. Returns `true` if a non-zero fixed amount exists, `false` otherwise. |

No database or CBS calls originate from `setPayFlg` itself. The method is a pure logic decision layer that consumes pre-loaded data from the data bean and output map.

## 5. Dependency Trace

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

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Logic: `FUW01901SFLogic.init()` | `init()` -> `setPayFlg(bean, outputMap)` -> `chkPayKoteiTanka(outputMap)` | `chkPayKoteiTanka [R] EKK0601B001CBSMsg1List` |

**Context:** The `init()` method of the same class (`FUW01901SFLogic`) calls `setPayFlg` and stores its boolean result back into the data bean:
```java
bean.sendMessageBoolean(FUW01901SFConst.PAY_FLG, X31CWebConst.DATABEAN_SET_VALUE, setPayFlg(bean, outputMap));
```
This sets the `PAY_FLG` (有料フラグ — paid flag) field in the bean, which the screen uses to conditionally render billing-related UI elements and validation rules during the FTTH service confirmation process.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(muryoCnt retrieval)` (L788-789)

> Retrieves the count of free-tier items from the data bean. The `MLAD_MRYO_CNT` constant maps to `"メールアドレス無料数"` (mail address free count).

| # | Type | Code |
|---|------|------|
| 1 | SET | `boolean res = false;` // Initialize return value to free (false) |
| 2 | SET | `int muryoCnt = bean.sendMessageLong(FUW01901SFConst.MLAD_MRYO_CNT, X31CWebConst.DATABEAN_GET_VALUE).intValue();` // Get free item count [-> MLAD_MRYO_CNT="メールアドレス無料数"] |
| 3 | SET | `boolean packFlg = bean.sendMessageBoolean(FUW01901SFConst.PACK_KEI_FLG, X31CWebConst.DATABEAN_GET_VALUE);` // Get package contract flag [-> PACK_KEI_FLG="パック契約フラグ"] |

**Block 2** — [IF] `(chkPayKoteiTanka(outputMap))` "Fixed unit price exists?" (L792)

> Primary branching: delegates to `chkPayKoteiTanka` to determine if any pricing plan has a non-zero fixed unit price. This is the gate for all paid services.

**Block 2.1** — [IF-THEN] `(muryoCnt <= 0)` "Free items: none" (L793-795)

> If a fixed unit price exists AND there are zero free-tier items, the service is paid. This represents a standard paid subscription with no complimentary add-ons.

| # | Type | Code |
|---|------|------|
| 1 | SET | `res = true;` // 固定単価あり＆無料数なし — fixed price exists and no free items => paid (有料) |

**Block 2.2** — [ELSE] `(muryoCnt > 0)` "Free items exist" (L796-808)

> If a fixed unit price exists AND there are free-tier items, a further check on the package contract flag is required.

**Block 2.2.1** — [IF] `(packFlg)` "Package contract active?" (L799-802)

> If the customer has an active package contract (パック契約中), the service is classified as paid even though free items exist. This represents a bundled package plan where the fixed price covers the base service.

| # | Type | Code |
|---|------|------|
| 1 | SET | `res = true;` // 固定単価あり＆無料数あり＆パック契約中 — fixed price exists, free items exist, package contract active => paid (有料) |

**Block 2.2.2** — [ELSE] `(not packFlg)` "Package contract not active" (L803-806)

> If the customer does NOT have a package contract but has free-tier items alongside a fixed unit price, the service is classified as free. This represents an unbundled plan where the customer is on a free tier without a package commitment.

| # | Type | Code |
|---|------|------|
| 1 | SET | `res = false;` // 固定単価あり＆無料数あり＆パック未契約 — fixed price exists, free items exist, no package contract => free (無料) |

**Block 3** — [ELSE] `(chkPayKoteiTanka returns false)` "Fixed unit price not found" (L811-813)

> If no pricing plan entry has a non-zero fixed unit price (固定単価なし), the service is unconditionally free. This is the fallback for services with no billing obligation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `res = false;` // 固定単価なし — no fixed unit price => free (無料) |

**Block 4** — [RETURN] `(return res)` (L815)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return res;` // true: 有料 (paid), false: 無料（支払い金なし）(free, no payment) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PAY_FLG` | Field | Paid flag — the final determination of whether a payment obligation exists for the service order (true=paid, free=free) |
| `PACK_KEI_FLG` | Field | Package contract flag — indicates whether the customer has an active bundled package plan (パック契約) |
| `MLAD_MRYO_CNT` | Field | Mail address free count — the number of complimentary/free-tier mail add-on items in the service order (メールアドレス無料数) |
| `muryoCnt` | Field | Local variable — the resolved count of free items, derived from the mail address free count constant |
| `packFlg` | Field | Local variable — the resolved package contract flag value |
| `res` | Field | Local variable — the result flag being built up through conditional logic |
| `FUSV005303SC` | Constant | Parent data map key — used to extract pricing plan data from the output map. Represents a service component data container |
| `EKK0601B001CBSMSG1LIST` | Constant | Pricing plan fixed unit price detail key — maps to `"EKK0601B001CBSMsg1List"`. Contains the list of pricing plan line items with their fixed amounts (料金プラン固定単価 (オプション申込料金) 明細) |
| `PPLAN_KOTEI_AMNT` | Constant | Pricing plan fixed amount — maps to `"料金プラン固定金額"`. The fixed unit price yen amount for a pricing plan entry |
| `PPLAN_CHRG_TANI_CD` | Constant (from schema) | Pricing plan charge unit code — the unit code for pricing plan charges (料金プラン課金単位コード) |
| `chkPayKoteiTanka` | Method | Checks whether a fixed unit price exists in the pricing plan data. Returns true if any plan entry has a fixed amount > 0 yen |
| `FUW01901SF` | Module | FTTH (Fiber To The Home) service registration module — handles new FTTH broadband service sign-up workflows |
| `X31SDataBeanAccess` | Type | Data bean access class — the standard data transfer mechanism in the K-Opticom web framework for carrying screen data between layers |
| `EKK0601B001CBSMsg1List` | Entity | Pricing plan fixed unit price detail entity — carries structured pricing plan line item data including charge unit code, fixed amount, unit code name, and price type code |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband internet service offered by K-Opticom |
| パック契約 | Business term | Package contract — a bundled service plan where multiple services are combined under a single pricing arrangement |
| 固定単価 | Business term | Fixed unit price — a recurring fixed charge amount for a service plan, as opposed to usage-based or variable pricing |
| 有料 / 無料 | Business term | Paid / Free — the final billing classification for a service order. 有料 means the customer must pay; 無料 means no payment is required |
| DATABEAN_GET_VALUE | Constant | Standard operation code for reading a value from a data bean |
| DATABEAN_SET_VALUE | Constant | Standard operation code for setting a value in a data bean |