#892: AuftragDao.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/AuftragDao.kt

Type: Spring @Service — Data Access Object

Package: org.projectforge.business.fibu

Full path: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/AuftragDao.kt

644 lines · 481 code · 93 comments · 70 blank

The primary data access object for AuftragDO (orders/quotes). Extends BaseDao<AuftragDO> and provides comprehensive CRUD operations, advanced filtering (by status, position type, payment type, user assignment, project, date ranges), validation during insert/modify, email notifications, history loading, and integration with the AuftragsCache. Responsible for the "to be invoiced" logic and multi-level order position filtering.

Class Definition

@Service
open class AuftragDao : BaseDao<AuftragDO>(AuftragDO::class.java)

Injected Dependencies

DependencyTypeNotes
auftragsCacheAuftragsCacheNot autowired (cyclic dependency); set via @PostConstruct in AuftragsCache
configurationServiceConfigurationServiceCheck if mail is configured
flatHistoryFormatServiceFlatHistoryFormatServiceHistory entry retrieval for notifications
kundeDaoKundeDaoCustomer resolution
projektDaoProjektDaoProject resolution
sendMailSendMailEmail notification delivery
taskDaoTaskDaoTask resolution for positions
userDaoUserDaoContact person resolution

Key Operations

Query & Selection

select(filter, checkAccess) — The core query method, overridden from BaseDao. Builds a complex QueryFilter supporting:

Validation: onInsertOrModify(obj, operationType)

Enforces business rules before persisting:

  1. nummer must not be null
  2. status must not be null or OPTIONAL
  3. On insert: nummer must be the next sequential number (no gaps)
  4. On update: nummer must not conflict with another existing order
  5. At least one position must exist
  6. Trailing empty positions (id=null, isEmpty=true) are removed from the end (but the first position is never removed)
  7. Each position's vollstaendigFakturiert flag is checked via checkVollstaendigFakturiert()
  8. UI status is serialized to XML and stored in uiStatusAsXml
  9. Trailing empty payment schedules are pruned
  10. validateDatesInPaymentScheduleWithinPeriodOfPerformanceOfPosition() — ensures all payment schedule dates fall within the position's period of performance (plus 3 months tolerance for the end date)
  11. validateAmountsInPaymentScheduleNotGreaterThanNetSumOfPosition() — sum of all payment schedule amounts for a position must not exceed the position's net sum

Number Management

Notification: sendNotificationIfRequired(auftrag, operationType, requestUrl)

Sends an HTML email notification to the contact person when an order is created/modified/deleted. Uses Groovy template mail/orderChangeNotification.html. Includes up to 10 most recent history entries. Returns false if mail is not configured, no contact person is assigned, or the contact person lacks SELECT access.

History Integration

Lookup Methods

Setter Helpers

Methods setContactPerson(), setTask(), setKunde(), and setProjekt() resolve related entities by ID using findOrLoad and set them on the order or position.

Additional Search Fields

The ADDITIONAL_SEARCH_FIELDS array extends Hibernate Search to index fields from related entities:

contactPerson.username, contactPerson.firstname, contactPerson.lastname,
kunde.name, projekt.name, projekt.kunde.name,
positionen.position, positionen.art, positionen.status,
positionen.titel, positionen.bemerkung, positionen.nettoSumme

Companion Object

ConstantValue
USER_RIGHT_IDUserRightId.PM_ORDER_BOOK
START_NUMBER1

Git History

868d6abb7 2025 -> 2026
4550ccc8a MonthlyEmployeeReport: show weekly net and gross hours. Fix select in AuftragDao.positionen.status
63081666f Source file headers: 2024-> 2025.
db2599ab8 History in orderbook, incoming/outgoing invoices and projects.
18bf92219 WIP: History entries handling. VisitorBookDao.
9c633d4ce AuftragDao/AuftragFilter: to-be-invoiced and fully-invoiced fixed.
ae2c04ee0 Migration stuff in progress... (all tests of all packages: OK).
(150+ commits total, spanning migration to Long IDs, Spring refactoring, Hibernate Search updates, etc.)