#917: EingangsrechnungDao.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/EingangsrechnungDao.kt Type: DAO (Data Access Object) / Spring Service
Package: org.projectforge.business.fibu
Path: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/EingangsrechnungDao.kt
Author: Kai Reinhard (k.reinhard@micromata.de) 270 lines · 185 code · 52 comments · 33 blank

DAO for EingangsrechnungDO (incoming invoices). Extends BaseDao<EingangsrechnungDO> providing CRUD, filtered listing, history merging, and payment-state filtering. Collaborates with EingangsrechnungCache for high-performance payment status queries and CurrencyConversionService for multi-currency statistics.

Architecture

Inheritance

Dependencies

DependencyRole
EingangsrechnungCacheCached payment-status lookup via RechnungJdbcService
KontoDaoSets account (Konto) on incoming invoice records
CurrencyConversionServiceCurrency conversion for statistics
ConfigurationServiceSystem default currency for statistics

Access Control

Guarded by UserRightId.FIBU_EINGANGSRECHNUNGEN, set in init.

Key Methods

Year Range

The years property executes a named query EingangsrechnungDO.SELECT_MIN_MAX_DATE (selecting min(datum) and max(datum)) and converts the result to an IntArray via getYearsByTupleOfLocalDate().

Statistics

buildStatistik(list) creates an EingangsrechnungsStatistik accumulator and adds each invoice to it. Before processing, it initializes the static currencyConversionService and configurationService on the shared AbstractRechnungsStatistik base class (companion object dependency injection pattern).

Konto Assignment

setKonto(eingangsrechnung, kontoId) looks up the KontoDO via kontoDao.findOrLoad() and assigns it. If kontoId is null, the konto is set to null.

Filtered Listing (select)

Wraps the filter in an EingangsrechnungListFilter if needed. Creates a QueryFilter with date restrictions and payment type filters. Orders by datum DESC, then kreditor DESC. After querying, applies payment-state post-filtering based on RechnungInfo from the cache:

Lifecycle Hooks

HookBehavior
afterLoad(obj)Sets obj.info from cache via rechnungCache.ensureRechnungInfo(obj)
onInsertOrModify(obj, opType)Delegates to AuftragAndRechnungDaoHelper.onSaveOrModify(); scales zahlBetrag to 2 decimal places; calls recalculate(); ensures at least one position exists (throws UserException if empty); removes trailing empty positions; writes UI status to XML.
afterInsertOrModify(obj, opType)Calls rechnungCache.update(obj) to refresh the cache

History Merging

addOwnHistoryEntries() iterates over all positions and their cost assignments (KostZuweisungDO), merging each child's history into the parent context. getHistoryPropertyPrefix() provides contextual prefixes: position numbers and "kost #N" for cost assignments.

Additional Queries

MethodDescription
findNewestByKreditor(kreditor)Finds the most recent (by created desc) non-deleted invoice for a given creditor
getByDateRange(from, until)Finds all non-deleted invoices in a date range, sorted by date and creditor. Used for import reconciliation.
contains(idSet, entry)Checks if any position id is in the given set (for bulk selection)

Additional Search Fields

Includes "positionen.text" in search queries, allowing full-text search across invoice line items.

Additional History Search DOs

Includes EingangsrechnungsPositionDO for cross-entity history searches.

Autocompletion

Enabled for "kreditor" (creditor name).

Git History

868d6abb7 2025 -> 2026
6be9c2b84 WIP: currency conversion with Claude Code.
363d3b836 WIP: Import of creditor invoices.
63081666f Source file headers: 2024-> 2025.
db2599ab8 History in orderbook, incming/outgoing invoices and projects.
18bf92219 WIP: History entries handling. VisitorBookDao.
b71b5073d Migration stuff in progress... (all tests of all packages: OK).
bbc198d03 Migration stuff in progress... (all tests of all packages: OK).
ba2479571 Migration stuff in progress...
b47c21af6 Refactored caching and calculations with invoices (not yet finished)
9e3c523c7 Migration stuff in progress... (all tests of all packages: OK).
c97135a57 Migration stuff in progress...
d18c899b5 Refactoring of history entries, FlatDisplayHistoryEntries and DisplayHistoryEntries...
b79a1edca Migration stuff in progress... (all tests of all packages: OK).
d67bce18b Migration stuff in progress...