# Business Logic - KKW00101SFLogic.checkKKW00105Error() [588 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00101SF.KKW00101SFLogic` |
| Layer | Service (Logic layer - web view business logic) |
| Module | `KKW00101SF` (Package: `eo.web.webview.KKW00101SF`) |

## 1. Role

### KKW00101SFLogic.checkKKW00105Error()

This method is the central error-checking and data-preparation routine for the KKW00105 "Contract New Registration Confirmation" screen in K-Opticom's customer management system. It validates all form fields entered by the user on the service contract new registration confirmation screen, performing required-field checks, length validations, date-integrity checks (including calendar conversion between Japanese era dates and Gregorian dates), and future-date boundary checks.

The method branches its validation logic based on the **contract type** -- applying individual (KOJIN / 個人) customer checks when the contractee type code equals "1", and corporate (HOJIN / 法人) customer checks otherwise. For individual customers, it also evaluates the **application type** (new registration, service addition) and the **simple plan flag** to determine whether guardian information is required (minors under 18 must provide a guardian).

Beyond pure validation, it sets up screen state -- zero-padding date fields, initializing input assistance data, dispatching address and mobile delivery data, querying the KKSV0084 service component to detect daytime-contact-phone errors, and performing post-processing address synchronization. The method always returns `true` (indicating the validation pass completed), but errors are accumulated in a screen-specific error info array and the UI tab state is switched to the error tab when violations are detected.

**Design patterns used:**

- **Routing/Dispatch**: Branches on `KEISHA_TYPE_CD` to select individual vs. corporate validation paths
- **Delegation**: Delegates to multiple specialized helper methods for address validation, phone checks, and guardian data checks
- **State Setup**: Prepares the data bean for downstream processing by setting tab display state, zero-padding dates, and syncing address information

**Branch summary:**

1. **Individual customer path** (KEISHA_TYPE_CD = "1"): Validates contractee name, kana, birthdate (including WAREKI/SEIREKI conversion and age calculation), priority contact phone (reflected from new application if applicable), and required contact fields (postcode, address, phone).
2. **Corporate customer path** (KEISHA_TYPE_CD != "1"): Validates corporate name, kana, and representative name/kana length constraints.
3. **Common checks** (both paths): Validates required fields (postcode, address, phone), equipment delivery address fields (if applicable), age requirements (guardian checks for minors), and calls KKSV0084 service to detect daytime contact errors.
4. **Simple plan check**: If the customer is on a simple plan and under 18, an error is flagged.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["checkKKW00105Error(params)"])

    START --> S1["Set nowGamenId to KKW00105"]
    S1 --> S2["Get dataBean from formBean"]
    S2 --> S3["Clear pageErrInfo KKW00105_ERR_INFO"]
    S3 --> S4["Set TAB_KEI_DSP_STAT to empty string"]
    S4 --> S5["Pad dates with zero padBf"]
    S5 --> S6["Set KEISHA_SCREEN_DSP_FLG to ZM 2"]
    S6 --> S7["Call initInputHojoKKW00105"]
    S7 --> BR0{isCallSetSameAddress}

    BR0 -->|false| S8["Call setSameAddress ADDRESS_RIYOBASHO"]
    BR0 -->|true| S8S["Skip setSameAddress"]
    S8 --> S9["Call setMobileSohusShs"]
    S8S --> S9

    S9 --> S10["Get opeDate from dataBean"]
    S10 --> BR1{KEISHA_TYPE_CD equals KOJIN 1}

    BR1 -->|true Individual| IND["Individual customer checks"]
    BR1 -->|false Corporate| CORP["Corporate customer checks"]

    IND --> I1{MSKM_FLG equals SHINKI 1}
    I1 -->|true New app| I2["Reflect priority contact phone"]
    I1 -->|false| I3["Skip phone reflect"]
    I2 --> I3

    I3 --> I4["Check CUST_NM empty"]
    I4 --> I5["Check CUST_NM length > KEISHA_LENGTH 45"]
    I5 --> I6["Check CUST_KANA empty"]
    I6 --> I7["Check CUST_KANA length > KEISHA_LENGTH 45"]
    I7 --> I8["Get KEISHA_BIRTHD Y/M/D"]
    I8 --> I9["Call checkBirthdRan birthdate validation"]
    I9 --> I10["Get pullDownCode KEISHA_BIRTHD_WAREKI"]
    I10 --> I11{WAREKI equals SEIREKI 0}
    I11 -->|no lunar| I12["Convert WAREKI to SEIREKI via getAdCalendar"]
    I11 -->|yes| I13["Use year month day directly"]
    I12 --> I14["Check ymd validDate + 8 digits"]
    I13 --> I14
    I14 --> I15{validDate + 8 digits}
    I15 -->|yes| I16{ymd compareTo opeDate >= 1}
    I15 -->|no| I17["Skip age calc"]
    I16 -->|future error| I18["Add future date errors"]
    I16 -->|valid| I19["Calculate keishaAge via getAge"]
    I18 --> I20["Check KEISHA_YUSEN_TELNO empty"]
    I19 --> I20
    I17 --> I20
    I20 --> I21{isNewMskm}
    I21 -->|true New| I22["Add new app error EKB0010_TW"]
    I21 -->|false Addition| I23["Add service addition error EKBD170__Q"]
    I22 --> I24["Required field checks postcode address phone"]
    I23 --> I24
    I24 --> IND_END["End individual block"]

    CORP --> C1["Check HOJIN_NM empty"]
    C1 --> C2["Check HOJIN_NM length > 45"]
    C2 --> C3["Check HOJIN_KANA empty"]
    C3 --> C4["Check HOJIN_KANA length > 45"]
    C4 --> C5["Check DIHYSHA_NM length > 45"]
    C5 --> C6["Check DIHYSHA_KANA length > 45"]
    C6 --> CORP_END["End corporate block"]

    IND_END --> R1["Check KEISHA_PCD_BF empty"]
    R1 --> R2["Check KEISHA_PCD_AF empty"]
    R2 --> R3["Check KEISHA_BNCHIGO empty"]
    R3 --> R4["Check KEISHA_TELNO empty"]
    R4 --> R5{isDspKeishaKikiSohusNew}

    R5 -->|true Equipment| R6["Check delivery address fields"]
    R5 -->|false| R7["Skip delivery checks"]
    R6 --> R7

    R7 --> R8["Get KEISHA_AGE from dataBean"]
    R8 --> R9{keishaAge empty}
    R9 -->|yes| R10["Default keishaAge to 018"]
    R9 -->|no| R11{keishaAge length != 3}
    R10 --> R12["Check isSimplePlan and age < 18"]
    R11 -->|yes| R13["fillZero keishaAge to 3"]
    R11 -->|no| R12
    R13 --> R12

    R12 --> B1{KEISHA_TYPE_CD equals KOJIN 1}
    B1 -->|true| B2{MSKM_FLG NOT equals TSUIKA}
    B2 -->|true| B3{NOT isSimplePlan}
    B3 -->|true| B4{keishaAge <= 018}
    B4 -->|under 18| SKSHA["Underage guardian checks"]
    B4 -->|18+| R14["End age block"]
    B3 -->|simple plan| R14
    B2 -->|addition| R14
    B1 -->|corporate| R14

    SKSHA --> G1["Check SKSHA_NM empty"]
    G1 --> G2["Check SKSHA_NM length > KEISHA_LENGTH 45"]
    G2 --> G3["Check SKSHA_KANA empty"]
    G3 --> G4["Check SKSHA_KANA length > KEISHA_LENGTH 45"]
    G4 --> G5["Check SKSHA_TELNO empty"]
    G5 --> G6["requireComboValCheck SKSHA_BIRTHD_WAREKI"]
    G6 --> G7["Get sYear sMonth sDay"]
    G7 --> G8["checkBirthdRan guardian birthdate"]
    G8 --> G9["getPullDownCode SKSHA_BIRTHD_WAREKI"]
    G9 --> G10{WAREKI equals SEIREKI 0}
    G10 -->|no| G11["Convert WAREKI to SEIREKI"]
    G10 -->|yes| G12["Use Y+M+D directly"]
    G11 --> G13["If half-width getAdCalendar"]
    G12 --> G14["Check sYmd validDate + 8 digits"]
    G13 --> G14
    G14 --> G15{sYmd valid + 8 digits}
    G15 -->|yes| G16{sYmd compareTo opeDate >= 1}
    G15 -->|no| G17["Skip age calc"]
    G16 -->|future| G18["Add future date errors"]
    G16 -->|valid| G19["Calculate skshaAge"]
    G18 --> G20["requireComboValCheckTkck ZOKUGARA_CD"]
    G19 --> G20
    G17 --> G20
    G20 --> G21["Check SKSHA_ZOKUGARA_OTHER regex"]
    G21 --> G22["Loop char check half-width en-num-kana"]
    G22 --> G23["End guardian block"]

    G23 --> AD["Call adCheckKKW00105Error"]
    AD --> MM["Create KKSV0084_KKSV0084OPDBMapper"]
    MM --> SS["setKKSV008401CC"]
    SS --> SVC["callService KKSV008401CC"]
    SVC --> BR2{result}
    BR2 -->|false| DAY["daytimeRrskTelnoErrDiv = getDaytimeRrskTelnoErrDiv"]
    BR2 -->|true| DS["Skip daytime error"]
    DAY --> DS

    DS --> POST{isCallSetSameAddress}
    POST -->|false| P1["setSameKeishaInfoForPayway"]
    POST -->|true| P2["Skip post processing"]
    P1 --> P3{checkAllGamen}
    P2 --> P4["Skip post processing"]
    P3 -->|true all screens| P5["setSameAddress otherAdCheck false"]
    P3 -->|false| P6["setSameAddress otherAdCheck true"]
    P5 --> P7["End address post"]
    P6 --> P7
    P4 --> P7

    P7 --> BR3{daytimeRrskTelnoErrDiv != 0}
    BR3 -->|yes| CE["convertErrorInfoKKW00105"]
    BR3 -->|no| REST["Restore nowGamenId"]
    CE --> BR4{errDiv & 0x02}
    BR4 -->|yes| D1["Add PHS/keitai error"]
    BR4 -->|no| BR5{errDiv & 0x01}
    D1 --> BR5
    BR5 -->|yes| D2["Add phone number error"]
    BR5 -->|no| REST
    D2 --> REST
    REST --> END(["return true"])

    style START fill:#e1f5fe
    style END fill:#e1f5fe
```
