# Business Logic — JKKKyoseiDslRunCC.kappu_cancel() [191 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKKyoseiDslRunCC` |
| Layer | CC / Common Component (Shared business logic bridge) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKKyoseiDslRunCC.kappu_cancel()

This method orchestrates the **cancellation of rental service contracts** (割賦契約 — "installment contract") within a telecommunications service contract management system. It serves as the centralized cancellation coordinator that ensures all prerequisites are satisfied before executing a cancellation workflow across multiple dependent services.

The method follows a **gate-and-dispatch** design pattern. It first verifies that rental service contracts exist and are in a cancellable state (ready or under review — statuses `010` or `020`). Then, before proceeding with any cancellation, it validates delivery (配送) information to confirm that either no delivery has occurred, or the delivery is in an accepted/completed (受付済) or stopped (中止) state — thereby preventing cancellation of already-delivered services that should proceed through a different termination flow.

When all prerequisites pass, the method invokes the rental contract cancellation service (`callKAPPUSC` with `EKK2541C170`). If a rental contract was successfully cancelled, it additionally handles **temporary charge cancellation** (一時金取消) — a financial reversal workflow that either modifies pending temporary charges (status `0` — unfinished) or retrieves and modifies contract-level temporary charges (status `1` — completed).

The method is a **shared utility** called by `kktkSvcKei_KyoseiDsl()`, which is the service contract modification DSL entry point. It acts as a gatekeeper within a larger service contract change operation, ensuring that any associated rental contracts and their financial obligations are cleanly cancelled before the broader modification proceeds.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["kappu_cancel starts"])
    
    START --> CALL1["CALL callKAPPUSC EKK2541B001 - Retrieve rental contract list"]
    
    CALL1 --> CHECK1{callKAPPUSC error}
    CHECK1 -- Yes --> RETURN_ERR1["Return statusCode"]
    CHECK1 -- No --> GET_LIST["GET resultHash EKK2541B001 ArrayList"]
    
    GET_LIST --> CHECK_EMPTY{rental list empty}
    CHECK_EMPTY -- Yes --> RETURN0_A["Return 0 no rental contracts"]
    CHECK_EMPTY -- No --> EXTRACT_IDS["EXTRACT svcKeiNo and kktkSvcKeiNo"]
    
    EXTRACT_IDS --> BUILD_HAISO["BUILD haisoStatList 001 002 003 004 005"]
    
    BUILD_HAISO --> CALL_HAISO["CALL JKKBpCommon searchHaisoInfo"]
    
    CALL_HAISO --> EXTRACT_DEL["EXTRACT CAANMsg delivery records"]
    
    EXTRACT_DEL --> INIT_FLAGS["INIT isUkzumiOrStp false isNoRecord true"]
    
    INIT_FLAGS --> LOOP_START{Iterate delivery records}
    
    LOOP_START --> FIND_MATCH{kkSvcKeiNo match}
    FIND_MATCH -- No --> LOOP_NEXT{More records}
    FIND_MATCH -- Yes --> SET_NORECORD["SET isNoRecord false"]
    
    SET_NORECORD --> CHECK_STATUS{haisoStat is 001 or 005}
    CHECK_STATUS -- Yes --> SET_UKZUMI["SET isUkzumiOrStp true BREAK"]
    CHECK_STATUS -- No --> LOOP_NEXT
    SET_UKZUMI --> LOOP_NEXT
    
    LOOP_NEXT -- Yes --> LOOP_START
    LOOP_NEXT -- No --> CHECK_FINAL{valid delivery found}
    
    CHECK_FINAL -- Yes --> RETURN0_B["Return 0 no valid delivery"]
    CHECK_FINAL -- No --> LOOP_CAPITAL["LOOP through rental contracts"]
    
    LOOP_CAPITAL --> GET_CAPSTAT["GET kapStat from contract"]
    
    GET_CAPSTAT --> CHECK_CAPSTAT{kapStat is 010 or 020}
    CHECK_CAPSTAT -- No --> RETURN0_C["Return 0 not ready cancelable"]
    CHECK_CAPSTAT -- Yes --> SAVE_CAP["PUT tmp hash resultHash"]
    
    SAVE_CAP --> CALL_CANCEL["CALL callKAPPUSC EKK2541C170 Cancel rental"]
    
    CALL_CANCEL --> CHECK_CANCEL{cancel error}
    CHECK_CANCEL -- Yes --> RETURN_ERR2["Return statusCode"]
    CHECK_CANCEL -- No --> SET_FLAG["SET isCancelKapKei true"]
    
    SET_FLAG --> CHECK_FLAG{isCancelKapKei true}
    CHECK_FLAG -- No --> RETURN_STATUS["Return statusCode"]
    CHECK_FLAG -- Yes --> CALL_TEMP_LIST["CALL callEKK1021B003SC temp charge list"]
    
    CALL_TEMP_LIST --> CHECK_TEMP_EMPTY{temp charges empty}
    CHECK_TEMP_EMPTY -- Yes --> RETURN0_D["Return 0 no temporary charges"]
    CHECK_TEMP_EMPTY -- No --> LOOP_TEMP["LOOP through temp charge list"]
    
    LOOP_TEMP --> GET_FINSTAT["GET finStatCd"]
    
    GET_FINSTAT --> CHECK_FINSTAT{finStatCd is 0 uncompleted}
    CHECK_FINSTAT -- Yes --> CALL_TEMP_MOD["CALL callEKK1021C010SC modify temp charge"]
    CHECK_FINSTAT -- No --> CHECK_FINSTAT2{finStatCd is 1 completed}
    
    CHECK_FINSTAT2 -- No --> LOOP_TEMP_NEXT{More records}
    CHECK_FINSTAT2 -- Yes --> CALL_CONTRACT_LIST["CALL callEKK1051B001SC contract charge list"]
    
    CALL_CONTRACT_LIST --> CHECK_CONTRACT_EMPTY{contract charges empty}
    CHECK_CONTRACT_EMPTY -- Yes --> RETURN0_E["Return 0 no contract charges"]
    CHECK_CONTRACT_EMPTY -- No --> GET_FIRST["GET first element"]
    
    GET_FIRST --> SAVE_CONTRACT["PUT tmp hash resultHash"]
    
    SAVE_CONTRACT --> CALL_CONTRACT_MOD["CALL callEKK1051C020SC modify contract charge"]
    
    CALL_TEMP_MOD --> CHECK_TEMP_MOD{temp mod error}
    CHECK_TEMP_MOD -- Yes --> RETURN_ERR3["Return statusCode"]
    CHECK_TEMP_MOD -- No --> LOOP_TEMP_NEXT
    
    CALL_CONTRACT_MOD --> CHECK_CONTRACT_MOD{contract mod error}
    CHECK_CONTRACT_MOD -- Yes --> RETURN_ERR4["Return statusCode"]
    CHECK_CONTRACT_MOD -- No --> LOOP_TEMP_NEXT
    
    LOOP_TEMP_NEXT -- Yes --> LOOP_TEMP
    LOOP_TEMP_NEXT -- No --> RETURN_STATUS
    
    RETURN_ERR1 --> END_NODE(["End"])
    RETURN0_A --> END_NODE
    RETURN0_B --> END_NODE
    RETURN0_C --> END_NODE
    RETURN0_D --> END_NODE
    RETURN0_E --> END_NODE
    RETURN_ERR2 --> END_NODE
    RETURN_ERR3 --> END_NODE
    RETURN_ERR4 --> END_NODE
    RETURN_STATUS --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing the transactional context and connection for all SC (Service Component) calls within this cancellation operation. |
| 2 | `param` | `IRequestParameterReadWrite` | Request/response data carrier. Used to pass the `KKSV016701CC` data map (service contract forced cancellation product mapping) and to receive results from SC calls. Contains the business payload that flows through the entire cancellation chain. |
| 3 | `requestParam` | `HashMap<String, Object>` | Input parameters hashmap carrying caller-provided data such as the service contract number (`svc_kei_no`) and rental contract details. Used as context for the SC method calls. |
| 4 | `resultHash` | `HashMap<String, Object>` | Output result container. SC calls store their results keyed by template ID (e.g., `EKK2541B001`, `EKK2541C170`, `EKK1021B003`). The method reads intermediate results from this map and stores `tmp` entries for downstream consumers. |

**External state / instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `HAISO_STAT_UK_ZM` | `String` | Local constant for delivery status "Accepted" (`"001"`). Used to identify delivery records that have been accepted/confirmed. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callKAPPUSC` (TEMPLATE_ID_EKK2541B001) | EKK2541B001SC | KK_T_KAPPU (rental contract table) | Retrieve rental contract list by equipment service contract number — reads active installment contracts to determine cancellation eligibility |
| R | `JKKBpCommon.searchHaisoInfo` | EDK0011B080SC | KK_T_HAISO (delivery information table) | Search delivery information for the service contract line by multiple delivery statuses (accepted, instructed, shipped, completed, stopped) |
| R | `callKAPPUSC` (TEMPLATE_ID_EKK2541C170) | EKK2541C170SC | KK_T_KAPPU (rental contract table) | Cancel rental contract — invokes the rental contract cancellation SIF to mark the contract as cancelled |
| R | `callEKK1021B003SC` | EKK1021B003SC | KK_T_ITCHI_KIN (temporary charge table) | Retrieve temporary charge list by application detail number — fetches all pending temporary charges associated with the cancellation |
| R | `callEKK1021C010SC` | EKK1021C010SC | KK_T_ITCHI_KIN (temporary charge table) | Modify temporary charge — updates a pending (unfinished) temporary charge to cancel it |
| R | `callEKK1051B001SC` | EKK1051B001SC | KK_T_ITCHI_KIN (temporary charge table) | Retrieve contract temporary charge list — fetches contract-level temporary charges linked to completed temporary charges |
| R | `callEKK1051C020SC` | EKK1051C020SC | KK_T_ITCHI_KIN (temporary charge table) | Modify contract temporary charge — updates a contract-level temporary charge to cancel it |

### Detailed CRUD mapping:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callKAPPUSC(EKK2541B001)` | EKK2541B001SC | KK_T_KAPPU | **R — Retrieve rental contract list** (割賦契約一覧照会) — Fetches all rental/installment service contracts associated with the equipment-provided service contract number. Results stored in `resultHash` under key `"EKK2541B001"`. |
| R | `searchHaisoInfo` | EDK0011B080SC | KK_T_HAISO | **R — Search delivery information** (配送情報照会処理) — Queries delivery records for the service contract line across 5 delivery statuses: accepted (`001`), instructed (`002`), shipped (`003`), completed (`004`), stopped (`005`). Results stored in `resultHash` under key `"EDK0011B080"` as `CAANMsg[]` array. |
| R | `callKAPPUSC(EKK2541C170)` | EKK2541C170SC | KK_T_KAPPU | **R — Cancel rental contract** (割賦契約キャンセル) — Invokes the SIF to cancel each rental contract that has status `010` (ready) or `020` (under review). This is the primary cancellation action. |
| R | `callEKK1021B003SC` | EKK1021B003SC | KK_T_ITCHI_KIN | **R — Retrieve temporary charge list** (一時金設定一覧照会) — After rental contract cancellation, fetches all temporary charges (deposit/installment fees) linked to the application. Results stored under key `"EKK1021B003"`. |
| R | `callEKK1021C010SC` | EKK1021C010SC | KK_T_ITCHI_KIN | **U — Modify temporary charge** (一時金設定変更実行処理) — For temporary charges with unfinished status (`finStatCd = "0"`), updates/cancels the charge. This reverses pending financial obligations. |
| R | `callEKK1051B001SC` | EKK1051B001SC | KK_T_ITCHI_KIN | **R — Retrieve contract temporary charge list** (契約一時金一覧照会) — For completed temporary charges (`finStatCd = "1"`), fetches linked contract-level temporary charges. Results stored under key `"EKK1051B001"`. |
| R | `callEKK1051C020SC` | EKK1051C020SC | KK_T_ITCHI_KIN | **U — Modify contract temporary charge** (契約一時金変更実行処理) — Updates the first contract-level temporary charge to cancel it. This completes the financial reversal for already-processed charges. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKKyoseiDslRunCC.kktkSvcKei_KyoseiDsl()` | `kktkSvcKei_KyoseiDsl()` -> `kappu_cancel()` | `callKAPPUSC [R] KK_T_KAPPU`, `searchHaisoInfo [R] KK_T_HAISO`, `callEKK1021C010SC [U] KK_T_ITCHI_KIN`, `callEKK1051C020SC [U] KK_T_ITCHI_KIN` |

**Call chain context:** `kktkSvcKei_KyoseiDsl()` is the service contract line modification DSL entry point within `JKKKyoseiDslRunCC`. It coordinates the broader service contract change operation, and `kappu_cancel()` is called as a sub-step to handle rental contract cancellation within that larger workflow.

**Terminal operations reached from this method:**

| Terminal Call | CRUD | Entity | Description |
|---------------|------|--------|-------------|
| `callEKK1051C020SC` | U | KK_T_ITCHI_KIN | Modify contract temporary charge |
| `callEKK1051B001SC` | R | KK_T_ITCHI_KIN | Retrieve contract temporary charge list |
| `callEKK1021C010SC` | U | KK_T_ITCHI_KIN | Modify temporary charge |
| `callEKK1021B003SC` | R | KK_T_ITCHI_KIN | Retrieve temporary charge list |
| `callKAPPUSC(EKK2541C170)` | R | KK_T_KAPPU | Cancel rental contract |
| `callKAPPUSC(EKK2541B001)` | R | KK_T_KAPPU | Retrieve rental contract list |
| `searchHaisoInfo` | R | KK_T_HAISO | Search delivery information |

## 6. Per-Branch Detail Blocks

**Block 1** — [INIT] Variable declarations (L7626)

> Initialize the return code variable.

| # | Type | Code |
|---|------|------|
| 1 | SET | `statusCode = 0` // Initialize return code |

**Block 2** — [CALL] Retrieve rental contract list (L7630)

> Calls the rental contract list retrieval SC. This is the first operational step — fetch all rental (installment) service contracts for the equipment service contract number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `callKAPPUSC(param, handle, requestParam, resultHash, TEMPLATE_ID_EKK2541B001)` // TEMPLATE_ID_EKK2541B001 = "EKK2541B001" — Rental contract list retrieval (割賦契約一覧照会) |

**Block 3** — [IF] Error check after rental list call (L7631)

> If the SC call fails, return the error code immediately.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` // Early return on SC error |

**Block 4** — [GET] Extract rental contract list (L7635)

> Retrieve the ArrayList from resultHash.

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK2541B001HashList = (ArrayList<HashMap<String, Object>>)resultHash.get(TEMPLATE_ID_EKK2541B001)` // Cast to ArrayList of rental contract hashes |

**Block 5** — [IF] Empty rental list check (L7638)

> If no rental contracts exist, there is nothing to cancel. The method exits cleanly.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (eKK2541B001HashList.size() == 0)` |
| 2 | RETURN | `return 0` // No rental contracts — nothing to cancel |

**Block 6** — [GET] Extract service contract numbers (L7642–7645)

> Extract the service contract number (`svcKeiNo`) and the rental service contract number (`kktkSvcKeiNo`) from previous resultHash entries. These are used to correlate delivery records with the specific rental contract.

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK0081A010Hash = (HashMap<String, Object>)resultHash.get(TEMPLATE_ID_EKK0081A010)` // Previous result — service contract data |
| 2 | GET | `svcKeiNo = (String)eKK0081A010Hash.get(EKK0081A010CBSMsg1List.SVC_KEI_NO)` // Service contract number |
| 3 | GET | `eKK0321A010Hash = (HashMap<String, Object>)resultHash.get(TEMPLATE_ID_EKK0321A010)` // Previous result — rental contract data |
| 4 | GET | `kktkSvcKeiNo = (String)eKK0321A010Hash.get(EKK0321A010CBSMsg1List.KKTK_SVC_KEI_NO)` // Rental/equipment service contract number |

**Block 7** — [BUILD] Build delivery status filter list (L7648–7655)

> Construct a list of delivery statuses to query. Per the comment (配信用情報一覧照会処理を実施 — execute delivery information list retrieval processing), this searches for deliveries in statuses: accepted (受付済), instructed (指示済), shipped (出荷済), completed (完了済), and stopped (中止).

| # | Type | Code |
|---|------|------|
| 1 | SET | `haisoStatList = new ArrayList<String>()` // Create delivery status list |
| 2 | EXEC | `haisoStatList.add(HAISO_STAT_UK_ZM)` // HAISO_STAT_UK_ZM = "001" (Accepted) 受付済の情報を探索 |
| 3 | EXEC | `haisoStatList.add(JKKDslRun.HAISO_STAT_SJ_ZM)` // HAISO_STAT_SJ_ZM = "002" (Instructed) ロット2IT1-2012-0001946対応 |
| 4 | EXEC | `haisoStatList.add(JKKDslRun.HAISO_STAT_SK_ZM)` // HAISO_STAT_SK_ZM = "003" (Shipped) ロット2IT1-2012-0001946対応 |
| 5 | EXEC | `haisoStatList.add(JKKDslRun.HAISO_STAT_KNRYO)` // HAISO_STAT_KNRYO = "004" (Completed) ロット2IT1-2012-0001946対応 |
| 6 | EXEC | `haisoStatList.add(JKKDslRun.HAISO_STAT_STP)` // HAISO_STAT_STP = "005" (Stopped) 中止の情報を探索 |

**Block 8** — [CALL] Search delivery information (L7657)

> Query delivery records for the service contract line. Uses `JKKBpCommon.searchHaisoInfo` with the status filter built in Block 7. Results stored in `eDK0011B080Hash`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKBpCommon.searchHaisoInfo(param, handle, svcKeiNo, null, null, null, haisoStatList, eDK0011B080Hash, KKSV016701CC)` // Search delivery info by service contract number and status list |

**Block 9** — [GET] Extract delivery records (L7660)

> Cast the result from the hash into a `CAANMsg[]` array of delivery records.

| # | Type | Code |
|---|------|------|
| 1 | GET | `eDK0011B080CBSMSG1list = (CAANMsg[])eDK0011B080Hash.get(EDK0011B080CBSMsg.EDK0011B080CBSMSG1LIST)` // Delivery message array |

**Block 10** — [INIT] Initialize delivery check flags (L7662–7664)

> Set up boolean flags for the delivery record iteration. `isUkzumiOrStp` tracks whether a delivered/stopped record was found. `isNoRecord` starts true and is set false when a matching record is found.

| # | Type | Code |
|---|------|------|
| 1 | SET | `isUkzumiOrStp = false` // Has accepted or stopped delivery |
| 2 | SET | `isNoRecord = true` // Flag: no matching record found yet |

**Block 11** — [FOR] Iterate delivery records (L7666–7679)

> Loop through all delivery records to find one that matches the rental service contract number (`kkSvcKeiNo`). If a matching record is found, check if its delivery status is "accepted" (受付済 = `001`) or "stopped" (中止 = `005`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` // Loop counter |
| 2 | EXEC | `null != eDK0011B080CBSMSG1list && i < eDK0011B080CBSMSG1list.length` // Loop condition |
| 3 | INC | `i++` |

**Block 11.1** — [GET] Extract matching rental contract number (L7669)

| # | Type | Code |
|---|------|------|
| 1 | GET | `tmpKktkSvcKeiNo = eDK0011B080CBSMSG1list[i].getString(EDK0011B080CBSMsg1List.KKTK_SVC_KEI_NO)` // Equipment service contract number from delivery record |

**Block 11.2** — [IF] Match check (L7670)

> Compare the delivery record's rental contract number with the expected value.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (kktkSvcKeiNo.equals(tmpKktkSvcKeiNo))` |
| 2 | SET | `isNoRecord = false` // Found a matching delivery record |

**Block 11.3** — [GET] Extract delivery status (L7672)

| # | Type | Code |
|---|------|------|
| 1 | GET | `haisoStat = eDK0011B080CBSMSG1list[i].getString(EDK0011B080CBSMsg1List.HAISO_STAT)` // Delivery status string |

**Block 11.4** — [IF] Accepted or stopped check (L7673)

> Check if the delivery status is "accepted" (`001`) or "stopped" (`005`). These are the states where cancellation is valid.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (HAISO_STAT_UK_ZM.equals(haisoStat) || JKKDslRun.HAISO_STAT_STP.equals(haisoStat))` // `001` = 受付済 (Accepted) OR `005` = 中止 (Stopped) [HAISO_STAT_UK_ZM="001", HAISO_STAT_STP="005"] |
| 2 | SET | `isUkzumiOrStp = true` // Mark that cancellation is valid |
| 3 | EXEC | `break` // Exit loop — found valid delivery state |

**Block 12** — [IF] Delivery validation check (L7683)

> Per the comment (配送データがないか、出荷指示前のデータが存在する場合はOKで、それ以外は終了): If a matching delivery record exists AND it is NOT in an accepted/stopped state, the method returns 0 (stops processing). This is the gate — deliveries in "instructed" (`002`), "shipped" (`003`), or "completed" (`004`) states that are NOT "stopped" will cause cancellation to abort.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (!isNoRecord && !isUkzumiOrStp)` // Matching record found but NOT accepted/stopped |
| 2 | RETURN | `return 0` // Processing aborted — delivery is in a state that prevents cancellation |

**Block 13** — [INIT] Initialize cancellation flag (L7687–7689)

> ANK-1306-00-00 2013/01/23 ADD. Tracks whether any rental contract was cancelled, to determine if temporary charge cancellation is needed.

| # | Type | Code |
|---|------|------|
| 1 | SET | `isCancelKapKei = false` // Flag: was any rental contract cancelled? |

**Block 14** — [FOR] Iterate rental contracts for cancellation (L7691–7735)

> Loop through all rental contracts returned in Block 4. For each contract, verify it is in a cancellable state (ready or under review) and then cancel it.

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` // Loop counter |
| 2 | EXEC | `i < eKK2541B001HashList.size()` // Loop condition |
| 3 | INC | `i++` |

**Block 14.1** — [GET] Extract rental contract hash (L7693)

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK2541B001Hash = eKK2541B001HashList.get(i)` // Current rental contract data |

**Block 14.2** — [GET] Extract rental contract status (L7695)

| # | Type | Code |
|---|------|------|
| 1 | GET | `kapStat = (String)eKK2541B001Hash.get(EKK2541B001CBSMsg1List.KAP_KEI_STAT)` // Rental contract status |

**Block 14.3** — [IF] Cancellable state check (L7698)

> Per the comment (受付済、または、照 miru 済でない場合は処理しない — do not process if not ready or under review). The contract must be in status `010` (受付済 — Ready) or `020` (照 miru 済 — Under review) to be cancelled. Per the 2013-01-06 internal fault No.340 fix, only contracts in these states are processed.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (!(JKKSvcConst.KAP_KEI_STAT_010.equals(kapStat) || JKKSvcConst.KAP_KEI_STAT_020.equals(kapStat)))` // `010` = 受付済 (Ready), `020` = 照 miru 済 (Under review) [KAP_KEI_STAT_010="010", KAP_KEI_STAT_020="020"] |
| 2 | RETURN | `return 0` // Contract not in cancellable state — abort |

**Block 14.4** — [SET] Save contract hash (L7700)

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultHash.put(TEMPLATE_ID_EKK2541B001 + "tmp", eKK2541B001Hash)` // Store current contract hash for downstream use |

**Block 14.5** — [CALL] Cancel rental contract (L7703)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `callKAPPUSC(param, handle, requestParam, resultHash, TEMPLATE_ID_EKK2541C170)` // TEMPLATE_ID_EKK2541C170 = "EKK2541C170" — Rental contract cancellation (割賦契約キャンセル) |

**Block 14.6** — [IF] Error check after cancellation (L7704)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` // Early return on cancellation error |

**Block 14.7** — [SET] Flag cancellation success (L7707–7709)

> ANK-1306-00-00 2013/01/23 ADD. Mark that at least one rental contract was cancelled.

| # | Type | Code |
|---|------|------|
| 1 | SET | `isCancelKapKei = true` // At least one rental contract was cancelled |

**Block 15** — [IF] Temporary charge cancellation check (L7713)

> Per the comment (割賦契約がキャンセルされた場合、一時金をキャンセルする — If a rental contract was cancelled, cancel the temporary charge). Only execute the temporary charge cancellation workflow if at least one rental contract was cancelled.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (isCancelKapKei)` // Temporary charge cancellation required |

**Block 16** — [CALL] Retrieve temporary charge list (L7716)

> Fetch all temporary charges (deposit/installment fees) associated with the application. Per the comment (一時金設定一覧照会 — Temporary charge setting list retrieval).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `callEKK1021B003SC(param, handle, requestParam, resultHash)` // Retrieve temporary charge list (一時金設定一覧照会 申込明细番号) |

**Block 17** — [IF] Error check after temp charge list (L7717)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` |

**Block 18** — [GET] Extract temporary charge list (L7720)

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK1021B003HashList = (ArrayList<HashMap<String, Object>>)resultHash.get(TEMPLATE_ID_EKK1021B003)` // Temporary charge ArrayList |

**Block 19** — [IF] Empty temporary charge list (L7723)

> If no temporary charges exist, there is nothing to cancel.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (eKK1021B003HashList.size() == 0)` |
| 2 | RETURN | `return 0` // No temporary charges to cancel |

**Block 20** — [FOR] Iterate temporary charges (L7726–7797)

> Loop through each temporary charge and process it based on its completion status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` // Loop counter |
| 2 | EXEC | `i < eKK1021B003HashList.size()` // Loop condition |
| 3 | INC | `i++` |

**Block 20.1** — [GET] Extract temporary charge hash (L7728)

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK1021B003Hash = eKK1021B003HashList.get(i)` // Current temporary charge data |

**Block 20.2** — [GET] Extract completion status code (L7730)

| # | Type | Code |
|---|------|------|
| 1 | GET | `kapKeiStat = (String)eKK1021B003Hash.get(EKK1021B003CBSMsg1List.FIN_STAT_CD)` // Completion status code |

**Block 20.3** — [SET] Save charge hash (L7731)

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultHash.put(TEMPLATE_ID_EKK1021B003 + "tmp", eKK1021B003Hash)` // Store for downstream |

**Block 21** — [IF] Unfinished status check (L7734)

> Per the comment (一時金設定の完了状況コードが未完了(0)の場合 — If temporary charge completion status is unfinished (0)). Temporary charges with status `0` are pending and need to be directly modified/cancelled.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (JKKStrConst.CD01147_MI_KANRYO.equals(kapKeiStat))` // `CD01147_MI_KANRYO` = "0" (Unfinished) [-> JKKStrConst.CD01147_MI_KANRYO="0"] |
| 2 | CALL | `callEKK1021C010SC(param, handle, requestParam, resultHash)` // Modify temporary charge (一時金設定変更実行処理) |

**Block 21.1** — [IF] Error check after temp charge modification (L7735)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` |

**Block 22** — [IF-ELSE] Completed status check (L7742)

> Per the comment (一時金設定の完了状況コードが完了(1)の場合 — If temporary charge completion status is completed (1)). For completed temporary charges, a two-step process is needed: first retrieve the linked contract-level temporary charges, then modify them.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (JKKStrConst.CD01147_KANRYO.equals(kapKeiStat))` // `CD01147_KANRYO` = "1" (Completed) [-> JKKStrConst.CD01147_KANRYO="1"] |

**Block 22.1** — [CALL] Retrieve contract temporary charge list (L7745)

> Per the comment (未取消契約一時金一覧照会 — Non-cancelled contract temporary charge list retrieval).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `callEKK1051B001SC(param, handle, requestParam, resultHash)` // Retrieve contract temporary charge list |

**Block 22.2** — [IF] Error check (L7746)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` |

**Block 22.3** — [GET] Extract contract charge list (L7749)

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK1051B001HashList = (ArrayList<HashMap<String, Object>>)resultHash.get(TEMPLATE_ID_EKK1051B001)` // Contract temporary charge ArrayList |

**Block 22.4** — [IF] Empty contract charge list (L7752)

> If no contract-level temporary charges are linked, there is nothing to cancel.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (eKK1051B001HashList.size() == 0)` |
| 2 | RETURN | `return 0` // No contract charges to cancel |

**Block 22.5** — [GET] Get first contract charge (L7755)

| # | Type | Code |
|---|------|------|
| 1 | GET | `eKK1051B001Hash = eKK1051B001HashList.get(0)` // First (and assumed only) contract charge |

**Block 22.6** — [SET] Save contract charge hash (L7756)

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultHash.put(TEMPLATE_ID_EKK1051B001 + "tmp", eKK1051B001Hash)` // Store for downstream |

**Block 22.7** — [CALL] Modify contract temporary charge (L7759)

> Per the comment (契約一時金変更実行処理 — Contract temporary charge modification execution processing).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `callEKK1051C020SC(param, handle, requestParam, resultHash)` // Modify contract temporary charge (契約一時金変更実行処理) |

**Block 22.8** — [IF] Error check after contract charge modification (L7760)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode` |

**Block 23** — [RETURN] Final return (L7801)

> Return the last processed status code. If no errors occurred, this is `0` indicating success.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return statusCode` // Return final status |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kappu` | Japanese term | Rental / Installment contract (割賦契約) — A financing arrangement where equipment or services are provided on an installment payment basis |
| `kap_kei_stat` | Field | Rental contract status code — Indicates the current state of a rental/installment contract |
| `KAP_KEI_STAT_010` | Constant | Rental contract status: Ready (受付済) — The contract has been accepted and is ready for processing |
| `KAP_KEI_STAT_020` | Constant | Rental contract status: Under Review (照 miru 済) — The contract is under review, still cancellable |
| `KAP_KEI_STAT_030` | Constant | Rental contract status: Closed (締結済) — The contract is finalized |
| `KAP_KEI_STAT_100` | Constant | Rental contract status: Completed (完了済) — The contract process is fully completed |
| `kapKeiStat` | Field | Temporary charge completion status code — Indicates whether a temporary charge has been processed |
| `finStatCd` | Field | Final completion status code — Used to determine if a temporary charge is pending (0) or completed (1) |
| `CD01147_MI_KANRYO` | Constant | Unfinished / Not completed ("0") — Temporary charge has not been finalized yet |
| `CD01147_KANRYO` | Constant | Completed ("1") — Temporary charge has been finalized |
| `svc_kei_no` | Field | Service contract number (サービス契約番号) — Unique identifier for a service contract line |
| `kkSvcKeiNo` / `kktkSvcKeiNo` | Field | Equipment service contract number (機器提供サービス契約番号) — Identifier for a rental/installment contract line within the service contract |
| `haiso_stat` | Field | Delivery status (配送ステータス) — Status of the delivery for a service contract line |
| `HAISO_STAT_UK_ZM` | Constant | Delivery status: Accepted (受付済) — "001", delivery has been accepted by the customer |
| `HAISO_STAT_SJ_ZM` | Constant | Delivery status: Instructed (指示済) — "002", delivery has been instructed but not yet shipped |
| `HAISO_STAT_SK_ZM` | Constant | Delivery status: Shipped (出荷済) — "003", delivery has been shipped |
| `HAISO_STAT_KNRYO` | Constant | Delivery status: Completed (完了済) — "004", delivery has been completed/delivered |
| `HAISO_STAT_STP` | Constant | Delivery status: Stopped (中止) — "005", delivery has been stopped/cancelled |
| `ITCHI_KIN` | Japanese term | Temporary charge (一時金) — A one-time fee or deposit associated with a service contract |
| `EDK0011B080CBSMSG1LIST` | Constant | Delivery message list field key — The list field within the EDK0011B080 response message |
| `KAP_KEI_STAT` | Constant | Rental contract status field key — The field name for rental contract status in messages |
| `KKSV016701CC` | Constant | Data key for service contract forced cancellation product mapping — Used as a parameter in delivery info search |
| SC | Acronym | Service Component — A modular service unit in the Fujitsufuturity platform that handles specific business operations |
| SIF | Acronym | System Interface — An interface for invoking SC methods |
| DSL | Acronym | Domain Specific Language — A pattern used for structured business processing flows |
| EKK | Prefix | Equipment/Service contract SC code prefix — Indicates an equipment or service-related service component |
| EDK | Prefix | Delivery/Information SC code prefix — Indicates a delivery or information-related service component |
| KK | Prefix | Kopt Business (KoptKigyō) module prefix — Indicates a module within the kopt business layer |
| CAANMsg | Class | Message data carrier class — Used to encapsulate message data returned from SC calls |
| Template ID | Concept | Identifier for SC request/response message templates — Used as keys in resultHash to store and retrieve SC call results |
| EKK2541B001 | Template ID | Rental contract list retrieval (割賦契約一覧照会 機器提供サービス契約番号) |
| EKK2541C170 | Template ID | Rental contract cancellation (割賦契約キャンセル) |
| EKK1021B003 | Template ID | Temporary charge list retrieval (一時金設定一覧照会 申込明细番号) |
| EKK1021C010 | Template ID | Temporary charge modification (一時金設定変更実行処理) |
| EKK1051B001 | Template ID | Contract temporary charge list retrieval (契約一時金一覧照会) |
| EKK1051C020 | Template ID | Contract temporary charge modification (契約一時金変更実行処理) |
| IT1-2012-0001946 | Change request | Lot 2 change request — A JIRA/ticket identifier for the 2012-11-12 delivery status filtering enhancement |
| ANK-1306-00-00 | Change request | Change request ID for the 2013-01-23 temporary charge cancellation feature |
