# Business Logic — JBSbatKKKjhKapZnskIktSikyAdchg.addPrg() [93 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKKjhKapZnskIktSikyAdchg` |
| Layer | Batch Service (Package: `eo.business.service`, source: `koptBatch`) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKKjhKapZnskIktSikyAdchg.addPrg()

The `addPrg` method registers a **progress record** (progress = 進捗) into the `KK_T_PRG` (Progress) table as part of the batch processing workflow for handling **work cost discount contract residual unified billing with address changes** (工事費割賦契約残債一括請求住所変更). This method is responsible for creating a structured progress tracking entry that captures the state of a service contract line item after a discount (割賦) contract has been registered during the batch run. It acts as the final data-persistence step in the per-record processing loop of the `execute()` method, writing a single progress row that tracks the association between a service detail, a billing service contract, and the progress state. The method uses a builder pattern — it assembles a 33-element parameter array where each element corresponds to a column in the `KK_T_PRG` table, populates those fields from input data and system state, and delegates the actual database insert to `executeKK_T_PRG_PKINSERT`. A key conditional branch determines the value of the "progress special item 1" (`PRG_TKJK_1`) field based on whether the work cost discount contract's plan code (`KAP_PLAN_CD`) is set to a unified billing plan, which controls whether a replacement date is displayed or marked as "not set" in the progress log.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addPrg()"])
    START --> CREATE_ARR["Create Object[] setParam size=33"]
    CREATE_ARR --> GET_SEQ["Generate prgNo via JCCBatCommon.getFormatedNextSeq"]
    GET_SEQ --> ASSIGN_FIELDS["Fill setParam[0] to setParam[27] with field values"]
    ASSIGN_FIELDS --> CHECK_PLAN{"excSearchList KAP_PLAN_CD equals IKKATSU or IKKATSU_10_PERCENT?"}
    CHECK_PLAN -->|Yes| SET_NOSET["setParam[18] = Discount unified billing replacement date not set"]
    CHECK_PLAN -->|No| SET_YMD["setParam[18] = Discount unified billing replacement date judgeYm"]
    SET_NOSET --> FINISH_FIELDS["Fill setParam[19] to setParam[32] with remaining fields"]
    SET_YMD --> FINISH_FIELDS
    FINISH_FIELDS --> CALL_INSERT["executeKK_T_PRG_PKINSERT setParam"]
    CALL_INSERT --> END_NODE(["Return"])
```

**Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `KAP_PLAN_CD_IKKATSU` | "unified" (割賦) | Discount unified billing plan |
| `KAP_PLAN_CD_IKKATSU_10_PERCENT` | "unified 10%" | Discount unified billing 10% plan |
| `CD00647_PRG_STAT_H033` | "H033" | Progress status code — registered/completed |
| `MK_FLG_YK` | "0" | Valid flag — 0 = active/valid (有効) |
| `KK_T_PRG_CNT` | 33 | Number of columns in the KK_T_PRG table |
| `SEQ_PRG_NO` | "SEQ_PRG_NO" | Sequence name for progress number generation |

**Processing Flow:**
1. Create a 33-element `Object[]` array (`setParam`) to hold column values for the `KK_T_PRG` table insert.
2. Generate a formatted progress number (`prgNo`) using the next sequence value from `SEQ_PRG_NO`, padded to 12 digits.
3. Populate each `setParam` index with corresponding business data:
   - Index 0: Generated progress number (`prgNo`)
   - Index 1: Application detail number (from `wribPrgAddData`)
   - Index 5: First billing service contract number (`firstSeikySvcKeiNo`)
   - Index 13: Discrepancy division code (from `wribPrgAddData`)
   - Index 14, 16, 20, 22: System date-time stamps (from `JBSbatDateUtil.getSystemDateTimeStamp()`)
   - Index 15: Progress status code "H033" (from `JBSbatKKConst.CD00647_PRG_STAT_H033`)
   - Index 21, 23: Batch user ID (from `super.batchUserId`)
   - Index 26: Valid flag "0" (from `JBSbatKKConst.MK_FLG_YK`)
   - Most other indices are set to empty strings as placeholders.
4. **Conditional branch** — Determine the value of `setParam[18]` (Progress special item 1) based on the discount plan code from `excSearchList`:
   - If `KAP_PLAN_CD` equals `IKKATSU` or `IKKATSU_10_PERCENT`: Set to "not set" (設定なし)
   - Otherwise: Set to the year-month portion (YYYYMM) extracted from `judgeYmd.substring(0, 6)`
5. Populate remaining indices (19–32) with empty strings and audit fields.
6. Call `executeKK_T_PRG_PKINSERT(setParam)` to insert the record into `KK_T_PRG` using primary key columns.
7. Return (void method).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `wribPrgAddData` | `JBSbatCommonDBInterface` | Discount and progress registration data — carries the application detail number (`MSKM_DTL_NO`) and discrepancy division code (`IDO_DIV`) used to link the progress record to the specific service contract line item being processed. Derived from a query on `KK_T_SVC_KEI` that selects discount-related service contract details. |
| 2 | `firstSeikySvcKeiNo` | `String` | First billing service contract number — the primary service contract identifier that triggers the initial billing event for this customer. Used as the anchor reference (index 5) for the progress record, linking progress to the billing-side of the service contract relationship. |
| 3 | `excSearchList` | `JBSbatCommonDBInterface` | Work cost discount contract exclusion search result — contains the exclusion criteria search outcome for work cost discount contracts, specifically including the discount plan code (`KAP_PLAN_CD`) from the `KK_T_KOJIHI_KAP_KEI` table. Used in the conditional branch to determine whether the discount plan is a unified billing plan. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `judgeYmd` | `String` | Judgment date (YYYYMMDD) — used for the discount unified billing replacement date when the plan is not a unified plan. Determined earlier in `execute()` based on service type (telco, internet, etc.). |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatCommon.getFormatedNextSeq` | JCCBatCommon | - | Retrieves the next formatted sequence number for `SEQ_PRG_NO`, padded to 12 digits, used as the progress number (PRG_NO) |
| R | `JBSbatDateUtil.getSystemDateTimeStamp` | JBSbatDateUtil | - | Returns the current system date-time stamp (YYYYMMDDHHmmss) used for audit timestamps (IDO_DTM, PRG_DTM, ADD_DTM, UPD_DTM) |
| R | `JBSbatCommonDBInterface.getString` | JBSbatCommonDBInterface | - | Reads field values from `wribPrgAddData` — MSKM_DTL_NO (application detail number) and IDO_DIV (discrepancy division) |
| R | `JBSbatCommonDBInterface.getString` | JBSbatCommonDBInterface | - | Reads `KAP_PLAN_CD` from `excSearchList` to determine the discount plan code for the conditional branch |
| C | `JBSbatKKKjhKapZnskIktSikyAdchg.executeKK_T_PRG_PKINSERT` | JBSbatKKKjhKapZnskIktSikyAdchg | `KK_T_PRG` | Inserts a new progress record into `KK_T_PRG` using primary key columns, mapping all 33 setParam values to table columns (PRG_NO, MSKM_DTL_NO, SEIKY_KEI_NO, SVC_KEI_NO, etc.) |
| - | `String.substring` | String | - | Extracts the year-month portion (YYYYMM) from `judgeYmd` for display in the progress special item 1 field |

### How fields map to KK_T_PRG table columns:

| Index | Column Name | Value Source |
|-------|-------------|--------------|
| 0 | `PRG_NO` | Generated sequence number |
| 1 | `MSKM_DTL_NO` | From `wribPrgAddData.getString(MSKM_DTL_NO)` |
| 2 | `SEIKY_KEI_NO` | Empty string |
| 3 | `SEIKY_WAY_NO_KOZA` | Empty string (mouth/bank transfer method number) |
| 4 | `SEIKY_WAY_NO_CRECARD` | Empty string (credit card method number) |
| 5 | `SVC_KEI_NO` | `firstSeikySvcKeiNo` |
| 6 | `SVC_KEI_UCWK_NO` | Empty string |
| 7 | `SVC_KEI_KAISEN_UCWK_NO` | Empty string |
| 8 | `KKTK_SVC_KEI_NO` | Empty string (device provider service contract number) |
| 9 | `OP_SVC_KEI_NO` | Empty string (option service contract number) |
| 10 | `SEIOPSVC_KEI_NO` | Empty string (billing option service contract number) |
| 11 | `SBOP_SVC_KEI_NO` | Empty string (sub-option service contract number) |
| 12 | `WRIB_SVC_KEI_NO` | Empty string |
| 13 | `IDO_DIV` | From `wribPrgAddData.getString(IDO_DIV)` |
| 14 | `IDO_DTM` | System date-time stamp |
| 15 | `PRG_STAT` | `CD00647_PRG_STAT_H033` |
| 16 | `PRG_DTM` | System date-time stamp |
| 17 | `PRG_MEMO` | Empty string |
| 18 | `PRG_TKJK_1` | Conditional: "not set" or `judgeYmd.substring(0,6)` |
| 19 | `PRG_TKJK_2` | Empty string |
| 20 | `ADD_DTM` | System date-time stamp |
| 21 | `ADD_OPEACNT` | `super.batchUserId` |
| 22 | `UPD_DTM` | System date-time stamp |
| 23 | `UPD_OPEACNT` | `super.batchUserId` |
| 24 | `DEL_DTM` | Empty string |
| 25 | `DEL_OPEACNT` | Empty string |
| 26 | `MK_FLG` | `MK_FLG_YK` (0 = valid) |
| 27–32 | Audit columns | Empty strings |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `executeKK_T_PRG_PKINSERT` [C], `getFormatedNextSeq` [R], `getSystemDateTimeStamp` [R], `getSystemDateTimeStamp` [R], `getString` [R], `getString` [R], `getString` [R], `substring` [-], `substring` [-], `substring` [-], `substring` [-], `getString` [R], `getSystemDateTimeStamp` [R], `getSystemDateTimeStamp` [R], `getString` [R]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKjhKapZnskIktSikyAdchg | `JBSbatKKKjhKapZnskIktSikyAdchg.execute()` → `addPrg(wribPrgAddData, firstSeikySvcKeiNo, excSearchList)` | `executeKK_T_PRG_PKINSERT [C] KK_T_PRG` |

**Execution context:**
- The `execute()` method loops over input file records for "address change residual unified billing" processing.
- For each record, it performs: mansion type judgment → work cost discount exclusion search → discount contract registration → standard work cost residual discount application judgment → discount data registration → **progress registration (this method)**.
- This method is the last per-record operation in the batch processing loop.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Create parameter array `(L2010)`

> Creates the 33-element parameter array for KK_T_PRG insert.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Object[] setParam = new Object[KK_T_PRG_CNT]` | // Create SQL setup value map for registration [-> KK_T_PRG_CNT=33] |

**Block 2** — [SET] Generate progress number `(L2012)`

> Retrieves the next formatted sequence number for the progress record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String prgNo = JCCBatCommon.getFormatedNextSeq(super.commonItem, SEQ_PRG_NO, "", 12)` | // Progress number [-> SEQ_PRG_NO="SEQ_PRG_NO"] |

**Block 3** — [SET] Populate setParam[0]–setParam[27] `(L2015–L2053)`

> Assigns business values, system timestamps, and constants to the first 28 parameter slots.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[0] = prgNo` | // Progress number |
| 2 | SET | `setParam[1] = wribPrgAddData.getString(JBSbatKK_T_SVC_KEI.MSKM_DTL_NO)` | // Application detail number [-> MSKM_DTL_NO="MSKM_DTL_NO"] |
| 3 | SET | `setParam[2] = ""` | // Billing contract number |
| 4 | SET | `setParam[3] = ""` | // Billing method number (mouth) |
| 5 | SET | `setParam[4] = ""` | // Billing method number (credit card) |
| 6 | SET | `setParam[5] = firstSeikySvcKeiNo` | // Service contract number |
| 7 | SET | `setParam[6] = ""` | // Service contract detail number |
| 8 | SET | `setParam[7] = ""` | // Service contract line detail number |
| 9 | SET | `setParam[8] = ""` | // Device provider service contract number |
| 10 | SET | `setParam[9] = ""` | // Option service contract number |
| 11 | SET | `setParam[10] = ""` | // Billing option service contract number |
| 12 | SET | `setParam[11] = ""` | // Sub-option service contract number |
| 13 | SET | `setParam[12] = ""` | // Discount service contract number |
| 14 | SET | `setParam[13] = wribPrgAddData.getString(JBSbatKK_T_SVC_KEI.IDO_DIV)` | // Discrepancy division [-> IDO_DIV="IDO_DIV"] |
| 15 | SET | `setParam[14] = JBSbatDateUtil.getSystemDateTimeStamp()` | // Discrepancy year-month-day time-second |
| 16 | SET | `setParam[15] = JBSbatKKConst.CD00647_PRG_STAT_H033` | // Progress status [-> CD00647_PRG_STAT_H033="H033"] |
| 17 | SET | `setParam[16] = JBSbatDateUtil.getSystemDateTimeStamp()` | // Progress year-month-day time-second |
| 18 | SET | `setParam[17] = ""` | // Progress memo |

**Block 4** — [IF/ELSE] Determine setParam[18] value `(L2055–L2067)`

> Controls whether the discount unified billing replacement date is set based on the plan code from the exclusion search result. Originally defaulted to the operation date substring, modified to use judgeYmd and conditionally cleared for unified plans.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[18] = "Discount unified billing replacement date: " + judgeYmd.substring(0, 6)` | // Progress special item 1 (default) |
| 2 | IF | `JKKStrConst.KAP_PLAN_CD_IKKATSU.equals(excSearchList.getString(JBSbatKK_T_KOJIHI_KAP_KEI.KAP_PLAN_CD))` | [KAP_PLAN_CD_IKKATSU="unified", KAP_PLAN_CD_IKKATSU_10_PERCENT="unified 10%"] |
| 3 | OR | `JKKStrConst.KAP_PLAN_CD_IKKATSU_10_PERCENT.equals(excSearchList.getString(JBSbatKK_T_KOJIHI_KAP_KEI.KAP_PLAN_CD))` | [KAP_PLAN_CD_IKKATSU_10_PERCENT="unified 10%"] |
| 4 | SET | `setParam[18] = "Discount unified billing replacement date: not set"` | // If unified plan — no replacement date needed |
| 5 | ELSE | — | |
| 6 | SET | `setParam[18] = "Discount unified billing replacement date: " + judgeYmd.substring(0, 6)` | // Otherwise — set the judge date year-month |

**Block 5** — [SET] Populate setParam[19]–setParam[32] `(L2069–L2095)`

> Fills remaining parameter slots with empty strings, audit fields, and the valid flag.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[19] = ""` | // Progress special item 2 |
| 2 | SET | `setParam[20] = JBSbatDateUtil.getSystemDateTimeStamp()` | // Registration year-month-day time-second |
| 3 | SET | `setParam[21] = super.batchUserId` | // Registration operator account |
| 4 | SET | `setParam[22] = JBSbatDateUtil.getSystemDateTimeStamp()` | // Update year-month-day time-second |
| 5 | SET | `setParam[23] = super.batchUserId` | // Update operator account |
| 6 | SET | `setParam[24] = ""` | // Delete year-month-day time-second |
| 7 | SET | `setParam[25] = ""` | // Delete operator account |
| 8 | SET | `setParam[26] = JBSbatKKConst.MK_FLG_YK` | // Invalid flag (0 = valid) [-> MK_FLG_YK="0"] |
| 9 | SET | `setParam[27] = ""` | // Registration operation year-month-day |
| 10 | SET | `setParam[28] = ""` | // Registration process ID |
| 11 | SET | `setParam[29] = ""` | // Update operation year-month-day |
| 12 | SET | `setParam[30] = ""` | // Update process ID |
| 13 | SET | `setParam[31] = ""` | // Delete operation year-month-day |
| 14 | SET | `setParam[32] = ""` | // Delete process ID |

**Block 6** — [CALL] Execute database insert `(L2097)`

> Delegates the primary key insert into `KK_T_PRG` to the helper method.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_PRG_PKINSERT(setParam)` | // Execute DB access — inserts into KK_T_PRG [C] KK_T_PRG |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PRG_NO` | Field | Progress number — unique identifier for a progress record in the KK_T_PRG table, generated via sequence |
| `MSKM_DTL_NO` | Field | Application detail number — internal tracking ID for service contract line items |
| `SVC_KEI_NO` | Field | Service contract number — primary identifier for a service contract (telecom/internet) |
| `SVC_KEI_UCWK_NO` | Field | Service contract detail number — sub-identifier for service contract details |
| `IDO_DIV` | Field | Discrepancy division code — classifies the type of discrepancy or change for the service record |
| `PRG_STAT` | Field | Progress status — code indicating the current state of the progress record (H033 = registered) |
| `PRG_TKJK_1` | Field | Progress special item 1 — custom text field used to record the discount unified billing replacement date |
| `PRG_MEMO` | Field | Progress memo — free-form note field for the progress record |
| `MK_FLG` | Field | Valid flag (無効フラグ) — 0 = active/valid (有効), 1 = invalid (無効) |
| `ADD_DTM` / `UPD_DTM` / `DEL_DTM` | Field | Add/Update/Delete date-time stamp — audit timestamps for each lifecycle transition |
| `ADD_OPEACNT` / `UPD_OPEACNT` / `DEL_OPEACNT` | Field | Add/Update/Delete operator account — ID of the user who performed each operation |
| `KK_T_PRG` | Table | Progress table — stores progress tracking records for service contracts |
| `KK_T_SVC_KEI` | Table | Service contract table — stores service contract information (telecom, internet, etc.) |
| `KK_T_KOJIHI_KAP_KEI` | Table | Special work cost discount contract table — stores discount contract exclusion criteria and plan codes |
| `KK_T_WRIB_SVC_KEI` | Table | Discount service contract table — stores discount-related service contract records |
| `KAP_PLAN_CD` | Field | Discount plan code — indicates the type of discount plan (unified billing, 10% unified, etc.) |
| `IKKATSU` | Business term | Unified billing plan (一括) — the discount is applied as a single unified billing charge |
| `IKKATSU_10_PERCENT` | Business term | Unified billing 10% plan — a variant where 10% discount applies under unified billing |
| `CD00647_PRG_STAT_H033` | Constant | Progress status code "H033" — indicates the progress record has been registered/completed |
| `MK_FLG_YK` | Constant | Valid flag "0" — indicates the record is active (有効) |
| `firstSeikySvcKeiNo` | Field | First billing service contract number — the primary contract used for the initial billing event |
| `wribPrgAddData` | Parameter | Discount/progress registration data — contains fields needed to register a progress record |
| `excSearchList` | Parameter | Exclusion search result — search result for work cost discount contract exclusion criteria |
| `judgeYmd` | Field | Judgment date (YYYYMMDD) — the date used for determining the discount unified billing replacement date |
| 進捗 (Shincho) | Japanese term | Progress — the business concept of tracking the state/progress of a service contract transaction |
| 割賦 (Kaffe) | Japanese term | Installment/discount — refers to the work cost installment (discount) plan applied to service charges |
| 一括請求 (Ikkatsu Seikyuu) | Japanese term | Unified billing — consolidating multiple charges into a single billing statement |
| 住所変更 (Jusho Henkou) | Japanese term | Address change — the process of updating a customer's registered address |
| 残債 (Sansa) | Japanese term | Outstanding balance — remaining debt on an installment plan after a transaction |
| JBSbatBusinessService | Class | Base batch service class — provides common batch processing infrastructure (commonItem, batchUserId, etc.) |
| `executeKK_T_PRG_PKINSERT` | Method | Inserts a new row into KK_T_PRG using primary key columns |
