#1000: KostZuweisungDO.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/KostZuweisungDO.kt Type: JPA Entity (DO) · Purpose: Cost assignment linking invoices/salaries to Kost1/Kost2 · Source: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/KostZuweisungDO.kt 266 lines · 190 code · 55 comments · 21 blank
Represents a cost assignment (KostZuweisung) — the allocation of invoice amounts or employee salary payments to specific cost centers (Kost1 and Kost2). Each assignment records a net amount and links to exactly one of: an outgoing invoice position, an incoming invoice position, or an employee salary entry.

Entity Design

FieldTypeDB ColumnDescription
indexShortINTArray index within the position's assignment list
nettoBigDecimal?DECIMAL(12,2)Net amount allocated to this cost center
kost1Kost1DO?FK kost1_fkCost center level 1 (ManyToOne, lazy)
kost2Kost2DO?FK kost2_fkCost center level 2 (ManyToOne, lazy)
rechnungsPositionRechnungsPositionDO?FK rechnungs_pos_fkOutgoing invoice position (nullable)
eingangsrechnungsPositionEingangsrechnungsPositionDO?FK eingangsrechnungs_pos_fkIncoming invoice position (nullable)
employeeSalaryEmployeeSalaryDO?FK employee_salary_fkEmployee salary entry (nullable)
commentString?VARCHAR(4000)Optional comment

Computed (Transient) Properties

PropertyTypeDescription
bruttoBigDecimalGross amount calculated from net + VAT of parent position
kost1IdLong?Shortcut for kost1.id
kost2IdLong?Shortcut for kost2.id
isEmptyBooleanTrue if netto is null or zero

Mutual Exclusion Constraint

A KostZuweisung must be assigned to exactly one financial object. The setter for each of the three references enforces mutual exclusivity at the Java level: setting rechnungsPosition throws if eingangsrechnungsPosition or employeeSalary is already set, and vice versa. The hasErrors() method validates that exactly one is assigned (returns an i18n error key if violated).

Persistence Details

Utility Methods

Source Code (abridged)

@Entity @Indexed @Table(name = "T_FIBU_KOST_ZUWEISUNG", ...)
open class KostZuweisungDO : DefaultBaseDO(), DisplayNameCapable {
    open var index: Short = 0
    open var netto: BigDecimal? = null
    open var kost1: Kost1DO? = null
    open var kost2: Kost2DO? = null
    open var rechnungsPosition: RechnungsPositionDO? = null
        set(value) { if (value != null && (eingangsrechnungsPosition != null
            || employeeSalary != null)) throw IllegalStateException(...) }

    val brutto: BigDecimal
        @Transient get() {
            val vat = when {
                rechnungsPosition != null -> rechnungsPosition!!.vat
                eingangsrechnungsPosition != null -> eingangsrechnungsPosition!!.vat
                else -> null
            }
            return CurrencyHelper.getGrossAmount(netto, vat)
        }
    // newClone(), hasErrors(), setAbstractRechnungsPosition(), etc.
}

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
0237d5eba Json: IdOnlySerializer and IdsOnlySerializer.
db2599ab8 History in orderbook, invoices and projects.
c8f8ed935 All entities FetchType.LAZY.
b04a74ffb DisplayHistoryEntry: new concept.
0b32a3f37 Migration stuff...
4c04cfd65 MAJOR-CHANGE! Integer id's to Long id's.
f984352a0 JsonBackReference/JsonManagedReference: KostZuweisungDO
ca27394ef Constants refactored.
b78b870bd ShortDisplayNameCapable -> DisplayNameCapable.
8675a1dbe Kotlin JPA entities declared open (lazy loading fix)
1cf12f943 Kostzuweisung: Infinite loop in json serialization fixed.
812b5b751 Heavy WIP: refactoring (Eingangs)Rechnung* perf killer
339e017b4 @PropertyInfo supported for getter methods.
3bd2b6e9d RechnungRest: Add position list
100cc30f0 KostZuweisungDO.java -> KostZuweisungDO.kt