# Business Logic — JBSbatKKRsvTokiHakTgCst.getSodHkSbtCd() [18 LOC]

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

## 1. Role

### JBSbatKKRsvTokiHakTgCst.getSodHkSbtCd()

The `getSodHkSbtCd()` method is a private batch utility that determines the **SOD (Service Order Data) issuance type code** for planned TOKI (a business document related to telecommunication service activation) issuance processing. It implements a **date-based routing/dispatch pattern**: it evaluates the TOKI end-scheduled date against the current transaction processing date to decide whether an SOD should be issued or suppressed.

Specifically, the method checks whether the provided TOKI end-scheduled date (`tokiEndRsymd`) has already passed relative to the transaction operational date (`trnOpeDate`). If the date has passed (or is null/empty), it returns the **"SOD not issued"** code (`"0"`), meaning no Service Order Data creation is necessary because the TOKI's validity window has already elapsed. If the date is in the future, it returns the **"Start SOD issuance"** code (`"1"`), instructing downstream processing to generate a new SOD for the planned TOKI.

This method is **called by multiple internal batch methods** within `JBSbatKKRsvTokiHakTgCst` -- including `outputTokiStart()` and the intermediate-file output paths for FTTH (Fiber To The Home) addition and DSL pause scenarios. It plays a **shared utility role** within the batch service layer, ensuring consistent SOD type determination logic across different TOKI processing branches without duplicating date comparison logic.

The method supports the broader system by preventing unnecessary SOD issuance for expired or invalid TOKI records while ensuring valid ones proceed through the service order creation pipeline.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getSodHkSbtCd"])
    CHECK_NULL["isNullDate(tokiEndRsymd)"]
    CHECK_PAST["JKKBatCommon.isPastDate"]
    BOTH_TRUE["Both conditions true: tokiEndRsymd is not null AND date is past"]
    SET_NONE["sodHkSbtCd = SOD_HAK_SBT_CD_NONE (value: 0)"]
    SET_STA["sodHkSbtCd = SOD_HAK_SBT_CD_STA (value: 1)"]
    RETURN["return sodHkSbtCd"]
    END_NODE(["Return / Next"])

    START --> CHECK_NULL
    CHECK_NULL -->|not null| CHECK_PAST
    CHECK_NULL -->|is null| ELSE_BRANCH["Else: date is null or empty"]
    CHECK_PAST -->|true| BOTH_TRUE
    CHECK_PAST -->|false| ELSE_BRANCH
    BOTH_TRUE --> SET_NONE
    ELSE_BRANCH --> SET_STA
    SET_NONE --> RETURN
    SET_STA --> RETURN
    RETURN --> END_NODE
```

**Processing flow description:**

1. The method receives `tokiEndRsymd` (TOKI end-scheduled date, either post-migration activation date or contract cancellation/suspension end date).
2. It first checks whether `tokiEndRsymd` is null or empty via `isNullDate()`. If it is, processing falls through to the else branch.
3. If not null, it delegates to `JKKBatCommon.isPastDate()` to compare `tokiEndRsymd` against the transaction processing date (`trnOpeDate`), with `"1"` as a day offset.
4. **If BOTH conditions are true** -- the date is not null AND it is in the past relative to `trnOpeDate` -- the method sets the SOD issuance type code to `"0"` (SOD not issued / cancel).
5. **Otherwise** (the date is null, empty, or still in the future) -- the method sets the SOD issuance type code to `"1"` (Start SOD issuance).

**Constant Resolution:**

| Constant Name | Actual Value | Business Meaning |
|--------------|-------------|------------------|
| `SOD_HAK_SBT_CD_NONE` | `"0"` | SOD Not Issued -- No Service Order Data creation is performed (cancellation case) |
| `SOD_HAK_SBT_CD_STA` | `"1"` | Start SOD Issuance -- A new Service Order Data record should be created |
| `SOD_HAK_SBT_CD_END` | `"2"` | End SOD Issuance -- (not used by this method, but defined in the class) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `tokiEndRsymd` | `String` | TOKI end-scheduled date -- represents either the post-migration-destination-activation TOKI termination scheduled date (移転先開通後トーキ終了予定年月日) or the contract cancellation/suspension TOKI termination scheduled date (解約・休止トーキ終了予定年月日). Values are date strings (e.g., `yyyyMMdd` format). If the date is null, empty, or in the future, SOD issuance is triggered (`"1"`). If the date is not null and is in the past relative to the transaction processing date, SOD issuance is suppressed (`"0"`). |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `trnOpeDate` | `String` | Transaction operational date -- the current processing date used as the reference point for date comparisons. Initialized in `initial()` from `super.onlineOpeDate`. |

## 4. CRUD Operations / Called Services

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

No SC codes, CBS, or Entity/DB tables are directly accessed within this method. The method performs **pure business logic computation** -- no database reads, writes, or external service calls. All called methods are **utility/date-checking methods** with no CRUD operations.

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatKKRsvTokiHakTgCst.isNullDate` | JBSbatKKRsvTokiHakTgCst | - | Calls `isNullDate` in `JBSbatKKRsvTokiHakTgCst` to check if `tokiEndRsymd` is null or empty |
| - | `JKKBatCommon.isPastDate` | JKKBatCommon | - | Calls `isPastDate` in `JKKBatCommon` to compare `tokiEndRsymd` against `trnOpeDate` with a day offset of `"1"` |

**Classification Notes:**

- `isNullDate`: A utility method that checks whether a date string is null, empty, or otherwise invalid. This is a **pure validation** operation -- no database or entity access.
- `JKKBatCommon.isPastDate(String date, String referenceDate, String offset)`: A batch-common date comparison utility that determines whether a given date is in the past relative to a reference date, with an optional day offset. This is a **pure date arithmetic** operation -- no database or entity access.

This method is a **pure computation utility** with zero direct database or entity CRUD operations. All its dependencies are date-checking utilities.

## 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: `isPastDate` [-], `isNullDate` [-]

### Caller Analysis:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKRsvTokiHakTgCst.outputTokiStart` | `outputTokiStart` -> `getSodHkSbtCd` | `isNullDate [-]`, `isPastDate [-]` |
| 2 | Batch: `JBSbatKKRsvTokiHakTgCst` (intermediate file output - FTTH addition) | `...createRsvTokiHakFile` -> `getSodHkSbtCd(itensOpafTokiEndRsymd)` | `isNullDate [-]`, `isPastDate [-]` |
| 3 | Batch: `JBSbatKKRsvTokiHakTgCst` (intermediate file output - DSL pause) | `...createRsvTokiHakFile` -> `getSodHkSbtCd(dslPauseTokiEndRsymd)` | `isNullDate [-]`, `isPastDate [-]` |

**Call Chain Details:**

- `outputTokiStart()`: Calls `getSodHkSbtCd(itensOpafTokiEndRsymd)` to determine the SOD type for FTTH planned TOKI processing. The result is used to tag intermediate file output.
- Intermediate file output methods: Call `getSodHkSbtCd()` with different date parameters (`itensOpafTokiEndRsymd` for FTTH addition, `dslPauseTokiEndRsymd` for DSL pause), passing the result to `createRsvTokiHakFile()` to produce intermediate files with the correct SOD issuance type code.

All callers reside within the same batch class `JBSbatKKRsvTokiHakTgCst`. No screen (KKSV*) or external entry points are directly connected to this method.

## 6. Per-Branch Detail Blocks

### Block 1 -- `if` `(tokiEndRsymd is not null AND date is past)` (L423)

> If the TOKI end-scheduled date is valid (not null/empty) and is in the past relative to the transaction processing date, the TOKI has expired -- so SOD issuance should NOT occur.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `isNullDate(tokiEndRsymd)` // Checks if date is null or empty [Returns: false => proceed to L2] |
| 2 | CALL | `JKKBatCommon.isPastDate(tokiEndRsymd, trnOpeDate, "1")` // Compares tokiEndRsymd against trnOpeDate with +1 day offset [JKBatConst.IS_PAST_DATE: true if date is past] |
| 3 | SET | `sodHkSbtCd = SOD_HAK_SBT_CD_NONE` // Assigns "0" (SOD Not Issued / Cancel) [-> SOD_HAK_SBT_CD_NONE="0"] |

### Block 2 -- `else` (L425)

> If the TOKI end-scheduled date is null, empty, or in the future -- SOD issuance SHOULD occur. This covers both the case where no end date was provided (default to issuing SOD) and where the TOKI is still valid.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sodHkSbtCd = SOD_HAK_SBT_CD_STA` // Assigns "1" (Start SOD Issuance) [-> SOD_HAK_SBT_CD_STA="1"] |

### Block 3 -- `return` (L430)

> Returns the computed SOD issuance type code to the caller for use in downstream batch processing.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return sodHkSbtCd` // Returns the determined SOD issuance type code |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `tokiEndRsymd` | Field | TOKI end-scheduled date -- the planned termination date of a TOKI document. Can be either the post-migration activation TOKI end date or the contract cancellation/suspension TOKI end date. |
| `trnOpeDate` | Field | Transaction operational date -- the current batch processing date, initialized from the online operational date. Used as the reference point for date comparisons. |
| `sodHkSbtCd` | Field | SOD issuance type code -- the output code indicating whether and how Service Order Data should be issued. |
| SOD | Acronym | Service Order Data -- a telecom order fulfillment entity representing a service order for provisioning. |
| SOD_HAK_SBT_CD_NONE | Constant | SOD Not Issued code (`"0"`) -- no Service Order Data creation is performed; used when the TOKI has expired. |
| SOD_HAK_SBT_CD_STA | Constant | Start SOD Issuance code (`"1"`) -- a new Service Order Data record should be created; used when the TOKI is still valid. |
| SOD_HAK_SBT_CD_END | Constant | End SOD Issuance code (`"2"`) -- SOD termination/cessation code (defined in class but not used by this method). |
| TOKI | Business term | A telecommunication service activation document (トーキ) used in the K-Opticom system for scheduling and tracking service provisioning milestones. |
| `isNullDate` | Method | A utility method that checks whether a date string is null, empty, or otherwise invalid. |
| `isPastDate` | Method | A date comparison utility that determines whether a given date is in the past relative to a reference date, with an optional day offset. |
| `JKKBatCommon` | Class | Batch-common utility class providing shared date-checking and batch processing helper methods. |
| FTTH | Business term | Fiber To The Home -- a fiber-optic broadband internet service type. |
| `createRsvTokiHakFile` | Method | Batch method that creates intermediate files for planned TOKI issuance, tagging them with the SOD issuance type code. |
| 移転先開通後トーキ終了予定年月日 | Field (Japanese) | Post-migration-destination-activation TOKI end-scheduled date -- the planned end date for a TOKI after a customer's service has been activated at a new (migrated) address. |
| 解約・休止トーキ終了予定年月日 | Field (Japanese) | Contract cancellation/suspension TOKI end-scheduled date -- the planned end date for a TOKI when a service contract is cancelled or suspended. |
| SOD発行種別 | Business term | SOD Issuance Type -- the classification of how a Service Order Data record should be created or processed (none/cancel, start, or end). |
| トーキ発行用中間ファイル | Business term | TOKI issuance intermediate file -- a batch output file that contains TOKI issuance records with associated SOD type codes, consumed by downstream processing. |
