diff --git a/src/BusProNet/DataProcessor/PersonalDataSynchronizer.php b/src/BusProNet/DataProcessor/PersonalDataSynchronizer.php index b0b46b2..7d9d2c4 100644 --- a/src/BusProNet/DataProcessor/PersonalDataSynchronizer.php +++ b/src/BusProNet/DataProcessor/PersonalDataSynchronizer.php @@ -23,6 +23,9 @@ class PersonalDataSynchronizer * Processes all active participants (status 'F' or 'A'). Skips canceled participants (status 'S'). * Updates all personal data fields and communication information. * + * For the applicant (index 0), missing mandatory fields are filled with defaults + * to handle company applicants created by travel agencies. + * * IMPORTANT: The applicant's address must never be modified. This method updates * participant addresses independently to ensure applicant data remains intact. * @@ -37,6 +40,11 @@ class PersonalDataSynchronizer continue; } + // Fill missing mandatory fields for applicant (company bookings by travel agencies) + if (0 === $participant->index) { + $this->fillMissingMandatoryFields($participant); + } + $bookingData->participants[$participant->index]->firstName = $participant->firstName; $bookingData->participants[$participant->index]->name = $participant->lastName; $bookingData->participants[$participant->index]->dateOfBirth = $participant->dateOfBirth; @@ -68,4 +76,34 @@ class PersonalDataSynchronizer } } } + + /** + * Fills missing mandatory fields with defaults for company applicants. + * + * Travel agencies often create bookings with company data as the applicant, + * which lacks personal data fields. These fields are mandatory for the BPN + * API, so we fill them with sensible defaults. + */ + private function fillMissingMandatoryFields(ParticipantDto $participant): void + { + if (null === $participant->firstName || '' === $participant->firstName) { + $participant->firstName = 'Anmelder'; + } + + if (null === $participant->gender || '' === $participant->gender) { + $participant->gender = 'D'; + } + + if (null === $participant->nationality || '' === $participant->nationality) { + $participant->nationality = 'D'; + } + + if (null === $participant->dateOfBirth) { + $participant->dateOfBirth = new \DateTimeImmutable('-20 years'); + } + + if (null === $participant->mobile || '' === $participant->mobile) { + $participant->mobile = '12345'; + } + } }