# ProfitCenter

## Description

ProfitCenter represents a discrete business segment — such as a product line, regional division, or service line — for which management can independently evaluate profitability through internal profit and loss reporting. Each profit center carries a code, name, optional description, optional responsible person, company scope, validity period (valid-from/to), and a status following a lifecycle from DRAFT through ACTIVE to INACTIVE. Revenue and cost transactions posted in the finance-ledger are tagged with profit center assignments, enabling aggregation of income and expenses at the profit center level. Profit centers are organized into hierarchical groupings via ProfitCenterHierarchy and are deliberately decoupled from the organizational hierarchy to allow flexible, cross-cutting profitability views.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createProfitCenter
    Draft --> Draft: updateProfitCenter
    Draft --> Active: activateProfitCenter
    Active --> Active: updateProfitCenter (limited fields)
    Active --> Inactive: deactivateProfitCenter
    Inactive --> Active: reactivateProfitCenter
    Draft --> [*]: deleteProfitCenter
```

### Command Definitions

- [createProfitCenter](../commands/CreateProfitCenter.md) - Create a new profit center in DRAFT status with code, name, and validity period
- [updateProfitCenter](../commands/UpdateProfitCenter.md) - Update mutable fields of a profit center (name, description, responsible person)
- [activateProfitCenter](../commands/ActivateProfitCenter.md) - Activate a DRAFT profit center, making it available for transaction tagging
- [deactivateProfitCenter](../commands/DeactivateProfitCenter.md) - Deactivate an ACTIVE profit center, preventing new transaction assignments
- [reactivateProfitCenter](../commands/ReactivateProfitCenter.md) - Reactivate an INACTIVE profit center back to ACTIVE status
- [deleteProfitCenter](../commands/DeleteProfitCenter.md) - Delete a DRAFT profit center and its hierarchy assignment
- [assignProfitCenterToHierarchyNode](../commands/AssignProfitCenterToHierarchyNode.md) - Assign or reassign a profit center to a hierarchy node

### Query Definitions

- [GetProfitCenter](../queries/GetProfitCenter.md) - Retrieve a profit center by id
- [ListProfitCenters](../queries/ListProfitCenters.md) - List profit centers with filters (status, company, validity period)

### Models

- ProfitCenter

### Invariants

- Profit center can only be created in DRAFT status
- Profit center requires a unique code within the company scope
- Profit center requires a name
- Profit center must reference a valid companyId; the company must be in ACTIVE status
- Valid-from date is required; valid-to date is optional
- Valid-to date, when specified, must be on or after the valid-from date
- Profit center code cannot be changed after activation
- Only DRAFT profit centers can be deleted; ACTIVE and INACTIVE profit centers cannot be deleted
- Only ACTIVE profit centers within their validity period can receive transaction assignments
- Transactions cannot be assigned to a DRAFT or INACTIVE profit center
- Transactions cannot be assigned to a profit center outside its validity period (before valid-from or after valid-to)
- Activating an already ACTIVE profit center fails with an invalid status transition error
- Deactivating a DRAFT profit center fails with an invalid status transition error
- Profit centers are scoped to a company; profit centers from different companies are fully isolated

### Relationships

- **References Company**: Each profit center is scoped to a Company via companyId (organization module)
- **References ProfitCenterHierarchyNode**: Each profit center can be assigned to a ProfitCenterHierarchyNode within a hierarchy
- **References User**: Each profit center optionally references a responsible person via responsiblePersonId (user-management module)
