# Business Logic — JBSbatKKSyuKeiStabunKikiStaAdd.executeKK_T_KAP_KEI_PKINSERT() [48 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKSyuKeiStabunKikiStaAdd` |
| Layer | Service (Batch processing within `eo.business.service`) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKSyuKeiStabunKikiStaAdd.executeKK_T_KAP_KEI_PKINSERT()

This method performs a **primary-key-based insert** of a full installment contract record (割賦契約, *kafu keiyaku*) into the `KK_T_KAP_KEI` database table. It serves as the dedicated persistence layer method for creating new installment contract lines when the primary key (PK) mode of the contract status registration process is triggered. The method implements a **mapping-and-insert** design pattern: it receives 40 field-value pairs via an `Object[]` array, constructs a structured database interface object by mapping each array element to its corresponding field key, and delegates the actual SQL insert to `JBSbatSQLAccess.insertByPrimaryKeys()`. Its role in the larger system is a **leaf service method** — it is called by the batch entry point `execute()` within the same class and does not route to other CBS/SC components, making it a focused CRUD insertion point. It handles all 40 columns of the installment contract table including contract identifiers, status flags, date/time fields, billing data, operator audit fields, and logical delete flags.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["executeKK_T_KAP_KEI_PKINSERT(setParam)"])
    STEP1["Create setMap: new JBSbatCommonDBInterface()"]
    STEP2["Map 40 fields from setParam array via setValue()"]
    STEP3["db_KK_T_KAP_KEI.insertByPrimaryKeys(setMap)"]
    END_NODE(["Return / Next"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> END_NODE
```

**Processing flow:**

1. **Map creation** — Instantiates a `JBSbatCommonDBInterface` object (`setMap`) as a key-value container for database fields.
2. **Field mapping** — Maps all 40 fields from the `setParam` array in indexed order. Each array element at index `i` is assigned to the corresponding database column key via `setMap.setValue(key, setParam[i])`. This covers all contract data fields plus operator/audit fields.
3. **Database insert** — Delegates to `db_KK_T_KAP_KEI.insertByPrimaryKeys(setMap)` which generates and executes a SQL `INSERT` statement against the `KK_T_KAP_KEI` table using all mapped values. The `JBSbatSQLAccess` framework resolves the table name (`D_TBL_NAME_KK_T_KAP_KEI = "KK_T_KAP_KEI"`) and constructs the insert SQL from the field-value pairs.
4. **Return** — The method returns `void` upon successful insert completion. Any database or mapping error propagates as a generic `Exception`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `setParam` | `Object[]` | An ordered array of 40 field values representing the complete installment contract record to be inserted into `KK_T_KAP_KEI`. Each element at index `i` maps to a specific database column as defined in the Javadoc. The array must be non-null and have exactly 40 elements; otherwise, a `NullPointerException` or `ArrayIndexOutOfBoundsException` will be thrown. |

**Indexed field mapping (setParam array positions to business fields):**

| Index | Field Key | Business Description |
|-------|-----------|---------------------|
| 0 | `KAP_KEI_NO` | Installment contract number — unique identifier for the installment contract line |
| 1 | `GENE_ADD_DTM` | Generation registration datetime — timestamp of this version's registration |
| 2 | `KAP_KEI_STAT` | Installment contract status — current lifecycle status of the contract |
| 3 | `KAP_PLAN_CD` | Installment plan code — billing/plan classification code |
| 4 | `KKTK_SVC_KEI_NO` | Device provision service contract number — links to the associated device service contract line |
| 5 | `ADD_JI_KIKI_CHG_NO` | Registration-time device change number — tracks device changes at registration |
| 6 | `MSKM_DTL_NO` | Application detail number — links to the original application line item |
| 7 | `IDO_DIV` | Transfer classification — indicates the type of status transfer (e.g., new, modify, transfer) |
| 8 | `RSV_APLY_YMD` | Reservation application date — date the reservation becomes effective |
| 9 | `RSV_CL_YMD` | Reservation cancellation date — date the reservation was cancelled |
| 10 | `RSV_APLY_CD` | Reservation application code — classification code for the reservation type |
| 11 | `KAP_IKT_SIKY_SWCH_YM` | Installment一括 billing switch year/month — billing aggregation switch timing |
| 12 | `KAP_KEI_CNC_YMD` | Installment contract signing date — when the contract was formally concluded |
| 13 | `KAP_SEIKY_ENDYMD` | Installment billing end date — end of the billing period |
| 14 | `KAP_KEI_DSL_YMD` | Installment contract cancellation date — when the contract was cancelled/dissolved |
| 15 | `PNLTY_HASSEI_CD` | Penalty occurrence code — flag/code indicating if penalty charges apply |
| 16 | `KAP_KEI_CANCEL_YMD` | Installment contract cancel date — contract cancellation effective date |
| 17 | `KAP_KEI_CHRG_STDARD_YMD` | Installment contract billing standard date — billing standard reference date |
| 18 | `KAP_KEI_CHRG_STAYMD` | Installment contract billing start date — start of the billing cycle |
| 19 | `KAP_SEIKY_STA_YM` | Installment billing start year/month — when billing begins |
| 20 | `KAP_PAY_ZAN_CNT` | Installment payment remaining count — number of remaining installment payments |
| 21 | `KAP_SEIKY_ZUMI_CNT` | Installment billing completed count — number of billing cycles already invoiced |
| 22 | `KAP_SEIKY_ZUMI_AMNT` | Installment billing completed amount — total amount already invoiced |
| 23 | `TNMT_BUY_TCHISHO_OPUT_SKCD` | Terminal purchase notice output identification code — flag for terminal purchase documentation |
| 24 | `TNMT_BUY_UK_TNTSHA_NM` | Terminal purchase receipt operator name — name of the operator who handled the terminal purchase |
| 25 | `PRMOP_REKEIJI_WRBHIAPL_FLG` | Premium option re-contract non-applicable discount flag — whether premium option discount is disabled |
| 26 | `HKTGI_MOTO_KAP_KEI_NO` | Transfer-source installment contract number — original contract number when contract is transferred |
| 27 | `ADD_DTM` | Registration datetime — timestamp when this record was created |
| 28 | `ADD_OPEACNT` | Registration operator account — account ID of the registering operator |
| 29 | `UPD_DTM` | Update datetime — timestamp of last modification |
| 30 | `UPD_OPEACNT` | Update operator account — account ID of the last modifying operator |
| 31 | `DEL_DTM` | Deletion datetime — timestamp of logical deletion |
| 32 | `DEL_OPEACNT` | Deletion operator account — account ID of the deleting operator |
| 33 | `MK_FLG` | Invalidation flag — logical delete flag (enabled/disabled) |
| 34 | `ADD_UNYO_YMD` | Registration operation date — business processing date at registration |
| 35 | `ADD_TRN_ID` | Registration transaction ID — system transaction identifier at registration |
| 36 | `UPD_UNYO_YMD` | Update operation date — business processing date at update |
| 37 | `UPD_TRN_ID` | Update transaction ID — system transaction identifier at update |
| 38 | `DEL_UNYO_YMD` | Deletion operation date — business processing date at deletion |
| 39 | `DEL_TRN_ID` | Deletion transaction ID — system transaction identifier at deletion |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| C | `insertByPrimaryKeys` | - | `KK_T_KAP_KEI` | Inserts a full installment contract record into the `KK_T_KAP_KEI` table using all 40 mapped fields as primary-key values. The `JBSbatSQLAccess` framework generates the SQL `INSERT` statement based on the field-value pairs in `setMap`. |
| - | `setValue` | - | - | Called 40 times to populate the `setMap` with key-value pairs mapping field names to their corresponding values from `setParam`. |

**How to classify:**
- **C (Create)**: `insertByPrimaryKeys` — this is a database insert operation that creates a new row in the `KK_T_KAP_KEI` table.
- **- (Utility)**: `setValue` — framework method calls on the `JBSbatCommonDBInterface` parameter object for building the field-value map. These are utility calls, not business service calls.

**SC Code analysis:**
This method does not invoke any SC (Service Component) or CBS (CBS Service) methods. It directly uses the `JBSbatSQLAccess` persistence framework to perform the insert. The SC Code is therefore not applicable (`-`).

**Entity/DB table:**
- `KK_T_KAP_KEI` — Installment Contract table (割賦契約テーブル). The table name constant is defined in this class as `D_TBL_NAME_KK_T_KAP_KEI = "KK_T_KAP_KEI"` at line 62.

## 5. Dependency Trace

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | JBSbatKKSyuKeiStabunKikiStaAdd.execute() | `execute()` -> `executeKK_T_KAP_KEI_PKINSERT(setParam)` | `insertByPrimaryKeys [C] KK_T_KAP_KEI` |

**Detailed call chain:**

The method `executeKK_T_KAP_KEI_PKINSERT()` is a private method within the same class and is invoked directly from `execute()` (the batch entry point of `JBSbatKKSyuKeiStabunKikiStaAdd`). The `execute()` method orchestrates the batch processing for installment contract status registration, and calls this method to persist the full contract record during the PK insert phase. No external screens or CBS components directly invoke this method — it is an internal batch service method.

**Terminal operations from this method:**
- `insertByPrimaryKeys` [C] `KK_T_KAP_KEI` — The single terminal database operation. This inserts the complete installment contract record.
- `setValue` [-] `JBSbatCommonDBInterface` — 40 internal utility calls (not terminal).

## 6. Per-Branch Detail Blocks

This method has **no conditional branches** (no if/else, switch, loop, or try/catch). It is a linear processing flow.

**Block 1** — [PROCESSING LINEAR] (L584)

> Creates a database interface map and maps all 40 fields from the setParam array.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface setMap = new JBSbatCommonDBInterface();` // Create field-value map container |
| 2 | EXEC | `setMap.setValue("KAP_KEI_NO", setParam[0]);` // Installment contract number |
| 3 | EXEC | `setMap.setValue("GENE_ADD_DTM", setParam[1]);` // Generation registration datetime |
| 4 | EXEC | `setMap.setValue("KAP_KEI_STAT", setParam[2]);` // Installment contract status |
| 5 | EXEC | `setMap.setValue("KAP_PLAN_CD", setParam[3]);` // Installment plan code |
| 6 | EXEC | `setMap.setValue("KKTK_SVC_KEI_NO", setParam[4]);` // Device provision service contract number |
| 7 | EXEC | `setMap.setValue("ADD_JI_KIKI_CHG_NO", setParam[5]);` // Registration-time device change number |
| 8 | EXEC | `setMap.setValue("MSKM_DTL_NO", setParam[6]);` // Application detail number |
| 9 | EXEC | `setMap.setValue("IDO_DIV", setParam[7]);` // Transfer classification |
| 10 | EXEC | `setMap.setValue("RSV_APLY_YMD", setParam[8]);` // Reservation application date |
| 11 | EXEC | `setMap.setValue("RSV_CL_YMD", setParam[9]);` // Reservation cancellation date |
| 12 | EXEC | `setMap.setValue("RSV_APLY_CD", setParam[10]);` // Reservation application code |
| 13 | EXEC | `setMap.setValue("KAP_IKT_SIKY_SWCH_YM", setParam[11]);` // Installment billing switch year/month |
| 14 | EXEC | `setMap.setValue("KAP_KEI_CNC_YMD", setParam[12]);` // Installment contract signing date |
| 15 | EXEC | `setMap.setValue("KAP_SEIKY_ENDYMD", setParam[13]);` // Installment billing end date |
| 16 | EXEC | `setMap.setValue("KAP_KEI_DSL_YMD", setParam[14]);` // Installment contract cancellation date |
| 17 | EXEC | `setMap.setValue("PNLTY_HASSEI_CD", setParam[15]);` // Penalty occurrence code |
| 18 | EXEC | `setMap.setValue("KAP_KEI_CANCEL_YMD", setParam[16]);` // Installment contract cancel date |
| 19 | EXEC | `setMap.setValue("KAP_KEI_CHRG_STDARD_YMD", setParam[17]);` // Installment billing standard date |
| 20 | EXEC | `setMap.setValue("KAP_KEI_CHRG_STAYMD", setParam[18]);` // Installment billing start date |
| 21 | EXEC | `setMap.setValue("KAP_SEIKY_STA_YM", setParam[19]);` // Installment billing start year/month |
| 22 | EXEC | `setMap.setValue("KAP_PAY_ZAN_CNT", setParam[20]);` // Installment payment remaining count |
| 23 | EXEC | `setMap.setValue("KAP_SEIKY_ZUMI_CNT", setParam[21]);` // Installment billing completed count |
| 24 | EXEC | `setMap.setValue("KAP_SEIKY_ZUMI_AMNT", setParam[22]);` // Installment billing completed amount |
| 25 | EXEC | `setMap.setValue("TNMT_BUY_TCHISHO_OPUT_SKCD", setParam[23]);` // Terminal purchase notice output code |
| 26 | EXEC | `setMap.setValue("TNMT_BUY_UK_TNTSHA_NM", setParam[24]);` // Terminal purchase receipt operator name |
| 27 | EXEC | `setMap.setValue("PRMOP_REKEIJI_WRBHIAPL_FLG", setParam[25]);` // Premium option discount non-applicable flag |
| 28 | EXEC | `setMap.setValue("HKTGI_MOTO_KAP_KEI_NO", setParam[26]);` // Transfer-source installment contract number |
| 29 | EXEC | `setMap.setValue("ADD_DTM", setParam[27]);` // Registration datetime |
| 30 | EXEC | `setMap.setValue("ADD_OPEACNT", setParam[28]);` // Registration operator account |
| 31 | EXEC | `setMap.setValue("UPD_DTM", setParam[29]);` // Update datetime |
| 32 | EXEC | `setMap.setValue("UPD_OPEACNT", setParam[30]);` // Update operator account |
| 33 | EXEC | `setMap.setValue("DEL_DTM", setParam[31]);` // Deletion datetime |
| 34 | EXEC | `setMap.setValue("DEL_OPEACNT", setParam[32]);` // Deletion operator account |
| 35 | EXEC | `setMap.setValue("MK_FLG", setParam[33]);` // Invalidation flag (logical delete) |
| 36 | EXEC | `setMap.setValue("ADD_UNYO_YMD", setParam[34]);` // Registration operation date |
| 37 | EXEC | `setMap.setValue("ADD_TRN_ID", setParam[35]);` // Registration transaction ID |
| 38 | EXEC | `setMap.setValue("UPD_UNYO_YMD", setParam[36]);` // Update operation date |
| 39 | EXEC | `setMap.setValue("UPD_TRN_ID", setParam[37]);` // Update transaction ID |
| 40 | EXEC | `setMap.setValue("DEL_UNYO_YMD", setParam[38]);` // Deletion operation date |
| 41 | EXEC | `setMap.setValue("DEL_TRN_ID", setParam[39]);` // Deletion transaction ID |

**Block 2** — [PROCESSING LINEAR] (L629)

> Executes the primary-key-based insert into the database.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_KAP_KEI.insertByPrimaryKeys(setMap);` // Inserts the full installment contract record into KK_T_KAP_KEI table. The JBSbatSQLAccess framework uses the table name constant D_TBL_NAME_KK_T_KAP_KEI="KK_T_KAP_KEI" and constructs an INSERT SQL from the 40 field-value pairs in setMap. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_KAP_KEI` | Table | Installment Contract table — the core database table storing installment (kafu) contract line records |
| 割賦契約 (kafu keiyaku) | Business term | Installment contract — a billing arrangement where charges are split into periodic payments |
| `KAP_KEI_NO` | Field | Installment contract number — unique identifier for an installment contract line |
| `GENE_ADD_DTM` | Field | Generation registration datetime — timestamp recording when this version of the contract was registered |
| `KAP_KEI_STAT` | Field | Installment contract status — current state code of the installment contract in its lifecycle |
| `KAP_PLAN_CD` | Field | Installment plan code — classification code for the installment billing plan type |
| `KKTK_SVC_KEI_NO` | Field | Device provision service contract number — foreign key linking to the device service contract line |
| `ADD_JI_KIKI_CHG_NO` | Field | Registration-time device change number — tracks device changes that occurred at registration time |
| `MSKM_DTL_NO` | Field | Application detail number — links to the original service application detail line item |
| `IDO_DIV` | Field | Transfer classification — indicates the type of status transfer (new registration, modification, etc.) |
| `RSV_APLY_YMD` | Field | Reservation application date — the date a reservation takes effect |
| `RSV_CL_YMD` | Field | Reservation cancellation date — the date a previously-made reservation was cancelled |
| `RSV_APLY_CD` | Field | Reservation application code — classification code for the reservation type |
| `KAP_IKT_SIKY_SWCH_YM` | Field | Installment一括 billing switch year/month — indicates when billing aggregation mode was switched |
| `KAP_KEI_CNC_YMD` | Field | Installment contract signing date — the date the contract was formally concluded |
| `KAP_SEIKY_ENDYMD` | Field | Installment billing end date — the end date of the billing period |
| `KAP_KEI_DSL_YMD` | Field | Installment contract cancellation date — when the contract was cancelled/dissolved |
| `PNLTY_HASSEI_CD` | Field | Penalty occurrence code — code indicating whether penalty charges apply to this contract |
| `KAP_KEI_CANCEL_YMD` | Field | Installment contract cancel date — effective date of contract cancellation |
| `KAP_KEI_CHRG_STDARD_YMD` | Field | Installment contract billing standard date — the reference date for billing |
| `KAP_KEI_CHRG_STAYMD` | Field | Installment contract billing start date — when the billing cycle starts |
| `KAP_SEIKY_STA_YM` | Field | Installment billing start year/month — the month when billing begins |
| `KAP_PAY_ZAN_CNT` | Field | Installment payment remaining count — number of remaining unpaid installments |
| `KAP_SEIKY_ZUMI_CNT` | Field | Installment billing completed count — number of billing cycles already invoiced |
| `KAP_SEIKY_ZUMI_AMNT` | Field | Installment billing completed amount — total amount already invoiced to the customer |
| `TNMT_BUY_TCHISHO_OPUT_SKCD` | Field | Terminal purchase notice output identification code — controls output of terminal purchase documentation |
| `TNMT_BUY_UK_TNTSHA_NM` | Field | Terminal purchase receipt operator name — the operator who handled the terminal purchase transaction |
| `PRMOP_REKEIJI_WRBHIAPL_FLG` | Field | Premium option re-contract non-applicable discount flag — indicates whether premium option discounts are excluded on re-contract |
| `HKTGI_MOTO_KAP_KEI_NO` | Field | Transfer-source installment contract number — the original contract number when this record is a transferred copy |
| `ADD_DTM` | Field | Registration datetime — system timestamp when this record was first created |
| `ADD_OPEACNT` | Field | Registration operator account — the operator account ID that created this record |
| `UPD_DTM` | Field | Update datetime — system timestamp of the last modification |
| `UPD_OPEACNT` | Field | Update operator account — the operator account ID that last modified this record |
| `DEL_DTM` | Field | Deletion datetime — system timestamp of logical deletion |
| `DEL_OPEACNT` | Field | Deletion operator account — the operator account ID that performed the logical deletion |
| `MK_FLG` | Field | Invalidation flag (無効フラグ) — logical delete flag indicating whether the record is active or disabled |
| `ADD_UNYO_YMD` | Field | Registration operation date — business processing date at the time of registration |
| `ADD_TRN_ID` | Field | Registration transaction ID — system-assigned transaction identifier at registration |
| `UPD_UNYO_YMD` | Field | Update operation date — business processing date at the time of update |
| `UPD_TRN_ID` | Field | Update transaction ID — system-assigned transaction identifier at update |
| `DEL_UNYO_YMD` | Field | Deletion operation date — business processing date at the time of deletion |
| `DEL_TRN_ID` | Field | Deletion transaction ID — system-assigned transaction identifier at deletion |
| `JBSbatSQLAccess` | Framework class | Batch database access framework class that provides CRUD operations (insertByPrimaryKeys, selectByPrimaryKeys, etc.) |
| `JBSbatCommonDBInterface` | Framework class | Key-value interface class used to build database field-value maps for batch SQL operations |
| `insertByPrimaryKeys` | Method | Batch framework method that generates and executes a SQL INSERT statement using all field-value pairs as primary key values |
| `JBSbatKKSyuKeiStabunKikiStaAdd` | Class | Installment contract status registration addition batch service — handles adding/modifying installment contract status records |
| `execute()` | Method | Batch entry point of the class — orchestrates the overall installment contract status registration workflow |
| PKINSERT | Mode | Primary-key insert mode — a registration mode that inserts a complete record with all fields |
