# Business Logic — JKKSecurityPackOperateCC.jdgHiChrgKekka() [173 LOC]

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

## 1. Role

### JKKSecurityPackOperateCC.jdgHiChrgKekka()

This method performs the **non-billing determination** (非課金判定処理) for security pack service contract cancellations. It evaluates whether a customer should be charged (課金) or exempt from charges (非課金) based on the contract cancellation type, the cancellation calculation date (起算日), and various service billing start dates. The method operates as a **conditional routing/dispatch pattern**, branching by contract cancellation flag (解約種別フラグ) to handle two distinct cancellation scenarios: discounted service contract cancellation and option service contract cancellation.

The method is a shared utility component (CC) called by multiple operations within `JKKSecurityPackOperateCC` — specifically `adchgDslOption()`, `dslOption()`, and `dslWrib()` — which are involved in the broader security pack handling workflow. It serves as a financial decision point during contract cancellation processing, determining billing eligibility and updating the relevant date fields accordingly. When parameter validation fails, it short-circuits by clearing all billing date fields and returning early, effectively marking the service as non-billable.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["jdgHiChrgKekka(params)"])
    CHECK["paramCheack jdgHiChrgMap"]
    CLEAR["Clear: svcChrgStaYmd='', svcChrgEndYmd='', chrgFlg=''"]
    EARLY_RET["Return jdgHiChrgMap early"]

    INIT["Init: chrgFlg = CHRG='1' (Billing)"]
    GET_DSL["Get: dslSbtFlg from map"]
    GET_CHRG_CD["Get: chrgHichrgCd from map"]
    GET_KISAN["Get: kisanDate from ccWorkMap.KEY_KISAN_YMD='kisan_ymd'"]
    GET_SVC_END["Get: svcChrgEndYmd from map"]

    DSL1["dslSbtFlg = WRIBSVCKEI_DSL='1' (Discounted Service Contract Cancellation)"]
    DSL2["dslSbtFlg = OPSVCKEI_DSL='2' (Option Service Contract Cancellation)"]

    DSL1_GET["Get: svcChrgStaYmd, wribSvcChrgStaYmd, wribSvcStaYmd, wribPlanChrgStaYmd"]
    DSL1_CMP1["kisanDate <= svcChrgStaYmd?"]
    DSL1_NONBILL["Set: chrgFlg = HICHRG='0' (Non-billing)"]
    DSL1_SET_DATES["Set: chrgWribSvcChrgStaYmd=kisanDate, chrgWribPlanChrgStaYmd=kisanDate"]
    DSL1_CMP2["kisanDate <= wribSvcChrgStaYmd?"]
    DSL1_CHK_CD["chrgHichrgCd = '2' (Non-billing code)?"]
    DSL1_CD2_NONBILL["Set: chrgFlg=HICHRG='0', dates=kisanDate"]
    DSL1_CD2_CHARGE["Set: chrgFlg=CHRG='1', dates=wribSvcStaYmd"]
    DSL1_ELS2_CHK["chrgHichrgCd = '2'?"]
    DSL1_ELS2_NONBILL["Set: chrgFlg=HICHRG='0', dates=kisanDate"]
    DSL1_ELS2_CHARGE["Set: chrgFlg=CHRG='1', no update"]

    DSL2_GET["Get: opSvcChrgStaYmd, svcChrgStaYmd"]
    DSL2_CMP1["kisanDate <= svcChrgStaYmd?"]
    DSL2_NONBILL["Set: chrgFlg = HICHRG='0'"]
    DSL2_CMP2["kisanDate <= opSvcChrgStaYmd?"]
    DSL2_CHK_CD["chrgHichrgCd = '2'?"]
    DSL2_CD2_NONBILL["Set: chrgFlg = HICHRG='0'"]
    DSL2_CD2_CHARGE["Set: chrgFlg = CHRG='1'"]
    DSL2_ELS_CHK["chrgHichrgCd = '2'?"]
    DSL2_ELS_NONBILL["Set: chrgFlg = HICHRG='0'"]
    DSL2_ELS_CHARGE["Set: chrgFlg = CHRG='1'"]

    WRITE_MAP["Set: svcChrgStaYmd=chrgWribSvcChrgStaYmd"]
    WRITE_PLAN["Set: planChrgStaYmd=chrgWribPlanChrgStaYmd"]
    WRITE_END["Set: svcChrgEndYmd=svcChrgEndYmd"]
    WRITE_FLG["Set: chrgFlg=chrgFlg"]
    FINAL_RET["Return jdgHiChrgMap"]

    START --> CHECK
    CHECK -- true --> CLEAR --> EARLY_RET
    CHECK -- false --> INIT --> GET_DSL --> GET_CHRG_CD --> GET_KISAN --> GET_SVC_END

    GET_SVC_END --> DSL1
    DSL1 -- true --> DSL1_GET
    DSL1_GET --> DSL1_CMP1
    DSL1_CMP1 -- true --> DSL1_NONBILL --> DSL1_SET_DATES --> WRITE_MAP
    DSL1_CMP1 -- false --> DSL1_CMP2
    DSL1_CMP2 -- true --> DSL1_CHK_CD
    DSL1_CHK_CD -- true --> DSL1_CD2_NONBILL --> WRITE_MAP
    DSL1_CHK_CD -- false --> DSL1_CD2_CHARGE --> WRITE_MAP
    DSL1_CMP2 -- false --> DSL1_ELS2_CHK
    DSL1_ELS2_CHK -- true --> DSL1_ELS2_NONBILL --> WRITE_MAP
    DSL1_ELS2_CHK -- false --> DSL1_ELS2_CHARGE --> WRITE_MAP

    DSL1 -- false --> DSL2
    DSL2 -- true --> DSL2_GET
    DSL2_GET --> DSL2_CMP1
    DSL2_CMP1 -- true --> DSL2_NONBILL --> WRITE_MAP
    DSL2_CMP1 -- false --> DSL2_CMP2
    DSL2_CMP2 -- true --> DSL2_CHK_CD
    DSL2_CHK_CD -- true --> DSL2_CD2_NONBILL --> WRITE_MAP
    DSL2_CHK_CD -- false --> DSL2_CD2_CHARGE --> WRITE_MAP
    DSL2_CMP2 -- false --> DSL2_ELS_CHK
    DSL2_ELS_CHK -- true --> DSL2_ELS_NONBILL --> WRITE_MAP
    DSL2_ELS_CHK -- false --> DSL2_ELS_CHARGE --> WRITE_MAP

    DSL2 -- false --> WRITE_MAP
    WRITE_MAP --> WRITE_PLAN --> WRITE_END --> WRITE_FLG --> FINAL_RET
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `jdgHiChrgMap` | `HashMap<String, Object>` | The non-billing determination map carrying all billing-related context: contract cancellation type flag (`dslSbtFlg`), billing/non-billing code (`chrgHichrgCd`), service billing start/end dates (`svcChrgStaYmd`, `svcChrgEndYmd`), discounted service billing dates (`wribSvcChrgStaYmd`, `wribPlanChrgStaYmd`, `wribSvcStaYmd`), option service billing start date (`opSvcChrgStaYmd`). This map is both consumed and mutated — the method reads input decision parameters and writes back updated billing dates and the final billing flag. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `ccWorkMap` | `Map<String, Object>` | Work area map containing the cancellation calculation date (`kisan_ymd`) — the reference date used to compare against billing start dates to determine whether charges apply. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JKKSecurityPackOperateCC.paramCheack` | JKKSecurityPackOperateCC | - | Parameter validation — checks if required fields exist in `jdgHiChrgMap`. Returns `true` if validation fails (early return path). |
| - | `JPCDateUtil.subtractDay` | JPCDate | - | Date comparison utility — computes the day difference between two date strings (`svcChrgStaYmd - kisanDate` or `wribSvcChrgStaYmd - kisanDate`). Result >= 0 means the cancellation date is on or before the billing start date. |
| - | `JPCUtilCommon.subtractDay` | JPCUtilCommon | - | Alternative date subtraction utility — appears as a dependency (potentially called within the same date comparison logic depending on code branch). |

**Note:** This method is a pure business logic evaluator — it reads input from maps and writes output to maps. It does not directly perform database CRUD operations. All data persistence is handled by the caller methods (`adchgDslOption`, `dslOption`, `dslWrib`) after this method returns.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `adchgDslOption()` (JKKSecurityPackOperateCC) | `adchgDslOption` -> `jdgHiChrgKekka` | `paramCheack [-]`, `subtractDay [-]` |
| 2 | `dslOption()` (JKKSecurityPackOperateCC) | `dslOption` -> `jdgHiChrgKekka` | `paramCheack [-]`, `subtractDay [-]` |
| 3 | `dslWrib()` (JKKSecurityPackOperateCC) | `dslWrib` -> `jdgHiChrgKekka` | `paramCheack [-]`, `subtractDay [-]` |

## 6. Per-Branch Detail Blocks

**Block 1** — IF (parameter check) `(paramCheack(jdgHiChrgMap) == true)` (L2383)

> Parameter validation failed — clear all billing fields and return early. This is a guard clause that prevents further processing when required parameters are missing or invalid.

| # | Type | Code |
|---|------|------|
| 1 | SET | `jdgHiChrgMap.put("svcChrgStaYmd", "")` // Clear service billing start date [-> `svcChrgStaYmd` key] |
| 2 | SET | `jdgHiChrgMap.put("svcChrgEndYmd", "")` // Clear service billing end date [-> `svcChrgEndYmd` key] |
| 3 | SET | `jdgHiChrgMap.put("chrgFlg", "")` // Clear billing flag [-> `chrgFlg` key] |
| 4 | RETURN | `return jdgHiChrgMap` |

**Block 2** — INITIALIZATION (non-billing determination setup) (L2393)

> Initialize all local variables for the non-billing determination logic. Default billing flag is set to `CHRG = "1"` (billing), which will be flipped to non-billing if conditions warrant.

| # | Type | Code |
|---|------|------|
| 1 | SET | `chrgFlg = CHRG = "1"` // Billing flag default [-> `CHRG="1"` (JKKSecurityPackOperateCC.java:111)] |
| 2 | SET | `dslSbtFlg = (String)jdgHiChrgMap.get("dslSbtFlg")` // Contract cancellation type flag |
| 3 | SET | `chrgHichrgCd = (String)jdgHiChrgMap.get("chrgHichrgCd")` // Billing/non-billing code |
| 4 | SET | `svcChrgStaYmd = ""` // Service billing start date (local) |
| 5 | SET | `svcChrgEndYmd = ""` // Service billing end date (local) |
| 6 | SET | `kisanDate = (String)ccWorkMap.get(KEY_KISAN_YMD)` // Cancellation calculation date [-> `KEY_KISAN_YMD="kisan_ymd"` (JKKSecurityPackOperateCC.java:291)] |
| 7 | SET | `svcChrgEndYmd = (String)jdgHiChrgMap.get("svcChrgEndYmd")` // Service billing end date from map |
| 8 | SET | `chrgWribSvcChrgStaYmd = ""` // Non-billing determination: service billing start date for writing [IT1-2017-0000067 ADD] |
| 9 | SET | `chrgWribPlanChrgStaYmd = ""` // Non-billing determination: plan billing start date for writing [IT1-2017-0000067 ADD] |

**Block 3** — IF (discounted service contract cancellation) `(WRIBSVCKEI_DSL.equals(dslSbtFlg))` where `WRIBSVCKEI_DSL = "1"` (L2409)

> Branch for "Discounted Service Contract Cancellation" (割引サービス契約解約). Evaluates billing eligibility by comparing the cancellation calculation date against the service billing start date and the discounted service billing start date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcChrgStaYmd = (String)jdgHiChrgMap.get("svcChrgStaYmd")` // Service billing start date |
| 2 | SET | `wribSvcChrgStaYmd = (String)jdgHiChrgMap.get("wribSvcChrgStaYmd")` // Discounted service billing start date |
| 3 | SET | `wribSvcStaYmd = (String)jdgHiChrgMap.get("wribSvcStaYmd")` // Discounted service start date |
| 4 | SET | `chrgWribSvcChrgStaYmd = (String)jdgHiChrgMap.get("wribSvcChrgStaYmd")` // For writing [IT1-2017-0000067 ADD] |
| 5 | SET | `chrgWribPlanChrgStaYmd = (String)jdgHiChrgMap.get("wribPlanChrgStaYmd")` // For writing [IT1-2017-0000067 ADD] |

**Block 3.1** — IF (cancellation on or before service billing start) `(0 <= JPCDateUtil.subtractDay(svcChrgStaYmd, kisanDate))` (L2420)

> Business rule: If the cancellation calculation date is on or before the original service billing start date, the customer is deemed **non-billable** (非課金). The billing start date is reset to the cancellation date for both service and plan records.

| # | Type | Code |
|---|------|------|
| 1 | SET | `chrgFlg = HICHRG = "0"` // Non-billing [-> `HICHRG="0"` (JKKSecurityPackOperateCC.java:113)] |
| 2 | SET | `chrgWribSvcChrgStaYmd = kisanDate` // Set service billing start for write [IT1-2017-0000067 ADD] |
| 3 | SET | `chrgWribPlanChrgStaYmd = kisanDate` // Set plan billing start for write [IT1-2017-0000067 ADD] |

**Block 3.2** — IF (cancellation after service billing start) `else` of Block 3.1 (L2430)

> The cancellation date is after the original billing start date. Check if it's also after the discounted service billing start date to determine further.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JPCDateUtil.subtractDay(wribSvcChrgStaYmd, kisanDate)` // Compare cancellation vs discounted billing start |

**Block 3.2.1** — IF (cancellation on or before discounted billing start) `(0 <= JPCDateUtil.subtractDay(wribSvcChrgStaYmd, kisanDate))` (L2433)

> The cancellation date is on or before the discounted service billing start date — within the grace period (利用開始当月). Billing status depends on the non-billing code.

| # | Type | Code |
|---|------|------|
| 1 | IF | `chrgHichrgCd.equals("2")` // Non-billing code check |
| 2 | SET (Block 3.2.1.1) | `chrgFlg = HICHRG = "0"` // Non-billing [-> `HICHRG="0"`] |
| 3 | SET (Block 3.2.1.1) | `chrgWribSvcChrgStaYmd = kisanDate` // Service write date = cancellation date [IT1-2017-0000067 ADD] |
| 4 | SET (Block 3.2.1.1) | `chrgWribPlanChrgStaYmd = kisanDate` // Plan write date = cancellation date [IT1-2017-0000067 ADD] |
| 5 | SET (Block 3.2.1.2) | `chrgFlg = CHRG = "1"` // Billing |
| 6 | SET (Block 3.2.1.2) | `chrgWribSvcChrgStaYmd = wribSvcStaYmd` // Use discounted service start date [-> `wribSvcStaYmd`] |
| 7 | SET (Block 3.2.1.2) | `chrgWribPlanChrgStaYmd = wribSvcStaYmd` // Use discounted service start date [-> `wribSvcStaYmd`] |

**Block 3.2.2** — IF (cancellation after discounted billing start) `else` of Block 3.2.1 (L2447)

> The cancellation date is past the discounted service billing start date. Billing status depends on the non-billing code, but dates are NOT updated (unchanged = original values).

| # | Type | Code |
|---|------|------|
| 1 | IF | `chrgHichrgCd.equals("2")` // Non-billing code check |
| 2 | SET (Block 3.2.2.1) | `chrgFlg = HICHRG = "0"` // Non-billing [-> `HICHRG="0"`] |
| 3 | SET (Block 3.2.2.1) | `chrgWribSvcChrgStaYmd = kisanDate` // Service write date = cancellation date [IT1-2017-0000067 ADD] |
| 4 | SET (Block 3.2.2.1) | `chrgWribPlanChrgStaYmd = kisanDate` // Plan write date = cancellation date [IT1-2017-0000067 ADD] |
| 5 | SET (Block 3.2.2.2) | `chrgFlg = CHRG = "1"` // Billing |
| 6 | SET (Block 3.2.2.2) | *(no date update — comment: 更新しない / "Do not update")* |

**Block 4** — IF (option service contract cancellation) `(OPSVCKEI_DSL.equals(dslSbtFlg))` where `OPSVCKEI_DSL = "2"` (L2465)

> Branch for "Option Service Contract Cancellation" (オプションサービス契約解約). Similar date comparison logic but uses option-specific dates instead of discounted service dates.

| # | Type | Code |
|---|------|------|
| 1 | SET | `opSvcChrgStaYmd = (String)jdgHiChrgMap.get("opSvcChrgStaYmd")` // Option service billing start date |
| 2 | SET | `svcChrgStaYmd = (String)jdgHiChrgMap.get("svcChrgStaYmd")` // Service billing start date |

**Block 4.1** — IF (cancellation on or before service billing start) `(0 <= JPCDateUtil.subtractDay(svcChrgStaYmd, kisanDate))` (L2473)

> If the cancellation date is on or before the service billing start date, the customer is **non-billable** (非課金).

| # | Type | Code |
|---|------|------|
| 1 | SET | `chrgFlg = HICHRG = "0"` // Non-billing |

**Block 4.2** — IF (cancellation after service billing start) `else` of Block 4.1 (L2479)

> The cancellation date is after the original billing start date. Check the option service billing start date.

**Block 4.2.1** — IF (cancellation on or before option billing start) `(0 <= JPCDateUtil.subtractDay(opSvcChrgStaYmd, kisanDate))` (L2482)

> Within the grace period (利用開始当月). Billing status depends on the non-billing code.

| # | Type | Code |
|---|------|------|
| 1 | IF | `chrgHichrgCd.equals("2")` // Non-billing code check |
| 2 | SET (Block 4.2.1.1) | `chrgFlg = HICHRG = "0"` // Non-billing |
| 3 | SET (Block 4.2.1.2) | `chrgFlg = CHRG = "1"` // Billing |

**Block 4.2.2** — IF (cancellation after option billing start) `else` of Block 4.2.1 (L2492)

> Cancellation is past the option billing start date. Billing status depends on the non-billing code.

| # | Type | Code |
|---|------|------|
| 1 | IF | `chrgHichrgCd.equals("2")` // Non-billing code check |
| 2 | SET (Block 4.2.2.1) | `chrgFlg = HICHRG = "0"` // Non-billing |
| 3 | SET (Block 4.2.2.2) | `chrgFlg = CHRG = "1"` // Billing |

**Block 5** — OUTPUT WRITING (L2501)

> Write the computed billing values back to the result map. After the cancellation type branches, the method consolidates all results into the output map. The billing start date is written as `chrgWribSvcChrgStaYmd` (the date to write for billing determination), and the plan billing start date is written as `chrgWribPlanChrgStaYmd`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `jdgHiChrgMap.put("svcChrgStaYmd", chrgWribSvcChrgStaYmd)` // Service billing start date for write [IT1-2017-0000067 ADD] |
| 2 | SET | `jdgHiChrgMap.put("planChrgStaYmd", chrgWribPlanChrgStaYmd)` // Plan billing start date [IT1-2017-0000067 ADD] |
| 3 | SET | `jdgHiChrgMap.put("svcChrgEndYmd", svcChrgEndYmd)` // Service billing end date |
| 4 | SET | `jdgHiChrgMap.put("chrgFlg", chrgFlg)` // Final billing flag |
| 5 | RETURN | `return jdgHiChrgMap` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `jdgHiChrgMap` | Field | Non-billing determination map — carries all input and output data for the billing eligibility decision |
| `chrgFlg` | Field | Billing flag — `"1"` means billable (課金), `"0"` means non-billable (非課金) |
| `dslSbtFlg` | Field | Contract cancellation type flag — distinguishes between discounted service cancellation (`"1"`) and option service cancellation (`"2"`) |
| `chrgHichrgCd` | Field | Billing/non-billing code — `"2"` indicates non-billing status |
| `kisan_ymd` | Field | Cancellation calculation date (起算日) — the reference date from `ccWorkMap` used to compare against billing start dates |
| `svcChrgStaYmd` | Field | Service billing start date (サービス課金開始日) — when the service billing period begins |
| `svcChrgEndYmd` | Field | Service billing end date (サービス課金終了日) — when the service billing period ends |
| `wribSvcChrgStaYmd` | Field | Discounted service billing start date (割引サービス課金開始日) |
| `wribSvcStaYmd` | Field | Discounted service start date (割引サービス開始日) — when the discounted service actually began |
| `wribPlanChrgStaYmd` | Field | Plan billing start date (プラン課金開始日) — when the plan billing begins |
| `opSvcChrgStaYmd` | Field | Option service billing start date (オプションサービス課金開始日) |
| `chrgWribSvcChrgStaYmd` | Field | Billing determination write service billing start date — the computed date to write to the map |
| `chrgWribPlanChrgStaYmd` | Field | Billing determination write plan billing start date — the computed date to write to the map |
| `ccWorkMap` | Field | Work area map — holds contextual data including the cancellation calculation date |
| CHRG | Constant | `"1"` — Billing flag value (課金) |
| HICHRG | Constant | `"0"` — Non-billing flag value (非課金) |
| WRIBSVCKEI_DSL | Constant | `"1"` — Discounted service contract cancellation type (割引サービス契約解約) |
| OPSVCKEI_DSL | Constant | `"2"` — Option service contract cancellation type (オプションサービス契約解約) |
| KEY_KISAN_YMD | Constant | `"kisan_ymd"` — Map key for cancellation calculation date |
| Non-billing determination (非課金判定) | Business term | Process of evaluating whether a customer should be charged for a cancelled service based on timing of cancellation relative to billing start dates |
| Cancellation calculation date (起算日) | Business term | The reference date from which billing eligibility is determined during contract cancellation |
| Grace period (割引課金開始前) | Business term | The period where cancellation occurs after the original billing start but on or before the discounted/option billing start — customer is still within the initial usage month |
| paramCheack | Method | Parameter validation — verifies required fields exist in the input map |
| JPCDateUtil.subtractDay | Utility | Date comparison — returns the difference in days between two date strings (first - second) |
