#996: Kost2DO.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2DO.kt Type: JPA Entity (DO) · Purpose: Kost2 cost center entity with 8-digit number + cost type · Source: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2DO.kt 252 lines · 149 code · 78 comments · 25 blank
Represents a Kost2 cost center — the finer-grained cost entity (compared to Kost1). A Kost2 is identified by a combination of 3 numeric components (Nummernkreis, Bereich, Teilbereich = 6 digits) and a Kost2Art (cost type, 2 digits). Each Kost2 belongs to a project and has a specific cost type classification.

Entity Design

FieldTypeDB ColumnDescription
kostentraegerStatusKostentraegerStatus?VARCHAR(30)ACTIVE, NONACTIVE, or ENDED
nummernkreisIntINTFirst digit (1-9)
bereichIntINTDigits 2-4; for 5.xxx this is the customer number
teilbereichIntINTDigits 5-6
kost2ArtKost2ArtDO?FK kost2_art_idManyToOne to cost type (2-digit classification)
workFractionBigDecimal?PRECISION(10,5)Work allocation fraction
descriptionString?VARCHAR(4000)Description
commentString?VARCHAR(4000)Optional comment
projektProjektDO?FK projekt_idAssociated project (lazy-loaded)

Computed (Transient) Properties

PropertyTypeDescription
effectiveKostentraegerStatusKostentraegerStatus?Inherits ENDED from project if project is ENDED or deleted
nummerIntComputed 8-digit integer (via KostFormatter.getKostAsInt)
formattedNumberStringFormatted as #.###.##.## (indexed for search)
rawNumberStringString8-digit compact string for search indexing
toolTipStringFormatted tooltip via OldKostFormatter

Named Queries

NamePurpose
FIND_BY_NK_BEREICH_TEILBEREICH_KOST2ARTFind by all 4 components
FIND_OTHER_BY_NK_BEREICH_TEILBEREICH_KOST2ARTFind duplicate (exclude self) for uniqueness check
FIND_ACTIVES_BY_NK_BEREICH_TEILBEREICHFind active entries by 6-digit prefix

Virtual Status Inheritance

The effectiveKostentraegerStatus property implements a key design pattern (introduced in commit 8239a53ee): if the linked Projekt has status ENDED or is deleted, the Kost2 is treated as ENDED regardless of its own status. This avoids data inconsistency when projects are closed.

Persistence Details

Source Code (abridged)

@Entity @Indexed @Table(name = "T_FIBU_KOST2", ...)
open class Kost2DO : DefaultBaseDO(), Comparable<Kost2DO>, DisplayNameCapable {
    open var kostentraegerStatus: KostentraegerStatus? = null

    val effectiveKostentraegerStatus: KostentraegerStatus?
        get() {
            val projektRef = PfCaches.instance.getProjektIfNotInitialized(projekt) ?: projekt
            if (projektRef != null &&
                (projektRef.status == ProjektStatus.ENDED || projektRef.deleted))
                return KostentraegerStatus.ENDED
            return kostentraegerStatus
        }

    open var nummernkreis: Int = 0
    open var bereich: Int = 0
    open var teilbereich: Int = 0
    open var kost2Art: Kost2ArtDO? = null
    open var projekt: ProjektDO? = null
    // ... formattedNumber, rawNumberString, toolTip computed properties
}

Git History

868d6abb7 2025 -> 2026
5c652782f AbstractTestBase initializes PfCaches.
dca4456f7 Fixed for test-cases.
8239a53ee Kost2: Virtuelle Status-Vererbung von ProjektDO
38e843800 CostSearch: search for plain number string.
63081666f Source file headers: 2024-> 2025.
0237d5eba Json: IdOnlySerializer and IdsOnlySerializer.
98555d5d8 Bugfix: search for numbers.
b3782c8a8 Migration stuff...
c8f8ed935 All entities FetchType.LAZY.
4c04cfd65 MAJOR-CHANGE! Integer id's to Long id's.
a1cf6f591 Code Cleanup
b78b870bd ShortDisplayNameCapable -> DisplayNameCapable
8675a1dbe Kotlin JPA entities declared open (lazy loading fix)
252b28955 JsonCreator for deserialization from Int
d849a79cc JsonCreator for deserialization from Number
0de418e75 DTO Tenant added to BaseDTO.
6d1f7a7cd Kost2DO.java -> Kost2DO.kt