#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
| Field | Type | DB Column | Description |
index | Short | INT | Array index within the position's assignment list |
netto | BigDecimal? | DECIMAL(12,2) | Net amount allocated to this cost center |
kost1 | Kost1DO? | FK kost1_fk | Cost center level 1 (ManyToOne, lazy) |
kost2 | Kost2DO? | FK kost2_fk | Cost center level 2 (ManyToOne, lazy) |
rechnungsPosition | RechnungsPositionDO? | FK rechnungs_pos_fk | Outgoing invoice position (nullable) |
eingangsrechnungsPosition | EingangsrechnungsPositionDO? | FK eingangsrechnungs_pos_fk | Incoming invoice position (nullable) |
employeeSalary | EmployeeSalaryDO? | FK employee_salary_fk | Employee salary entry (nullable) |
comment | String? | VARCHAR(4000) | Optional comment |
Computed (Transient) Properties
| Property | Type | Description |
brutto | BigDecimal | Gross amount calculated from net + VAT of parent position |
kost1Id | Long? | Shortcut for kost1.id |
kost2Id | Long? | Shortcut for kost2.id |
isEmpty | Boolean | True 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
- Mapped to
T_FIBU_KOST_ZUWEISUNG
- Three unique constraints, one for each financial object type: (index, rechnungs_pos_fk, kost1_fk, kost2_fk), (index, eingangsrechnungs_pos_fk, kost1_fk, kost2_fk), (index, employee_salary_fk, kost1_fk, kost2_fk)
- Five indexes for FK-based query performance
- Extends
DefaultBaseDO, implements DisplayNameCapable
@JsonBackReference on rechnungsPosition and eingangsrechnungsPosition prevents infinite recursion during JSON serialization
@JsonSerialize(using = IdOnlySerializer) on all ManyToOne references for compact API responses
Utility Methods
setAbstractRechnungsPosition(position) — polymorphic setter dispatching by type
newClone() — creates a deep copy (without IDs) for invoice cloning
- Equals/hashCode based on index + parent position IDs (business key across all three parent types)
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