# CreateAccount

## Permission Scope

accountManagement

## Overview

createAccount creates a new ACTIVE GL account for a company. The account carries only company, code, name, account type, and status.

## Business Rules

- Company must exist and be ACTIVE
- Account code is required, must be numeric, and must be unique within the company
- Account name is required and must be non-empty
- Account type must be one of ASSET, LIABILITY, EQUITY, REVENUE, or EXPENSE
- Account is created in ACTIVE status

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Name and code valid?}
    B -->|No| C[Return validation error]
    B -->|Yes| D{Company exists?}
    D -->|No| E[Return company not found]
    D -->|Yes| D2{Company ACTIVE?}
    D2 -->|No| D3[Return company inactive]
    D2 -->|Yes| F{Code unique?}
    F -->|No| G[Return duplicate code]
    F -->|Yes| H[Create ACTIVE account]
    H --> I[Return account]
```

## External Dependencies

- [organization::getCompany](../../../organization/docs/query/GetCompany.md) - Validates that the referenced company exists and is ACTIVE

## Error Scenarios

- **COMPANY_NOT_FOUND**: Referenced company does not exist
- **COMPANY_INACTIVE**: Referenced company is not in ACTIVE status
- **DUPLICATE_ACCOUNT_CODE**: An account with the same code already exists in the company
- **NAME_REQUIRED**: Name is empty, whitespace-only, or not provided
- **INVALID_ACCOUNT_CODE**: Account code is not a valid numeric identifier

## Test Cases

- returns error when company does not exist
- returns error when company is not ACTIVE
- returns error when account code already exists in company
- returns error when account code is not numeric
- returns error when name is empty
- creates account in ACTIVE status
- passes custom fields through to insert
