# KKW00804SFLogic

## Purpose

`KKW00804SFLogic` is the webview business-logic controller for the **My Home Page Info Registration** screen (KKW00804). It handles the full lifecycle of allowing a customer to select and register a "My Home Page" (MyHP) data capacity plan through a web interface — from initial screen display with pre-populated options, through registration confirmation and final submission, to back/edit/finish navigation. This class is a central hub in the K-Opticom contract management system for MyHP plan enrollment.

## Design

The class follows the **Page Controller** pattern (part of the `futurity` web framework). It extends `JCCWebBusinessLogic` and provides `action*` methods that correspond to user interactions on a single JSP screen. Each action method orchestrates data preparation, service invocation, and navigation to the next screen.

Behind the scenes, two key backing services are called:

- **`KKSV0005`** — the *init display service*. It populates the screen with available Home Page capacity options, access analysis data, service contract status, pricing codes, customer agreement status, and operational parameters. This is a read-only service.
- **`KKSV0006`** — the *registration confirmation service*. It processes the submitted MyHP info registration, creating contract records, updating ISP agreements, registering billing/encoding targets, and SOD (service order) issuance. The `func_code` parameter distinguishes between display (validation, `FUNC_CD_2`) and actual registration (write, `FUNC_CD_1`).

The class uses **DBMapper** objects (`KKSV0005_KKSV0005OPDBMapper`, `KKSV0006_KKSV0006OPDBMapper`) to map between screen `DataBean` fields and the service layer's input/output maps, acting as a structured data-translation layer.

## Key Methods

### `actionInit() -> boolean` [lines 140-160]

Entry point for the initial screen display. Called when the user navigates to the MyHP registration screen.

1. Retrieves inherited screen info from the session (`JCCWebCommon.getScreenInfo(this)`).
2. Obtains the `X31SDataBeanAccess` form bean.
3. Calls `setHktgiBean()` to populate the customer contract inheritance list (sysid, service contract number, migration division code).
4. Calls `executeInitSvc()` to invoke the KKSV0005 service and populate capacity/pulldown lists.
5. Calls `setInitBean()` to set default pulldown indices and default dates.
6. Returns `true` (proceed to display the screen).

This is the gateway method — it sets up all the data the user sees before making any choices.

### `actionAddMyHPInfo() -> boolean` [lines 168-196]

Handled when the user clicks the **Register Confirm** button on the initial screen.

1. Retrieves the form bean.
2. Calls `setHPInfoBean()` to convert the user's MyHP capacity selection (pulldown index) into concrete values: `HP_CAPA_VALUE`, `CAPA`, `HP_CAPA_NM`, `ACCSS_BNSK_NM`, the start date (`USE_STAYMD`), additional capacity beyond the free tier (`ADD_CAPA`), pricing codes, order codes, and flags for automatic service fee application.
3. Calls `executeAddCfmSvc()` with `func_code = FUNC_CD_2` (display/validation mode) to process the registration data.
4. Sets an info message ("My Home Page info registration") with message ID `EKB0370__I`.
5. Configures navigation to the **confirmation screen** (KKW00805).
6. Dumps the data bean for logging.
7. Returns `true`.

### `actionBack() -> boolean` [lines 204-217]

Handled when the user clicks the **Back** button. Simply configures navigation to return to the previous screen (the current screen ID) and logs the data bean. Does not invoke any service — a simple page navigation action.

### `actionFixMyHPInfo() -> boolean` [lines 225-250]

Handled when the user clicks the **Confirm** button on the confirmation screen (KKW00805).

1. Retrieves the form bean.
2. Calls `executeAddCfmSvc()` with `func_code = FUNC_CD_1` (actual registration/write mode) to commit the MyHP info registration.
3. Sets an info message with message ID `EKB4390__I`.
4. Configures navigation to the **completion screen** (KKW00806).
5. Logs the data bean.
6. Returns `true`.

This is the critical write method — it actually creates the MyHP plan subscription through the KKSV0006 service, which internally calls numerous sub-SC (service component) methods for contract registration, ISP agreement, billing setup, encoding registration, and SOD issuance.

### `actionShusei() -> boolean` [lines 259-273]

Handled when the user clicks the **Edit** button on the confirmation screen. Configures navigation back to the registration screen (KKW00804) so the user can change their MyHP capacity selection. No service call — purely navigational.

### `actionFin() -> boolean` [lines 281-293]

Handled when the user clicks the **Finish** button on the completion screen. Configures navigation back to the service contract one-line screen (KKW02301), which is the parent menu from which the user originally navigated to this flow. No service call.

### `executeInitSvc(X31SDataBeanAccess[] paramBean) -> void` [lines 302-406]

Core method that invokes the KKSV0005 init display service. Sets up the following mapping operations via `KKSV0005_KKSV0005OPDBMapper`:

| SC Method | Purpose |
|---|---|
| `setKKSV000504SC` | Option service contract one-line screen |
| `setKKSV000501SC` | Option service contract <ISP> one-line screen |
| `setKKSV000502SC` | Home Page capacity information retrieval |
| `setKKSV000503SC` | Access analysis information retrieval |
| `setKKSV000505SC` | Business parameter management one-line screen |
| `setKKSV000506SC` | Customer one-line screen |
| `setKKSV000507SC` | Service contract one-line screen |
| `setKKSV000508SC` | Pricing code option service list |

After calling `invokeService(paramMap, inputMap, outputMap)`, it pulls back all results via the corresponding `getKKSV0005xxSC` methods. It then processes the HP capacity pulldown values (current/default, max, increment) and access analysis pulldown via `JKKWebCommon.setPulldownListNoIndex()`. The use date (`UNYO_YMD`) is set to the current operation date.

### `executeAddCfmSvc(X31SDataBeanAccess[] paramBean, String func_code) -> void` [lines 415-517]

Core method that invokes the KKSV0006 registration confirmation service. This is a complex, multi-step service call. The SC operations invoked include:

| SC Method | Purpose |
|---|---|
| `setKKSV000601SC` | Application content approval registration |
| `setKKSV000603SC` | Option service contract <ISP> info update |
| `setKKSV000604SC` | Option service contract <ISP> registration |
| `setKKSV000605SC` | Option service contract <ISP> registration |
| `setKKSV000618SC` | Option service contract <ISP> inquiry |
| `setKKSV000611SC` | Option service contract <ISP> closing |
| `setKKSV000612SC` | Option service contract <ISP> start |
| `setKKSV000619SC` | Option service contract <ISP> inquiry |
| `setKKSV000606SC` | Option service contract <ISP> closing |
| `setKKSV000607SC` | Option service contract <ISP> usage start |
| `setKKSV000609SC` | Encoding target registration |
| `setKKSV000620SC` | Encoding target registration |
| `setKKSV000616SC` | Migration one-line screen |
| `setKKSV000610SC` | Migration info registration |
| `setKKSV000608SC` | Application detail one-line screen |
| `setKKSV000602SC` | Application detail inquiry / follow-up |
| `setKKSV000613SC` | Fee priority inquiry |
| `setJKKHakkoSODCC` | SOD issuance |
| `setKKSV0006WORK` | MyHP info registration work item |
| `setUpdMkmScinsprtWkCC` | Application screen support work info update |

After invoking the service, it pulls back inquiry results. If `func_code` is `FUNC_CD_2` (display mode) and the migration division is "new contract" or "service add", it copies the migration date/time from the output map to the DataBean (`IDO_DTM`).

### `setInitBean(X31SDataBeanAccess[] paramBean) -> void` [lines 525-560]

Sets default values on the initial screen's DataBean:

- Sets the MyHP capacity pulldown default to index 0 (first option, likely the free/min tier).
- Sets the access analysis pulldown default to index 0.
- Ensures the domain (`HPAD_DOMAIN`) is populated from the URL domain parameter if blank.
- Sets default "use end date" fields (year, month, day) from the current operation date.
- Logs the data bean.

### `setHPInfoBean(X31SDataBeanAccess[] paramBean) -> void` [lines 568-777]

This is the most comprehensive data-preparation method, setting roughly **30+ DataBean fields** before a registration service call. Key responsibilities:

1. **MyHP capacity resolution**: Converts the user's pulldown index selection into the actual capacity code (`HP_CAPA_VALUE`, `CAPA`) and capacity name (`HP_CAPA_NM`).
2. **Access analysis name**: Reads the name for the selected access analysis option (always index 0, "none").
3. **Date composition**: Combines the year/month/day fields into `USE_STAYMD` (YYYYMMDD), calculates the first day of the month, and computes the service charge start date (first day of the following month).
4. **Migration division and application state logic**:
   - If migration division is `IDO_DIV_OP` (option setup): sets application type to `MSKM_SBT_CD_OP` (00026). If the operation date equals the start date, sets progress status to `PRG_STAT_OP_END` (5102, option setup complete); otherwise `PRG_STAT_OP_REQEST` (5101, option application in progress).
   - Otherwise (new application): sets application type to `MSKM_SBT_CD_NEW` (00001), with the same date-based status logic.
5. **Feature flags**: Sets the progress feature item (MyHP info registration), encoding type (URL), and constructs the encoding URL from domain + account.
6. **Operational date/time**: Sets `UNYO_YMD` (YYYYMMDD) and `UNYO_DTM` (YYYYMMDDHHMMSS with zeros).
7. **Additional capacity calculation**: If the selected capacity exceeds the free tier, computes `ADD_CAPA` as the difference; otherwise sets it to 0.
8. **Pricing/order codes**: Sets a comprehensive set of codes for pricing code (`PCRS_CD_MYHP`), pricing plan code (`PPLAN_CD_MYHP`), sub-option codes, order subdivision (`ORDER_SBT_CD_NET`), service order code, order issuance condition, request type (new/change), order content, and automatic fee application flag.
9. **System timestamp**: Sets `IDO_DTM` to the current system date-time stamp.

### `setHktgiBean(X31SDataBeanAccess[] paramBean) -> void` [lines 785-807]

Retrieves the customer contract inheritance list from the DataBean, extracts the `SYSID`, `SVC_KEI_NO` (service contract number), and `IDO_DIV` (migration division code), and copies them to the main bean. Also sets the sub-option service code to the Home Page capacity code (`SBOP_SVC_CD_HPCAPA`). This ensures the downstream services know which customer and contract they are operating on.

## Relationships

### Inbound (who depends on this class)

Four XML screen-definition files reference `KKW00804SFLogic`:

- **`WEBGAMEN_KKW008040PJP.xml`** — The initial MyHP info registration screen (KKW00804).
- **`WEBGAMEN_KKW008050PJP.xml`** — The MyHP info registration confirmation screen (KKW00805).
- **`WEBGAMEN_KKW008060PJP.xml`** — The MyHP info registration completion screen (KKW00806).
- **`x31business_logic_KKW00804SF.xml`** — The business logic routing configuration.

These three screens form a wizard-like flow: register -> confirm -> complete.

### Outbound (what this class depends on)

```mermaid
flowchart LR
    subgraph "Dependent Screens"
        A["KKW008040PJP"]
        B["KKW008050PJP"]
        C["KKW008060PJP"]
    end
    subgraph "Business Logic"
        D["KKW00804SFLogic"]
    end
    subgraph "Supporting Components"
        E["JCCWebBusinessLogic
Parent class"]
        F["KKSV0005 Mapper
Init service mapper"]
        G["KKSV0006 Mapper
Submit service mapper"]
        H["KKW00804SFConst
Constants"]
    end
    A --> D
    B --> D
    C --> D
    D --> E
    D --> F
    D --> G
    D --> H
```

- **`JCCWebBusinessLogic`** — Parent class providing base screen controller utilities (`getServiceFormBean`, `getCommonInfoBean`, `invokeService`, `dumpDatabean`, etc.).
- **`KKSV0005_KKSV0005OPDBMapper`** — Maps the init service's DataBean fields to input/output HashMaps.
- **`KKSV0006_KKSV0006OPDBMapper`** — Maps the registration service's DataBean fields to input/output HashMaps.
- **`X31SDataBeanAccess` / `X31SDataBeanAccessArray`** — The framework's data container objects used throughout the screen lifecycle.

### Class overview

```mermaid
flowchart TD
    subgraph "KKW00804SF Logic Flow"
        A["KKW00804SFLogic"] --> B["actionInit
Screen init"]
        A --> C["actionAddMyHPInfo
Registration confirm"]
        A --> D["actionBack
Back button"]
        A --> E["actionFixMyHPInfo
Confirm button"]
        A --> F["actionShusei
Edit button"]
        A --> G["actionFin
Finish button"]
        A --> H["executeInitSvc
Init service call"]
        A --> I["executeAddCfmSvc
Submit service call"]
        A --> J["setInitBean
Init bean setup"]
        A --> K["setHPInfoBean
HP info bean setup"]
        A --> L["setHktgiBean
Contract info setup"]
        B --> H
        B --> J
        B --> L
        C --> K
        C --> I
        E --> I
    end
    subgraph "Dependencies"
        A --> M["JCCWebBusinessLogic
Parent class"]
        A --> N["KKSV0005 Mapper
Service calls"]
        A --> O["KKSV0006 Mapper
Submit calls"]
        A --> P["X31SDataBeanAccess
Data container"]
    end
    M --> Q["X31BWebBusinessLogic
Base class"]
```

## Usage Example

The typical user flow proceeds through three screens:

1. **Registration screen (KKW00804)**: The user lands via `actionInit()`. The screen displays a pulldown of available MyHP capacity options (populated by `executeInitSvc` -> KKSV0005), the current access analysis setting, and the default use start date. The user selects a capacity and clicks the Register Confirm button.

2. **Confirmation screen (KKW00805)**: The user clicks the Register Confirm button, triggering `actionAddMyHPInfo()`. The `setHPInfoBean()` method resolves the user's pulldown selection into concrete capacity values and computes derived data (additional capacity, service charge dates, pricing codes, etc.). The KKSV0006 service is invoked in display/validation mode (`FUNC_CD_2`). A confirmation screen is displayed.

3. The user can either click **Edit** (`actionShusei()`) to return to step 1, or **Confirm** (`actionFixMyHPInfo()`), which invokes KKSV0006 in write mode (`FUNC_CD_1`) to actually register the subscription. After confirmation, they are taken to the completion screen (KKW00806).

4. **Completion screen (KKW00806)**: The user clicks **Finish** (`actionFin()`), which navigates them back to the service contract one-line screen (KKW02301).

The sequence diagram below illustrates this flow:

```mermaid
sequenceDiagram
    participant U as User
    participant S as Screen
    participant L as KKW00804SFLogic
    participant B as DataBean
    participant SV as Backing Service

    Note over U,SV: Initialization (actionInit)
    U->>S: Navigate to screen
    S->>L: actionInit()
    L->>B: getScreenInfo
    L->>B: getServiceFormBean
    L->>L: setHktgiBean
    L->>L: executeInitSvc
    L->>SV: invokeService(KKSV0005)
    SV-->>L: outputMap
    L->>B: setPulldownListNoIndex
    L->>L: setInitBean
    L-->>S: return true

    Note over U,SV: Submit (actionAddMyHPInfo)
    U->>S: Click Register Confirm
    S->>L: actionAddMyHPInfo()
    L->>B: getServiceFormBean
    L->>L: setHPInfoBean
    L->>L: executeAddCfmSvc
    L->>SV: invokeService(KKSV0006)
    SV-->>L: outputMap
    L->>B: setMessageInfo
    L->>B: setNextScreen KKW00805
    L-->>S: return true
```

## Notes for Developers

### Thread safety
The class has **no instance fields** beyond the static constants inherited from `JCCWebBusinessLogic`. All mutable state lives in the `paramBean` array and the local `HashMap` variables within methods. Each HTTP request creates a new instance (standard for the Page Controller pattern), so the class is effectively thread-safe.

### Functional mode distinction
The `func_code` parameter in `executeAddCfmSvc` is critical:
- **`FUNC_CD_1`** (write mode): Used in `actionFixMyHPInfo()` to actually commit the MyHP plan registration.
- **`FUNC_CD_2`** (display/validation mode): Used in `actionAddMyHPInfo()` for validation-only operations and in `executeInitSvc()` for read-only service calls.

Passing the wrong code to the KKSV0006 mapper will produce incorrect results (displaying data instead of writing it, or vice versa).

### Date logic nuance
In `setHPInfoBean()`, the progress status (`PRG_STAT`) is determined by comparing the operational date (`UNYO_YMD`) with the selected use start date (`USE_STAYMD`). If they are equal, the status is set to "option setup complete" (5102); otherwise it is "option application in progress" (5101). This means the same registration can be processed either as a new application or as an option setup depending on the date — a subtle business rule that could cause unexpected behavior if dates are manipulated.

### Added capacity calculation
The `ADD_CAPA` field is computed as `selected_capacity - free_tier_capacity`. When the user selects the minimum (free) tier, `ADD_CAPA` is 0. When a higher tier is selected, the difference is positive and will be billed. This logic is only active when the pulldown index is not "0".

### Logging
Every public action method and every private service method ends with `JSYwebLog.println(JSYwebLog.DataBean_Dump, ...)` to dump the full DataBean state. This is useful for debugging but adds significant log volume — be aware when enabling this in production.

### Constant management
The class defines ~25 static constants with Japanese comments, many of which map to values in `JKKCommonConst`. This duplication of constants could become a maintenance burden if the common constants change — any change would need to be reflected both in `JKKCommonConst` and verified in this class.

### Service call complexity
`executeAddCfmSvc` invokes **22 distinct SC (service component) operations** in a single `invokeService` call. This makes it a complex, multi-participant business transaction. Adding a new step to the registration process requires understanding where in this chain it should be inserted and which other steps may need to be adjusted.

### Version history
- **v1.00** (2011/03/30): New creation by Fuji Tsutomu.
- **v3.00** (2012/03/15): Date field initial display support by Morimoto.
- **v4.00** (2012/10/16): Progress compensation item editing support by Kiyosaki.
- **v4.01** (2013/01/11): Migration date-to-system date-stamp setting by Tsuruya.
- **v4.02** (2013/01/28): Cancel SOD issuance support by Kiyosaki.
- **v5.00** (2013/06/18): Progress scheme migration date/time stamp support by Kiyosaki.
