# Business Logic — JBSbatKKEoTVChgeFix.insertKktkSvcKeiKojiFin() [856 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKEoTVChgeFix` |
| Layer | Service (Batch processing — part of K-Opticom customer core system, `koptBatch` module) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKEoTVChgeFix.insertKktkSvcKeiKojiFin()

This method performs the final registration (insert/update) of the **Equipment-Provided Service Contract** (機器提供サービス契約, Kiki Teihyo Service Contract) in the `KK_T_KKTK_SVC_KEI` table. It is invoked at the end of equipment change workflows — specifically when the installation work is cancelled — to persist the final state of a customer's service contract after device-level modifications. The method acts as a **routing/dispatch pattern**: it reads a single `flg` parameter to determine which of four equipment handling scenarios is in effect, and for each scenario it computes different date boundaries, status codes, and termination metadata before assembling all 168 fields into a parameter array and calling `executeKK_T_KKTK_SVC_KEI_PKINSERT` for the final database write.

The four scenarios handled are:

- **Post-exchange** (`flg = "0"`): The equipment swap (STB or C-CAS) has already completed. The service contract status is set to "Service in Progress" (100), reservation application date is set to the operational date, and all plan/service dates are set to the future maximum (2099-12-31) since the contract remains active.

- **Pre-exchange** (`flg = "1"`): The equipment swap has not yet occurred. The method copies existing plan start and service details from the database while calculating end dates as one day before the new equipment dates. The plan end type is set to "Plan Change Termination" (1), and a read query is executed to look up the penalty code from the master table.

- **STB Add** (`flg = "2"`): An additional STB (Set-Top Box) device is being added to an existing service contract. The method computes all service dates from the construction execution date, and for B-CAS service subscriptions, it consults `bCasStartRsvAplyYmdMap` to set the reservation application date from a prior B-CAS start mapping if a 4K-STB to STB exchange accompanies a B-CAS deactivation.

- **STB Partial Removal** (`flg = "3"`): One STB device is being removed from a multi-STB service contract. All service dates are set to the construction execution month end. The termination reason is set to "Normal Cancellation" (01), the plan end type to "Termination by Removal" (2), and the penalty code is either preserved as "0" (no penalty) or looked up from the master table based on the equipment service code.

After all conditional branches converge, the method assembles 168 fields from the database (via `dbInfo`) and computed local variables into a single `Object[]` array and performs a single PK insert/update on the `KK_T_KKTK_SVC_KEI` table.

This method is a **shared utility** called by three internal methods in the same class, forming part of the eoTV equipment change confirmation batch processing pipeline.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertKktkSvcKeiKojiFin()"])
    START --> GET_SYS["Get system datetime sysDate"]
    GET_SYS --> GET_KAIHK["Clear kaihkYmd from dbInfo KAIHK_YMD"]
    GET_KAIHK --> FLG_CHECK{flg value}

    FLG_CHECK -->|"KOUKAN_AF = 0: Post-exchange"| POST_EX["Block: Post-exchange (KOUKAN_AF)"]
    FLG_CHECK -->|"KOUKAN_BF = 1: Pre-exchange"| PRE_EX["Block: Pre-exchange (KOUKAN_BF)"]
    FLG_CHECK -->|"STB_ADD_KKTK = 2: STB Add"| STB_ADD_B["Block: STB Add (STB_ADD_KKTK)"]
    FLG_CHECK -->|"STB_DSL_KKTK = 3: STB Partial Removal"| STB_DSL_B["Block: STB Partial Removal (STB_DSL_KKTK)"]

    POST_EX --> PK_SELECT["executeKK_M_KKTK_SVC_PKSELECT"]
    STB_ADD_B --> B_CAS_CHECK{B-CAS check: TAKNKIKI_SBT_CD equals B0?}
    B_CAS_CHECK -->|"Yes"| B_CAS_MAP{bCasStartRsvAplyYmdMap has key?}
    B_CAS_MAP -->|"Yes"| B_CAS_SET["Set rsvAplyYmd from bCasStartRsvAplyYmdMap"]
    B_CAS_MAP -->|"No"| SET_PARAM
    B_CAS_SET --> SET_PARAM
    B_CAS_CHECK -->|"No"| SET_PARAM

    STB_DSL_B --> PNLTY_CHECK{idoPnltyHasseiCd equals 0?}
    PNLTY_CHECK -->|"Yes"| PNLTY_ZERO["Set pnltyHasseiCd to 0"]
    PNLTY_CHECK -->|"No"| PNLTY_QUERY["Query PNLTY_HASSEI_UM from KK_M_KKTK_SVC"]
    PNLTY_ZERO --> SET_PARAM
    PNLTY_QUERY --> SET_PARAM

    PRE_EX --> SET_PARAM
    STB_ADD_B --> SET_PARAM

    SET_PARAM["Build setParam array of 168 fields from dbInfo plus computed values"]
    SET_PARAM --> INSERT["executeKK_T_KKTK_SVC_KEI_PKINSERT setParam"]
    INSERT --> END_NODE(["Return"])
```

### Branch Summary

The method branches on `flg` into 4 distinct processing paths, all of which:
1. Set `kktkSvcKeiStat` to `CD00056_KKTK_SVC_KEI_STAT_100` (Service in Progress)
2. Populate `Object[] setParam` from `dbInfo` data (reading from `KK_T_KKTK_SVC_KEI` table fields)
3. Populate computed/overridden fields (plan dates, service dates, penalty code)
4. Call `executeKK_T_KKTK_SVC_KEI_PKINSERT(setParam)` for final database insert/update

The `flg = "3"` (STB Partial Removal) branch additionally:
- Contains a nested `if/else` on `idoPnltyHasseiCd` to decide whether to look up the penalty code from the master table
- Calls `executeKK_M_KKTK_SVC_PKSELECT` for the penalty lookup

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `dbInfo` | `JBSbatCommonDBInterface` | Equipment-provided service contract cursor — contains all fields from the `KK_T_KKTK_SVC_KEI` table record being finalized. This is the source of truth for existing contract data that gets carried forward or modified. |
| 2 | `kojiakJssiYmd` | `String` | Construction execution date (工事案件実施年月日) — the date when the installation work is carried out. Used in STB Partial Removal (`flg = "3"`) to set plan end dates, service end dates, and service termination dates. Format: `yyyyMMdd` (8 characters). |
| 3 | `planStaymdKiki` | `String` | Plan start date from the new equipment (プラン開始年月日（工事案件）) — the plan start date from the construction work order, used as-is for the new plan's start date in post-exchange and STB Add scenarios. |
| 4 | `planChrgStaymdKiki` | `String` | Plan charge start date from the new equipment (プラン課金開始年月日（工事案件）) — the date billing begins for the new equipment, used as the plan charge start date in post-exchange and STB Add scenarios. |
| 5 | `flg` | `String` | Equipment handling flag — determines which of 4 processing branches is executed. Values: `"0"` = Post-exchange (KOUKAN_AF), `"1"` = Pre-exchange (KOUKAN_BF), `"2"` = STB Add (STB_ADD_KKTK), `"3"` = STB Partial Removal (STB_DSL_KKTK). |
| 6 | `strIdoDiv` | `String` | Migration division (異動区分) — the migration type code. Used in STB Partial Removal to set the migration division in the final record. |
| 7 | `strMskmDtlNo` | `String` | Application detail number (申込明細番号) — the application line item number. Used in STB Partial Removal to set the application detail number in the final record. |
| 8 | `idoPnltyHasseiCd` | `String` | Penalty generation code (違約金発生コード) — indicates whether a penalty fee applies for the STB removal. `"0"` means no penalty; any other value triggers a lookup from the master table based on the equipment service code. |

**Instance fields read by this method:**
- `bCasStartRsvAplyYmdMap` (Map<String, String>) — B-CAS start reservation application date map. Used in the STB Add branch to handle B-CAS deactivation during 4K-STB to STB exchanges. Keyed by service contract detail number.
- `batchUserId` — The batch operator account ID, written to registration/update `user` fields in the parameter array.
- `super.opeDate` — The operational date (from parent class), used as the reservation application date in post-exchange and STB Partial Removal scenarios.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `dbInfo.getString(KKTK_SVC_KEI)` | - | `KK_T_KKTK_SVC_KEI` | Reads all contract fields from the equipment-provided service contract table via cursor |
| R | `executeKK_M_KKTK_SVC_PKSELECT` | EKK_M_KKTK_SVC | `KK_M_KKTK_SVC` | Selects penalty generation flag (`PNLTY_HASSEI_UM`) from the equipment service master table. Used only when STB Partial Removal is triggered and penalty code is not "0". |
| C | `executeKK_T_KKTK_SVC_KEI_PKINSERT` | EKK_T_KKTK_SVC_KEI | `KK_T_KKTK_SVC_KEI` | Performs the final primary key insert/update of the equipment-provided service contract record with all 168 fields. |
| - | `JBSbatStringUtil.Rtrim` | - | - | String utility — trims whitespace from all string values retrieved from the database |
| - | `JBSbatDateUtil.getSystemDateTimeStamp` | - | - | System utility — returns current system timestamp as `yyyyMMddHHmmss` |
| - | `JBSbatDateUtil.adjustDate` | - | - | Date utility — calculates dates relative to a reference date (used to compute end dates as -1 day or month-end) |
| - | `JBSbatDateUtil.getEndOfMonth` | - | - | Date utility — returns the last day of a given month for computing end-of-month dates |

### Called Methods Detail

**executeKK_M_KKTK_SVC_PKSELECT(param)** — Read from `KK_M_KKTK_SVC` (Equipment-Provided Service Master)
- Called only in the `flg = "3"` branch when `idoPnltyHasseiCd != "0"`
- Queries the equipment service master table using the `KKTK_SVC_CD` to look up the penalty generation flag (`PNLTY_HASSEI_UM`)
- Returns a `JBSbatCommonDBInterface` with the penalty determination code

**executeKK_T_KKTK_SVC_KEI_PKINSERT(setParam)** — Create/Update on `KK_T_KKTK_SVC_KEI` (Equipment-Provided Service Contract)
- Called once at the end of all branches
- Inserts or updates the equipment-provided service contract record with 168 fields
- Fields include: contract numbers, dates (plan start/end, service start/end, charge dates), device information (STB model, serial number), delivery address fields, service status codes, penalty codes, and audit fields (registration/update/delete timestamps and user IDs)

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Class:JBSbatKKEoTVChgeFix.createKktkSvcKeiAddInfoKjFin | `createKktkSvcKeiAddInfoKjFin` -> `insertKktkSvcKeiKojiFin` | `executeKK_T_KKTK_SVC_KEI_PKINSERT [C] KK_T_KKTK_SVC_KEI` |
| 2 | Class:JBSbatKKEoTVChgeFix.createKktkSvcKeiDslInfoKjFin | `createKktkSvcKeiDslInfoKjFin` -> `insertKktkSvcKeiKojiFin` | `executeKK_T_KKTK_SVC_KEI_PKINSERT [C] KK_T_KKTK_SVC_KEI` |
| 3 | Class:JBSbatKKEoTVChgeFix.createKokanBfSTBInfo | `createKokanBfSTBInfo` -> `insertKktkSvcKeiKojiFin` | `executeKK_T_KKTK_SVC_KEI_PKINSERT [C] KK_T_KKTK_SVC_KEI`, `executeKK_M_KKTK_SVC_PKSELECT [R] KK_M_KKTK_SVC` |

**Notes:**
- All direct callers are internal methods within `JBSbatKKEoTVChgeFix` (the same batch service class).
- No screen (KKSV) or external batch entry points were found within 8 hops.
- The method is a leaf-level data persistence utility invoked during the equipment change confirmation batch workflow.
- Terminal operations from this method: `Rtrim` (string utility), `executeKK_T_KKTK_SVC_KEI_PKINSERT [C] KK_T_KKTK_SVC_KEI`, `getString [R] KK_T_KKTK_SVC_KEI`, `executeKK_M_KKTK_SVC_PKSELECT [R] KK_M_KKTK_SVC` (conditional).

## 6. Per-Branch Detail Blocks

### Block 1 — INITIALIZATION (L4848)

> Initialize local variables and read recovery date from the database.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysDate = JBSbatDateUtil.getSystemDateTimeStamp()` // Get system timestamp |
| 2 | SET | `kktkSvcKeiStat = ""` // Initialize equipment-provided service contract status |
| 3 | SET | `rsvAplyYmd = ""` // Initialize reservation application date |
| 4 | SET | `rsvAplyCd = ""` // Initialize reservation application code |
| 5 | SET | `planStaymd = ""` // Initialize plan start date |
| 6 | SET | `planEndymd = ""` // Initialize plan end date |
| 7 | SET | `planChrgStaymd = ""` // Initialize plan charge start date |
| 8 | SET | `planChrgEndymd = ""` // Initialize plan charge end date |
| 9 | SET | `svcStaYmd = ""` // Initialize service start date |
| 10 | SET | `svcChrgStaymd = ""` // Initialize service charge start date |
| 11 | SET | `svcEndymd = ""` // Initialize service end date |
| 12 | SET | `svcChrgEndymd = ""` // Initialize service charge end date |
| 13 | SET | `svcDslYmd = ""` // Initialize service termination date |
| 14 | SET | `idoDiv = ""` // Initialize migration division |
| 15 | SET | `mskmDtlNo = ""` // Initialize application detail number |
| 16 | SET | `svcDlreCd = ""` // Initialize service termination reason code |
| 17 | SET | `planEndSbtCd = ""` // Initialize plan end type code |
| 18 | SET | `pnltyHasseiCd = ""` // Initialize penalty generation code |
| 19 | SET | `kaihkYmd = JBSbatStringUtil.Rtrim(dbInfo.getString(KAIHK_YMD))` // Read recovery date from cursor [OM-2014-0000400] |

### Block 2 — BRANCH: flg = KOUKAN_AF = "0" (Post-exchange) (L4875)

> Post-equipment-exchange processing. The swap has completed. Set service status to "Service in Progress" (100), set plan dates to maximum (20991231), and read current service dates from the database.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiStat = JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_100` // = "100" (Service in Progress) [v20.00.00] |
| 2 | SET | `rsvAplyYmd = super.opeDate` // Set to operational date |
| 3 | SET | `rsvAplyCd = JBSbatKKConst.RSV_APLY_CD_FIX` // = "2" (Reservation Fixed) [v20.00.00] |
| 4 | SET | `planStaymd = planStaymdKiki` // Plan start = construction execution date |
| 5 | SET | `planEndymd = MAX_YYYYMMDD` // = "20991231" — contract remains active |
| 6 | SET | `planChrgStaymd = planChrgStaymdKiki` // Plan charge start = construction execution next month |
| 7 | SET | `planChrgEndymd = MAX_YYYYMMDD` // = "20991231" |
| 8 | SET | `svcStaYmd = dbInfo.getString(SVC_STA_YMD)` // Read from cursor |
| 9 | SET | `svcChrgStaymd = dbInfo.getString(SVC_CHRG_STAYMD)` // Read from cursor |
| 10 | SET | `svcEndymd = dbInfo.getString(SVC_ENDYMD)` // Read from cursor |
| 11 | SET | `svcChrgEndymd = dbInfo.getString(SVC_CHRG_ENDYMD)` // Read from cursor |
| 12 | SET | `svcDslYmd = dbInfo.getString(SVC_DSL_YMD)` // Read from cursor |
| 13 | SET | `idoDiv = dbInfo.getString(IDO_DIV)` // Read from cursor |
| 14 | SET | `mskmDtlNo = dbInfo.getString(MSKM_DTL_NO)` // Read from cursor |
| 15 | SET | `svcDlreCd = dbInfo.getString(SVC_DLRE_CD)` // Read from cursor |
| 16 | SET | `planEndSbtCd = dbInfo.getString(PLAN_END_SBT_CD)` // Read from cursor |
| 17 | SET | `pnltyHasseiCd = dbInfo.getString(PNLTY_HASSEI_CD)` // Read from cursor |

### Block 3 — BRANCH: flg = KOUKAN_BF = "1" (Pre-exchange) (L4913)

> Pre-equipment-exchange processing. The swap has not yet occurred. Read existing contract data and compute end dates as one day before the new equipment dates. The plan end type is set to "Plan Change Termination" (1).

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiStat = JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_100` // = "100" (Service in Progress) |
| 2 | SET | `rsvAplyYmd = dbInfo.getString(RSV_APLY_YMD)` // Read existing reservation application date |
| 3 | SET | `rsvAplyCd = dbInfo.getString(RSV_APLY_CD)` // Read existing reservation application code |
| 4 | SET | `planStaymd = dbInfo.getString(PLAN_STAYMD)` // Read existing plan start date |
| 5 | SET | `planEndymd = JBSbatDateUtil.adjustDate(planStaymdKiki, -1)` // One day before construction execution date |
| 6 | SET | `planChrgStaymd = dbInfo.getString(PLAN_CHRG_STAYMD)` // Read existing plan charge start |
| 7 | SET | `planChrgEndymd = JBSbatDateUtil.adjustDate(planChrgStaymdKiki, -1)` // One day before new charge start |
| 8 | SET | `svcStaYmd = dbInfo.getString(SVC_STA_YMD)` // Read from cursor |
| 9 | SET | `svcChrgStaymd = dbInfo.getString(SVC_CHRG_STAYMD)` // Read from cursor |
| 10 | SET | `svcEndymd = dbInfo.getString(SVC_ENDYMD)` // Read from cursor |
| 11 | SET | `svcChrgEndymd = dbInfo.getString(SVC_CHRG_ENDYMD)` // Read from cursor |
| 12 | SET | `svcDslYmd = dbInfo.getString(SVC_DSL_YMD)` // Read from cursor |
| 13 | SET | `idoDiv = dbInfo.getString(IDO_DIV)` // Read from cursor |
| 14 | SET | `mskmDtlNo = dbInfo.getString(MSKM_DTL_NO)` // Read from cursor |
| 15 | SET | `svcDlreCd = dbInfo.getString(SVC_DLRE_CD)` // Read from cursor |
| 16 | SET | `planEndSbtCd = JBSbatKKConst.PLAN_END_SBT_CD_PLANCHG` // = "1" (Plan Change Termination) [v20.00.00] |
| 17 | SET | `pnltyHasseiCd = dbInfo.getString(PNLTY_HASSEI_CD)` // Read from cursor |

### Block 4 — BRANCH: flg = STB_ADD_KKTK = "2" (STB Add) (L4947)

> STB (Set-Top Box) Add processing. A new STB device is being added to an existing contract. All service dates are computed from the construction execution date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiStat = JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_100` // = "100" (Service in Progress) |
| 2 | SET | `rsvAplyYmd = dbInfo.getString(RSV_APLY_YMD)` // Read existing reservation application date |

#### Block 4.1 — B-CAS Special Handling (ANK-3488-00-00) (L4953)

> If the device subtype is B-CAS ("B0"), check the B-CAS start reservation date map for B-CAS deactivation during 4K-STB to STB exchange.

| # | Type | Code |
|---|------|------|
| 1 | SET | `stbAddtaknkikiSbtCd = JBSbatStringUtil.Rtrim(dbInfo.getString(TAKNKIKI_SBT_CD))` // Read device subtype |
| 2 | IF | `JBSbatKKConst.CD01262_TAKNKIKI_SBT_CD_B0.equals(stbAddtaknkikiSbtCd)` // [ANK-3488-00-00] TAKNKIKI_SBT_CD_B0 = "B0" |

##### Block 4.1.1 — B-CAS Map Lookup (L4958)

| # | Type | Code |
|---|------|------|
| 1 | SET | `stbAddsvcKeiUcwkNo = JBSbatStringUtil.Rtrim(dbInfo.getString(SVC_KEI_UCWK_NO))` // Read service contract detail number |
| 2 | IF | `bCasStartRsvAplyYmdMap.containsKey(stbAddsvcKeiUcwkNo)` // Map contains this contract's B-CAS start date |

###### Block 4.1.1.1 — Override Reservation Application Date (L4960)

| # | Type | Code |
|---|------|------|
| 1 | SET | `rsvAplyYmd = bCasStartRsvAplyYmdMap.get(stbAddsvcKeiUcwkNo)` // Override with B-CAS start date |

#### Block 4.2 — Continue STB Add Processing (L4965)

| # | Type | Code |
|---|------|------|
| 1 | SET | `rsvAplyCd = dbInfo.getString(RSV_APLY_CD)` // Read from cursor |
| 2 | SET | `planStaymd = planStaymdKiki` // Plan start = construction execution date |
| 3 | SET | `planEndymd = MAX_YYYYMMDD` // = "20991231" |
| 4 | SET | `planChrgStaymd = planChrgStaymdKiki` // Plan charge start = construction execution next month |
| 5 | SET | `planChrgEndymd = MAX_YYYYMMDD` // = "20991231" |
| 6 | SET | `svcStaYmd = planStaymdKiki` // Service start = construction execution date |
| 7 | SET | `svcChrgStaymd = planChrgStaymdKiki` // Service charge start = construction execution next month |
| 8 | SET | `svcEndymd = MAX_YYYYMMDD` // = "20991231" |
| 9 | SET | `svcChrgEndymd = MAX_YYYYMMDD` // = "20991231" |
| 10 | SET | `svcDslYmd = dbInfo.getString(SVC_DSL_YMD)` // Read from cursor |
| 11 | SET | `idoDiv = dbInfo.getString(IDO_DIV)` // Read from cursor |
| 12 | SET | `mskmDtlNo = dbInfo.getString(MSKM_DTL_NO)` // Read from cursor |
| 13 | SET | `svcDlreCd = dbInfo.getString(SVC_DLRE_CD)` // Read from cursor |
| 14 | SET | `planEndSbtCd = dbInfo.getString(PLAN_END_SBT_CD)` // Read from cursor |
| 15 | SET | `pnltyHasseiCd = dbInfo.getString(PNLTY_HASSEI_CD)` // Read from cursor |

### Block 5 — BRANCH: flg = STB_DSL_KKTK = "3" (STB Partial Removal) (L5015)

> STB Partial Removal processing. One STB device is being removed. Service status is set to "Terminated" (910), all service dates are set to the construction execution month end, and the termination reason is "Normal Cancellation" (01).

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiStat = JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_910` // = "910" (Terminated) [v20.00.00] |
| 2 | SET | `rsvAplyYmd = super.opeDate` // Set to operational date |
| 3 | SET | `rsvAplyCd = JBSbatKKConst.RSV_APLY_CD_FIX` // = "2" (Reservation Fixed) |
| 4 | SET | `planStaymd = dbInfo.getString(PLAN_STAYMD)` // Read from cursor |
| 5 | SET | `planEndymd = kojiakJssiYmd` // Plan end = construction execution date |
| 6 | SET | `planChrgStaymd = dbInfo.getString(PLAN_CHRG_STAYMD)` // Read from cursor |
| 7 | SET | `planChrgEndymd = kojiakJssiYmd.substring(0,6) + getEndOfMonth(substring)` // Plan charge end = construction execution month end |
| 8 | SET | `svcStaYmd = dbInfo.getString(SVC_STA_YMD)` // Read from cursor |
| 9 | SET | `svcChrgStaymd = dbInfo.getString(SVC_CHRG_STAYMD)` // Read from cursor |
| 10 | SET | `svcEndymd = kojiakJssiYmd` // Service end = construction execution date |
| 11 | SET | `svcChrgEndymd = kojiakJssiYmd.substring(0,6) + getEndOfMonth(substring)` // Service charge end = construction execution month end |
| 12 | SET | `svcDslYmd = kojiakJssiYmd` // Service termination = construction execution date |
| 13 | SET | `idoDiv = strIdoDiv` // Set from parameter |
| 14 | SET | `mskmDtlNo = strMskmDtlNo` // Set from parameter |
| 15 | SET | `svcDlreCd = JBSbatKKConst.SVC_DLRE_CD_NORMAL` // = "01" (Normal Cancellation) [v20.00.00] |
| 16 | SET | `planEndSbtCd = JBSbatKKConst.PLAN_END_SBT_CD_MSDDSL` // = "2" (Termination by Removal) [v20.00.00] |

#### Block 5.1 — Penalty Code Decision (L5035)

> Determine the penalty generation code. If `idoPnltyHasseiCd` equals "0" (no penalty), keep it as "0". Otherwise, query the equipment service master table to look up the actual penalty flag.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JBSbatKKConst.CD01375_PNLTY_HASSEI_CD_0.equals(idoPnltyHasseiCd)` // [v20.00.00] PNLTY_HASSEI_CD_0 = "0" |

##### Block 5.1.1 — No Penalty (L5040)

| # | Type | Code |
|---|------|------|
| 1 | SET | `pnltyHasseiCd = "0"` // No penalty fee |

##### Block 5.1.2 — Look Up Penalty from Master (L5045)

> Query the equipment service master table to determine if a penalty applies for this service type.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktk_svc_cd = dbInfo.getString(KKTK_SVC_CD)` // Read equipment service code from cursor |
| 2 | SET | `param = new String[]{kktk_svc_cd}` // Build query parameter array |
| 3 | CALL | `pnltyHasseiUmMap = executeKK_M_KKTK_SVC_PKSELECT(param)` // [R] Query KK_M_KKTK_SVC master table |
| 4 | IF | `pnltyHasseiUmMap != null` // Check if query returned a result |

###### Block 5.1.2.1 — Set Penalty Code (L5051)

| # | Type | Code |
|---|------|------|
| 1 | SET | `pnltyHasseiCd = JBSbatStringUtil.Rtrim(pnltyHasseiUmMap.getString(PNLTY_HASSEI_UM))` // Set from master lookup |

#### Block 5.2 — Clear Recovery Date (L5056)

> OM-2014-0000400: Clear the recovery date when creating a termination record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kaihkYmd = ""` // Clear recovery date [OM-2014-0000400] |

### Block 6 — DATA ASSEMBLY: Build setParam Array (L5060)

> Assemble 168 fields into an Object array. Fields are populated from `dbInfo` (cursor reads from `KK_T_KKTK_SVC_KEI`) and computed local variables. This represents all contract, device, address, service period, and audit information.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam = new Object[168]` // Initialize parameter array |
| 2 | SET | `setParam[0] = dbInfo.getString(KKTK_SVC_KEI_NO)` // Equipment-provided service contract number |
| 3 | SET | `setParam[1] = sysDate` // Registration date/time (system timestamp) |
| 4 | SET | `setParam[2] = kktkSvcKeiStat` // Equipment-provided service contract status (computed) |
| 5 | SET | `setParam[3] = dbInfo.getString(KKTK_SVC_CD)` // Equipment-provided service code |
| 6 | SET | `setParam[4] = dbInfo.getString(PCRS_CD)` // Price code |
| 7 | SET | `setParam[5] = dbInfo.getString(PPLAN_CD)` // Price plan code |
| 8 | SET | `setParam[6] = dbInfo.getString(TK_HOSHIKI_KEI_NO)` // Supply method contract number |
| 9 | SET | `setParam[7] = dbInfo.getString(KKTK_SBT_CD)` // Equipment-provided type code |
| 10 | SET | `setParam[8] = dbInfo.getString(HAMBAI_SBT_CD)` // Sales type code |
| 11 | SET | `setParam[9..28]` // Service request dates, maker code, device designation, indoor device type/model, serial number, accessory info, device change info, telecom set code, HDD capacity, installation location, parent contract ID, service contract number, service contract detail number, service contract wiring detail number, option service contract number |
| 12 | SET | `setParam[29] = dbInfo.getString(SYSID)` // SYSID |
| 13 | SET | `setParam[30] = mskmDtlNo` // Application detail number (computed) |
| 14 | SET | `setParam[31..53]` // Link STB flag, device delivery designation warehouse, installation address (name, kana, address code, postal code, state, city, district, town, chome, block, building, room), manual input flag |
| 15 | SET | `setParam[54..75]` // Phone number, mansion building number, contractor address difference flag, individual delivery designation flag, delivery supplementary codes/memo, installation destination address fields (name, kana, address, postal code, state, city, district, town, block, building, room) |
| 16 | SET | `setParam[76..97]` // Auto-add code, address unconfirmed flag/remove date, charge start date correction, installation supplementary codes, post-contract work request date, inspection date/cancel date, delivery division/date/delivery destination designation date, trial addition/completion dates, actual addition/transfer deadline dates, contract conclusion date, JCCC application document date, guarantee code/period |
| 17 | SET | `setParam[98] = rsvAplyYmd` // Reservation application date (computed) |
| 18 | SET | `setParam[99] = dbInfo.getString(RSV_CL_YMD)` // Reservation cancellation date |
| 19 | SET | `setParam[100] = rsvAplyCd` // Reservation application code (computed) |
| 20 | SET | `setParam[101] = dbInfo.getString(KIKI_CHG_YMD)` // Device change date |
| 21 | SET | `setParam[102] = planStaymd` // Plan start date (computed) |
| 22 | SET | `setParam[103] = planEndymd` // Plan end date (computed) |
| 23 | SET | `setParam[104] = planChrgStaymd` // Plan charge start date (computed) |
| 24 | SET | `setParam[105] = planChrgEndymd` // Plan charge end date (computed) |
| 25 | SET | `setParam[106] = planEndSbtCd` // Plan end type code (computed) |
| 26 | SET | `setParam[107..128]` // Service cancellation dates/reason, service start date, service charge start, service stop dates/reason, service pause dates/reasons/memos, service end date, service charge end date, service termination date/reason/memo |
| 27 | SET | `setParam[129] = dbInfo.getString(ZANCHI_FLG)` // Remaining flag |
| 28 | SET | `setParam[130] = dbInfo.getString(SVC_DSL_TTDKI_FIN_FLG)` // Service termination completion flag |
| 29 | SET | `setParam[131] = kaihkYmd` // Recovery date (computed — cleared in STB Partial Removal) |
| 30 | SET | `setParam[132..136]` // Service cancellation cancel date, service termination cancel date, review result send code, service pause charge start date, penalty generation code (computed) |
| 31 | SET | `setParam[137..148]` // Device authentication ID/password, migration division, installation actual receipt date, eoTV installation acceptance status, device installation acceptance date, indoor device migration code, CAS card usage permission date, device additional info code, review termination completion code, router termination reservation processing status/result code |
| 32 | SET | `setParam[149] = dbInfo.getString(HAISO_WAY_CD)` // Delivery method code |
| 33 | SET | `setParam[150] = dbInfo.getString(KIKI_ITENS_MV_JSSIS_SKCD)` // Device transfer destination executor identification code |
| 34 | SET | `setParam[151] = dbInfo.getString(KAISHU_KIKI_UM)` // Returned device existence flag |
| 35 | SET | `setParam[152] = dbInfo.getString(HAISO_REQ_SHITEI_YMD)` // Delivery request designation date |
| 36 | SET | `setParam[153] = dbInfo.getString(SHKA_FIN_JI_SYRZM_FLG)` // Dispatch completion processing complete flag |
| 37 | SET | `setParam[154] = dbInfo.getString(SVC_STA_JI_HIS_JOKYO_SKCD)` // Service start date delivery status identification code |
| 38 | SET | `setParam[155] = sysDate` // Registration date/time (system timestamp) |
| 39 | SET | `setParam[156] = batchUserId` // Registration operator account |
| 40 | SET | `setParam[157] = sysDate` // Update date/time (system timestamp) |
| 41 | SET | `setParam[158] = batchUserId` // Update operator account |
| 42 | SET | `setParam[159] = ""` // Delete date/time (empty) |
| 43 | SET | `setParam[160] = ""` // Delete operator account (empty) |
| 44 | SET | `setParam[161] = JBSbatKKConst.MK_FLG_YK` // = "0" (Valid) [v20.00.00] |
| 45 | SET | `setParam[162..167] = ""` // Registration/update/delete operation dates and process IDs (all empty) |

### Block 7 — FINAL INSERT (L5701)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KKTK_SVC_KEI_PKINSERT(setParam)` // [C] Final database insert/update on KK_T_KKTK_SVC_KEI |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KKTK_SVC_KEI` | Table | Equipment-Provided Service Contract — main table storing service contract records for equipment-provided services (STB, C-CAS, etc.) |
| `KK_M_KKTK_SVC` | Table | Equipment-Provided Service Master — master table defining equipment service types and their properties (e.g., whether a penalty applies) |
| `kktkSvcKeiStat` | Field | Equipment-provided service contract status — "100" = Service in Progress, "910" = Terminated |
| `KOUKAN_AF` | Constant | Post-equipment-exchange flag = "0" — indicates the device swap (STB or C-CAS) has already been completed |
| `KOUKAN_BF` | Constant | Pre-equipment-exchange flag = "1" — indicates the device swap has not yet occurred |
| `STB_ADD_KKTK` | Constant | STB Add flag = "2" — indicates a new STB device is being added to the contract |
| `STB_DSL_KKTK` | Constant | STB Partial Removal flag = "3" — indicates one STB device is being removed from a multi-STB contract |
| `kojiakJssiYmd` | Parameter | Construction execution date — the date when the installation work for equipment change is carried out |
| `planStaymdKiki` | Parameter | Plan start date from construction — the new plan's start date from the work order |
| `planChrgStaymdKiki` | Parameter | Plan charge start date from construction — the new billing start date from the work order |
| `flg` | Parameter | Equipment handling flag — dispatches to one of 4 processing branches |
| `strIdoDiv` | Parameter | Migration division — the migration type code for the equipment change |
| `strMskmDtlNo` | Parameter | Application detail number — the application line item number |
| `idoPnltyHasseiCd` | Parameter | Penalty generation code from migration — indicates whether a cancellation penalty applies |
| `rsvAplyYmd` | Field | Reservation application date — when the reservation becomes effective |
| `rsvAplyCd` | Field | Reservation application code — "2" = Reservation Fixed |
| `planStaymd` | Field | Plan start date — when the plan begins |
| `planEndymd` | Field | Plan end date — when the plan terminates |
| `planChrgStaymd` | Field | Plan charge start date — when billing begins |
| `planChrgEndymd` | Field | Plan charge end date — when billing ends |
| `svcStaYmd` | Field | Service start date — when the service becomes available |
| `svcChrgStaymd` | Field | Service charge start date — when service billing begins |
| `svcEndymd` | Field | Service end date — when the service terminates |
| `svcChrgEndymd` | Field | Service charge end date — when service billing ends |
| `svcDslYmd` | Field | Service termination date — when the service contract is formally terminated |
| `svcDlreCd` | Field | Service termination reason code — "01" = Normal Cancellation |
| `planEndSbtCd` | Field | Plan end type code — "1" = Plan Change Termination, "2" = Termination by Removal |
| `pnltyHasseiCd` | Field | Penalty generation code — "0" = No penalty, other values indicate penalty applies |
| `kaihkYmd` | Field | Recovery date — used for service recovery; cleared on termination record creation |
| `IDO_DIV` | Field | Migration division — code indicating the type of migration (e.g., equipment change, address change) |
| `MSKM_DTL_NO` | Field | Application detail number — line item identifier in the application |
| `KKTK_SVC_CD` | Field | Equipment-provided service code — identifies the type of equipment service (e.g., STB, C-CAS) |
| `TAKNKIKI_SBT_CD` | Field | Indoor device type code — identifies the type of indoor device (e.g., "B0" = B-CAS) |
| `SVC_KEI_UCWK_NO` | Field | Service contract detail number — internal tracking ID for service contract line items |
| `bCasStartRsvAplyYmdMap` | Instance Field | B-CAS start reservation application date map — keyed by service contract detail number, used to track B-CAS deactivation dates during 4K-STB to STB exchanges |
| `KKTK_SVC_KEI_STAT_100` | Constant | Service in Progress status code = "100" |
| `KKTK_SVC_KEI_STAT_910` | Constant | Terminated status code = "910" |
| `RSV_APLY_CD_FIX` | Constant | Reservation Fixed code = "2" |
| `PLAN_END_SBT_CD_PLANCHG` | Constant | Plan Change Termination code = "1" |
| `PLAN_END_SBT_CD_MSDDSL` | Constant | Termination by Removal code = "2" |
| `SVC_DLRE_CD_NORMAL` | Constant | Normal Cancellation code = "01" |
| `CD01262_TAKNKIKI_SBT_CD_B0` | Constant | B-CAS device type code = "B0" |
| `CD01375_PNLTY_HASSEI_CD_0` | Constant | No-penalty code = "0" |
| `MK_FLG_YK` | Constant | Valid flag = "0" (records are valid/active) |
| `MAX_YYYYMMDD` | Constant | Future maximum date = "20991231" — used to indicate "no end date" for active contracts |
| STB | Acronym | Set-Top Box — decoding device for broadcast television signals |
| B-CAS | Business term | B-CAS (Broadcast Content Access System) — Japanese broadcast content copy protection and subscription management system |
| 4K-STB | Business term | 4K Set-Top Box — high-resolution STB capable of decoding 4K broadcast signals, associated with ACAS chip integration |
| C-CAS | Business term | Conditional Access System — subscription management system for encrypted broadcast content |
| K-Opticom | Business term | Major Japanese cable television and broadband service provider |
| eoTV | Business term | K-Opticom's IPTV/cable television service brand |
| ANK | Acronym | Internal project/issue tracking code prefix (e.g., ANK-3488-00-00) |
| OM | Acronym | Internal project/issue tracking code prefix (e.g., OM-2014-0000400) |
| SG1 | Acronym | Internal project/issue tracking code prefix (e.g., SG1-2013-0000100) |
| PK INSERT | Technical term | Primary Key Insert — database operation that inserts or updates a record by primary key |