# Business Logic — JKKIntrInfoChgCfmCC.makeIntrWribAddYmd() [66 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKIntrInfoChgCfmCC` |
| Layer | CC/Common Component (`AbstractCommonComponent` base class, `com.fujitsu.futurity.bp.custom.common`) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKIntrInfoChgCfmCC.makeIntrWribAddYmd()

This method retrieves and processes the **introduction (referral) discount service agreement registration date** for the K-Opticom customer core system. It is responsible for identifying whether a customer has any active referral-based discount service contracts and, if so, determining the most recent registration date among them. The method operates as a **shared utility component** called during customer information change confirmation flows — specifically within the introduction code update process when a customer's referral information is being registered or changed.

The method implements a **query-and-validate routing pattern**. It first queries for the list of eligible discount service codes using a data item-based extraction service (`callEKK2391B003SC`), then retrieves the discount service agreement numbers (`callEKK0481B001SC`). For each agreement number, it executes a service agreement consent check (`callEKK0451A010SC`) to validate the agreement status. It then filters results based on whether the service code matches an introduction discount service code and whether the service status excludes terminated (`WRIB_SVC_KEI_STAT_910`) and expired/invalid (`WRIB_SVC_KEI_STAT_920`) states. If valid agreements are found, it returns the maximum (most recent) registration date; otherwise, it clears the field and returns `false`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["makeIntrWribAddYmd"])

    START --> INIT["Initialize: wribCdList=null, wribSvcKeiList=null, wribAddYmdList=[]"]
    INIT --> FETCH_CD["callEKK2391B003SC - Fetch discount service code list"]
    FETCH_CD --> FETCH_SVC["callEKK0481B001SC - Fetch discount service agreement number list"]
    FETCH_SVC --> FOR_CHECK{"wribSvcKeiList.size > 0?"}

    FOR_CHECK -->|Yes| FOR_BODY["Loop: i = 0 to size-1"]
    FOR_BODY --> GET_KEY["Get wribSvcKei from wribSvcKeiList[i]"]
    GET_KEY --> PUT_MAP["workMap.put('wrib_svc_kei_no', wribSvcKei)"]
    PUT_MAP --> CONSENT["callEKK0451A010SC - Execute discount service agreement consent"]
    CONSENT --> EXTRACT["Extract wribSvcCd and wribSvcKeiStat from workMap"]
    EXTRACT --> IF_CHECK{"wribCdList.contains(wribSvcCd) AND<br/>wribSvcKeiStat != '910' AND<br/>wribSvcKeiStat != '920'"}

    IF_CHECK -->|Yes| ADD_YMD["Get wribAddYmd from workMap, add to wribAddYmdList"]
    ADD_YMD --> FOR_NEXT["i++"]
    FOR_NEXT --> FOR_CHECK

    IF_CHECK -->|No| FOR_NEXT

    FOR_CHECK -->|No| FINAL_CHECK{"wribAddYmdList.isEmpty?"}

    FINAL_CHECK -->|Yes| DEFAULT["workMap.put('intr_cmp_wribsvk_add_ymd', '')<br/>return false"]
    FINAL_CHECK -->|No| MAX["checkWribMaxYmd - Get maximum date from list"]
    MAX --> PUT_MAX["workMap.put('intr_cmp_wribsvk_add_ymd', maxYmd)"]
    PUT_MAX --> RETURN_TRUE["return true"]

    RETURN_TRUE --> END(["End"])
    DEFAULT --> END
```

**CRITICAL — Constant Resolution:**

| Constant | Value | Business Meaning | Source Location |
|----------|-------|-----------------|-----------------|
| `WRIB_SVC_KEI_STAT_910` | Not resolved (external JAR) | Discount service agreement status: terminated/cancelled — excluded from valid agreements | External library `WRIB_SVC_KEI_STAT` constants |
| `WRIB_SVC_KEI_STAT_920` | Not resolved (external JAR) | Discount service agreement status: expired/invalid — excluded from valid agreements | External library `WRIB_SVC_KEI_STAT` constants |
| `kei_ido_kh_result` | `"kei_ido_kh_result"` | Service detail movement history result flag | `JKKKeiIdoKhCheckConstCC.java:59` |

> **Note:** The constants `WRIB_SVC_KEI_STAT_910` and `WRIB_SVC_KEI_STAT_920` are defined in an external library (not present in the source tree) and could not be resolved. They represent service agreement state codes that exclude non-active agreements from the discount eligibility check.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying screen input data — contains the data item extraction settings that determine which discount service codes to query. Used to pass user-specified selection criteria for the introduction discount service code lookup. |
| 2 | `handle` | `SessionHandle` | The session context handle providing database connection and transaction scope. Used to maintain consistency across multiple service component calls within the same business transaction. |
| 3 | `workMap` | `HashMap<String, Object>` | The shared work data map acting as the inter-method data bus. Used to pass the discount service agreement number into each consent call, receive the consent result (service code, status, registration date), and accumulate the final result (`intr_cmp_wribsvk_add_ymd`). |
| 4 | `inMap` | `HashMap<String, Object>` | The input parameter map used as an auxiliary data carrier passed through to service components. May contain session-scoped configuration or additional business context needed by downstream SC calls. |

**Instance fields read:** None. This method is stateless — it reads no instance fields.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKIntrInfoChgCfmCC.callEKK2391B003SC` | EKK2391B003SC | - | Reads discount service code list based on data item extraction settings (e.g., filters for introduction discount service codes) |
| R | `JKKIntrInfoChgCfmCC.callEKK0481B001SC` | EKK0481B001SC | - | Reads discount service agreement number list — retrieves all service agreement numbers associated with the customer |
| R | `JKKIntrInfoChgCfmCC.callEKK0451A010SC` | EKK0451A010SC | - | Executes discount service agreement consent check — validates a specific service agreement and populates consent result data (service code, status, registration date) in workMap |
| R | `JKKIntrInfoChgCfmCC.checkWribMaxYmd` | - | - | Returns the maximum (latest) date value from a list of registration dates |

**Classification rationale:**
- `callEKK2391B003SC`: SC pattern — queries a list of discount service codes, used as the eligible introduction discount filter set.
- `callEKK0481B001SC`: SC pattern — reads customer's service agreement numbers for discount services.
- `callEKK0451A010SC`: SC pattern — performs agreement consent lookup for each service agreement, returning consent result data.
- `checkWribMaxYmd`: Internal helper — performs a simple max-date operation over the collected registration dates.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS:JKKIntrInfoChgCfmCC.changeSvoaSwk | `changeSvoaSwk` → `makeIntrWribAddYmd` | `callEKK0451A010SC [R]`, `checkWribMaxYmd [R]` |
| 2 | CBS:JKKIntrInfoChgCfmCC.insertSvoaSwk | `insertSvoaSwk` → `makeIntrWribAddYmd` | `callEKK0451A010SC [R]`, `checkWribMaxYmd [R]` |

**Terminal operations from this method:**
- `checkWribMaxYmd` [R] — Internal: returns max date from list
- `callEKK0451A010SC` [R] — Service: discount service agreement consent
- `callEKK0481B001SC` [R] — Service: discount service agreement number list
- `callEKK2391B003SC` [R] — Service: discount service code list (introduction)

## 6. Per-Branch Detail Blocks

**Block 1** — VARIABLE DECLARATION (L2839)

> Initialize local variables for service code list, service agreement list, and date accumulator.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribCdList = null` |
| 2 | SET | `wribSvcKeiList = null` |
| 3 | SET | `wribAddYmdList = new ArrayList<String>()` — Initialize empty date accumulator list |

**Block 2** — FETCH INTRO DISCOUNT SERVICE CODES [ANK-1756-00-00] (L2847)

> **ANK-1756-00-00 (v7.00.01):** Replaced the original `callEKK2311B004SC` call (DEL START/END, L2842-2844) with `callEKK2391B003SC` to change the data extraction basis for fetching discount service codes.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `wribCdList = callEKK2391B003SC(param, handle, workMap, inMap)` | [ANK-1756-00-00 ADD] Fetch introduction discount service code list based on data item extraction settings. This set of codes represents all valid introduction discount service types. |

**Block 3** — FETCH DISCOUNT SERVICE AGREEMENT NUMBERS (L2850)

> Retrieve the list of discount service agreement numbers (contract line item identifiers) associated with the customer.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `wribSvcKeiList = callEKK0481B001SC(param, handle, workMap, inMap)` | Fetch discount service agreement number list — retrieves all service agreement numbers for discount services the customer holds. |

**Block 4** — FOR LOOP OVER SERVICE AGREEMENT NUMBERS (L2852)

> Iterate over each discount service agreement number to validate consent and collect registration dates.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `i = 0` | Loop counter initialized to 0 |
| 2 | COND | `i < wribSvcKeiList.size()` | Check if more agreements to process |
| 3 | INC | `i++` | Increment loop counter (executed at end of each iteration) |

**Block 4.1** — WITHIN LOOP: PROCESS SINGLE AGREEMENT (L2854-2878)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `wribSvcKei = wribSvcKeiList.get(i)` — Get the current agreement number from the list |
| 2 | EXEC | `workMap.put("wrib_svc_kei_no", wribSvcKei)` — Put the agreement number into workMap for the consent call |
| 3 | CALL | `callEKK0451A010SC(param, handle, workMap, inMap)` | Execute discount service agreement consent check. This validates the specific service agreement and populates `workMap` with result fields: `wrib_svc_cd` (discount service code), `wrib_svc_kei_stat` (agreement status), and `wrib_add_ymd` (registration date). |
| 4 | SET | `wribSvcCd = (String) workMap.get("wrib_svc_cd")` — Extract the discount service code from consent result |
| 5 | SET | `wribSvcKeiStat = (String) workMap.get("wrib_svc_kei_stat")` — Extract the agreement status from consent result |

**Block 4.1.1** — IF [ELIGIBLE INTRO DISCOUNT] (L2874)

> Check if this agreement qualifies as a valid introduction discount. Three conditions must ALL be true: (1) the service code is in the introduction discount list, (2) the status is NOT the terminated status (`WRIB_SVC_KEI_STAT_910`), and (3) the status is NOT the expired status (`WRIB_SVC_KEI_STAT_920`). This replaces a stricter v7.00.03 check (L2877-2878) that required exact status match to `WRIB_SVC_KEI_STAT_010`.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | COND | `wribCdList.contains(wribSvcCd)` | Is the service code in the introduction discount code list? |
| 2 | COND | `wribSvcKeiStat.compareTo(WRIB_SVC_KEI_STAT_910) != 0` [-> WRIB_SVC_KEI_STAT_910] | Status is NOT terminated/cancelled |
| 3 | COND | `wribSvcKeiStat.compareTo(WRIB_SVC_KEI_STAT_920) != 0` [-> WRIB_SVC_KEI_STAT_920] | Status is NOT expired/invalid |
| 4 | SET | `wribAddYmd = (String) workMap.get("wrib_add_ymd")` — Get the registration date from consent result |
| 5 | EXEC | `wribAddYmdList.add(wribAddYmd)` — Add valid registration date to the accumulator list |

**Block 5** — FINAL CHECK [NO VALID AGREEMENTS] (L2881)

> After processing all agreements, check if any valid introduction discount registration dates were collected.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | COND | `!wribAddYmdList.isEmpty()` | Check if any valid introduction discount dates were accumulated |

**Block 5.1** — ELSE [NO VALID INTRO DISCOUNTS FOUND] (L2891)

> No valid introduction discount agreements were found. Clear the result field and return `false`.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `workMap.put("intr_cmp_wribsvk_add_ymd", "")` — Initialize the introduction discount service addition date field in workMap (Japanese: 作業マップ(wrib_add_ymd)を初期化) |
| 2 | RETURN | `return false` | No introduction discount service agreement exists |

**Block 5.2** — THEN [VALID INTRO DISCOUNTS FOUND] (L2884)

> Valid introduction discount agreements were found. Compute the maximum date and store it in workMap.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `maxYmd = checkWribMaxYmd(wribAddYmdList)` | Get the maximum (most recent) registration date from the accumulated list |
| 2 | EXEC | `workMap.put("intr_cmp_wribsvk_add_ymd", maxYmd)` — Store the result date in workMap under the key `intr_cmp_wribsvk_add_ymd` (introduction comparison discount service addition date) |
| 3 | RETURN | `return true` | An introduction discount service agreement exists |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrib` | Abbreviation | Short for Japanese 割引 (waribiki) — discount. Used throughout field names to denote discount-related data. |
| `wrib_svc_cd` | Field | Discount service code — the type/category code identifying a specific discount service offering. |
| `wrib_svc_kei_no` | Field | Discount service agreement number — internal identifier for a discount service contract line item. |
| `wrib_svc_kei_stat` | Field | Discount service agreement status — code indicating the current state of a discount service contract (active, terminated, expired, etc.). |
| `wrib_add_ymd` | Field | Discount service registration date — the date (year/month/day) when a discount service contract was registered. |
| `intr_cmp_wribsvk_add_ymd` | Field | Introduction comparison discount service addition date — the final computed result field storing the most recent introduction discount registration date. |
| `wribCdList` | Field | Discount service code list — the list of introduction discount service codes fetched via SC, used as a filter set. |
| `wribSvcKeiList` | Field | Discount service agreement number list — the list of all discount service agreement numbers for the customer. |
| `wribAddYmdList` | Field | Discount registration date accumulator — collects valid introduction discount registration dates for max-date computation. |
| `WRIB_SVC_KEI_STAT_910` | Constant | Discount service agreement status code for terminated/cancelled agreements — these are excluded from eligibility. (Exact value in external library.) |
| `WRIB_SVC_KEI_STAT_920` | Constant | Discount service agreement status code for expired/invalid agreements — these are excluded from eligibility. (Exact value in external library.) |
| `WRIB_SVC_KEI_STAT_010` | Constant | Discount service agreement status code for active agreements. Removed from the v7.00.04 change (the condition was changed from requiring exact match to this value to excluding only 910/920). |
| EKK2391B003SC | SC Code | Service Component: Discount service code list extraction by data item settings — queries which discount service codes are eligible based on screen/data item configuration. |
| EKK0481B001SC | SC Code | Service Component: Discount service agreement number list query — retrieves all discount service agreement numbers for a customer. |
| EKK0451A010SC | SC Code | Service Component: Discount service agreement consent check — validates a specific discount service agreement and returns consent result data (service code, status, registration date). |
| callEKK2311B004SC | SC Code | (Deprecated, deleted in ANK-1756-00-00 v7.00.01) — Previous implementation for fetching introduction discount service codes, replaced by `callEKK2391B003SC`. |
| ANK-1756-00-00 | Project/Ticket | Introduction code support work — a project series adding introduction code functionality to the system, including v7.00.01 (code replacement), v7.00.02 (support continuation), and v7.00.04 (service status check change). |
| 紹介割引 (Shoukai Waribiki) | Japanese term | Introduction (referral) discount — a discount offered to customers referred by existing customers through an introduction code system. |
| サービス契約合意確認 (Saabisu Keiyaku Goui Kakunin) | Japanese term | Service agreement consent check — the validation process that confirms a service agreement exists and is valid. |
| workMap | Technical term | Shared work data map — a HashMap used as a data bus between methods within the same transaction context, carrying request inputs and responses. |
| consent result | Business term | The outcome of a service agreement consent check, including service code, agreement status, and registration date. |
