/**
  * Validate form data
  *
  * @param FormInterface $form
  * @param ClientAccount $data
  */
 private function validate(FormInterface $form, ClientAccount $data)
 {
     $group = $form->get('group')->getData();
     if ($data) {
         $data->setClient($this->client);
         if ($group == AccountGroup::GROUP_EMPLOYER_RETIREMENT) {
             $data->setMonthlyDistributions(null);
             $data->setSasCash(null);
             if (floatval($data->getValue()) < 50000) {
                 $form->get('value')->addError(new FormError('Minimum value must be $50,000 for retirement plans.'));
             }
             if ($form->get('plan_provider')->getData()) {
                 $financialInstitution = $data->getFinancialInstitution();
                 $data->setFinancialInstitution($form->get('plan_provider')->getData() . " (" . $financialInstitution . ")");
             }
         }
         if ($this->validateAdditionalFields && $form->has('owners')) {
             if ($data->getTypeName() == 'Joint Account') {
                 $ownerTypes = $form->get('owners')->get('owner_types')->getData();
                 if (!is_array($ownerTypes) || count($ownerTypes) !== 2) {
                     $form->get('owners')->get('owner_types')->addError(new FormError('You should select two owners of the account.'));
                 }
                 if ($form->get('owners')->has('other_contact')) {
                     /** @var ClientAdditionalContact $otherContact */
                     $otherContact = $form->get('owners')->get('other_contact')->getData();
                     if (!$otherContact->getFirstName() || trim($otherContact->getFirstName() == '')) {
                         $form->get('owners')->get('other_contact')->get('first_name')->addError(new FormError('Required.'));
                     }
                     if (!$otherContact->getMiddleName() || trim($otherContact->getMiddleName() == '')) {
                         $form->get('owners')->get('other_contact')->get('middle_name')->addError(new FormError('Required.'));
                     }
                     if (!$otherContact->getLastName() || trim($otherContact->getLastName() == '')) {
                         $form->get('owners')->get('other_contact')->get('last_name')->addError(new FormError('Required.'));
                     }
                     if (!$otherContact->getRelationship() || trim($otherContact->getRelationship() == '')) {
                         $form->get('owners')->get('other_contact')->get('relationship')->addError(new FormError('Required.'));
                     }
                 }
             } elseif ($this->client->isMarried()) {
                 $ownerType = $form->get('owners')->get('owner_types')->getData();
                 $choices = ClientAccountOwner::getOwnerTypeChoices();
                 unset($choices[ClientAccountOwner::OWNER_TYPE_OTHER]);
                 if (!$ownerType || !in_array($ownerType, $choices)) {
                     $form->get('owners')->get('owner_types')->addError(new FormError('Select owner of the account.'));
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Get owner_type
  *
  * @return string
  */
 public function getOwnerType()
 {
     return parent::getOwnerType();
 }