private function validateOwnerInformation(FormInterface $form, $data)
 {
     if ($form->has('first_name') && !$data->getFirstName()) {
         $form->get('first_name')->addError(new FormError('Required.'));
     }
     if ($form->has('middle_name') && !preg_match('/[A-Za-z]/', $data->getMiddleName())) {
         $form->get('middle_name')->addError(new FormError('Enter least 1 letter.'));
     }
     if ($form->has('last_name') && !$data->getLastName()) {
         $form->get('last_name')->addError(new FormError('Required.'));
     }
     if ($form->has('street') && !$data->getStreet()) {
         $form->get('street')->addError(new FormError('Required.'));
     }
     if ($form->has('city') && !$data->getCity()) {
         $form->get('city')->addError(new FormError('Required.'));
     }
     if ($form->has('state') && !$data->getState()) {
         $form->get('state')->addError(new FormError('Required.'));
     }
     if ($form->has('estimated_income_tax') && !$data->getEstimatedIncomeTax()) {
         $form->get('estimated_income_tax')->addError(new FormError('Required.'));
     }
     // Choices validation
     if ($form->has('marital_status') && !in_array($data->getMaritalStatus(), Profile::getMaritalStatusChoices())) {
         $form->get('marital_status')->addError(new FormError('Required.'));
     }
     if ($form->has('annual_income') && !in_array($data->getAnnualIncome(), Profile::getAnnualIncomeChoices())) {
         $form->get('annual_income')->addError(new FormError('Required.'));
     }
     if ($form->has('liquid_net_worth') && !in_array($data->getLiquidNetWorth(), array_keys(Profile::getLiquidNetWorthChoices()))) {
         $form->get('liquid_net_worth')->addError(new FormError('Required.'));
     }
     if ($form->has('employment_type') && !in_array($data->getEmploymentType(), array_keys(Profile::getEmploymentTypeChoices()))) {
         $form->get('employment_type')->addError(new FormError('Required.'));
     }
     if ($form->has('birth_date')) {
         $birthDateData = $form->get('birth_date')->getData();
         if ($birthDateData && $birthDateData instanceof \DateTime) {
             $year = (int) $birthDateData->format('Y');
             if ($year < 1900) {
                 $form->get('birth_date')->addError(new FormError('year must start with 19 or 20 e.g. 1980'));
             }
         } else {
             $form->get('birth_date')->addError(new FormError('date format must be MM-DD-YYYY'));
         }
     }
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $client = $builder->getData();
     $this->factory = $builder->getFormFactory();
     /** @var \Wealthbot\UserBundle\Entity\User $ria */
     $ria = $client->getRia();
     $groups = array();
     foreach ($ria->getOwnGroups() as $group) {
         $groups[$group->getId()] = $group->getName();
     }
     $selectedGroupId = 0;
     $selectedGroup = $client->getGroups()->first();
     if ($selectedGroup) {
         $selectedGroupId = $selectedGroup->getId();
     }
     $builder->add('rebalancingLevel', 'choice', array('attr' => array('class' => 'input-medium'), 'choices' => Profile::$client_account_managed_choices, 'label' => 'Rebalancing Level: ', 'property_path' => 'profile.clientAccountManaged'));
     $builder->add('annualIncome', 'choice', array('attr' => array('class' => 'input-large'), 'choices' => Profile::getAnnualIncomeChoices(), 'empty_value' => 'Choose an Option', 'label' => 'Annual Income', 'property_path' => 'profile.annualIncome'))->add('estimatedIncomeTax', 'percent', array('attr' => array('class' => 'input-mini'), 'precision' => 0, 'required' => false, 'label' => 'Income tax bracket', 'property_path' => 'profile.estimatedIncomeTax'))->add('liquidNetWorth', 'choice', array('attr' => array('class' => 'input-large'), 'choices' => Profile::getLiquidNetWorthChoices(), 'empty_value' => 'Choose an Option', 'label' => 'Liquid Net Worth', 'property_path' => 'profile.liquidNetWorth'))->add('group', 'choice', array('attr' => array('class' => 'input-medium'), 'choices' => $groups, 'data' => $selectedGroupId, 'empty_value' => '', 'label' => 'Advisor Set: ', 'property_path' => false));
     $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPresetData'));
     $builder->addEventListener(FormEvents::BIND, array($this, 'onBindData'));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $data = $builder->getData();
     $isExist = $data->getId();
     $builder->remove('citezen')->remove('ssn_tin_1')->remove('ssn_tin_2')->remove('ssn_tin_3')->remove('is_senior_political_figure')->remove('senior_spf_name')->remove('senior_political_title')->remove('senior_account_owner_relationship')->remove('senior_country_office')->remove('is_publicly_traded_company')->remove('publicle_company_name')->remove('publicle_address')->remove('publicle_city')->remove('publicleState')->remove('is_broker_security_exchange_person')->remove('broker_security_exchange_company_name')->remove('compliance_letter_file')->add('email', 'email')->add('first_name', 'text', array('required' => false, 'disabled' => true))->add('middle_name', 'text', array('required' => false, 'disabled' => true))->add('last_name', 'text', array('required' => false, 'disabled' => true))->add('birth_date', 'date', array('widget' => 'single_text', 'format' => 'MM-dd-yyyy', 'required' => true, 'disabled' => true, 'attr' => array('class' => 'jq-date input-small')))->add('citizenship', 'choice', array('choices' => array(1 => 'Yes', 0 => 'No'), 'expanded' => true, 'multiple' => false, 'required' => false, 'property_path' => false, 'data' => $isExist ? 1 : null, 'label' => $data && $data->getMaritalStatus() == 'Married' ? 'Are you and your spouse both U.S. citizens?' : 'Are you a U.S. citizen?', 'disabled' => true))->add('marital_status', 'choice', array('choices' => Profile::getMaritalStatusChoices(), 'empty_value' => 'Choose an Option', 'required' => false))->add('phone_number', 'text', array('required' => false))->add('spouse', new ClientSpouseFormType())->add('annual_income', 'choice', array('choices' => Profile::getAnnualIncomeChoices(), 'empty_value' => 'Choose an Option', 'required' => false))->add('estimated_income_tax', 'percent', array('precision' => 0, 'required' => false, 'label' => 'What is your estimated income tax bracket?'))->add('liquid_net_worth', 'choice', array('choices' => Profile::getLiquidNetWorthChoices(), 'empty_value' => 'Choose an Option', 'required' => false));
     $formFactory = $builder->getFormFactory();
     $builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($formFactory) {
         $form = $event->getForm();
         $data = $event->getData();
         if ($data === null) {
             return;
         }
         if (isset($data['marital_status'])) {
             $form->remove('citizenship');
             $form->add($formFactory->createNamed('citizenship', 'choice', null, array('choices' => array(1 => 'Yes', 0 => 'No'), 'expanded' => true, 'multiple' => false, 'required' => false, 'property_path' => false, 'data' => isset($data['id']) ? 1 : null, 'label' => $data['marital_status'] == 'Married' ? 'Are you and your spouse both U.S. citizens?' : 'Are you a U.S. citizen?', 'disabled' => true)));
         }
     });
     $builder->addEventListener(FormEvents::BIND, array($this, 'changeProfileValidate'));
 }
 public function validate(FormEvent $event)
 {
     /** @var \Wealthbot\UserBundle\Entity\Profile $data */
     $data = $event->getData();
     $form = $event->getForm();
     if ($form->has('first_name') && !$data->getFirstName()) {
         $form->get('first_name')->addError(new FormError('Required.'));
     }
     if ($form->has('last_name') && !$data->getLastName()) {
         $form->get('last_name')->addError(new FormError('Required.'));
     }
     if ($form->has('street') && !$data->getStreet()) {
         $form->get('street')->addError(new FormError('Required.'));
     }
     if ($form->has('city') && !$data->getCity()) {
         $form->get('city')->addError(new FormError('Required.'));
     }
     if ($form->has('state') && !$data->getState()) {
         $form->get('state')->addError(new FormError('Required.'));
     }
     if ($form->has('estimated_income_tax') && !$data->getEstimatedIncomeTax()) {
         $form->get('estimated_income_tax')->addError(new FormError('Required.'));
     }
     // Choices validation
     if ($form->has('marital_status') && !in_array($data->getMaritalStatus(), Profile::getMaritalStatusChoices())) {
         $form->get('marital_status')->addError(new FormError('Required.'));
     }
     if ($form->has('annual_income') && !in_array($data->getAnnualIncome(), Profile::getAnnualIncomeChoices())) {
         $form->get('annual_income')->addError(new FormError('Required.'));
     }
     if ($form->has('liquid_net_worth') && !in_array($data->getLiquidNetWorth(), array_keys(Profile::getLiquidNetWorthChoices()))) {
         $form->get('liquid_net_worth')->addError(new FormError('Required.'));
     }
     if ($form->has('employment_type') && !in_array($data->getEmploymentType(), array_keys(Profile::getEmploymentTypeChoices()))) {
         $form->get('employment_type')->addError(new FormError('Required.'));
     }
     if ($form->has('birth_date')) {
         $birthDateData = $form->get('birth_date')->getData();
         if ($birthDateData && $birthDateData instanceof \DateTime) {
             $year = (int) $birthDateData->format('Y');
             if ($year < 1900) {
                 $form->get('birth_date')->addError(new FormError('year must start with 19 or 20 e.g. 1980'));
             }
         } else {
             $form->get('birth_date')->addError(new FormError('date format must be MM-DD-YYYY'));
         }
     }
     if ($form->has('spouse') && $data->getMaritalStatus() === Profile::CLIENT_MARITAL_STATUS_MARRIED) {
         /** @var ClientAdditionalContact $spouse */
         $spouse = $form->get('spouse')->getData();
         $phoneNum = str_replace(array(' ', '-', '(', ')'), '', $data->getPhoneNumber());
         $spouseValidator = new ClientSpouseFormValidator($form->get('spouse'), $data->getUser()->getSpouse());
         $spouseValidator->validate();
         $spouse->setSpouseFirstName($data->getFirstName());
         $spouse->setSpouseMiddleName($data->getMiddleName());
         $spouse->setSpouseLastName($data->getLastName());
         $spouse->setSpouseBirthDate($data->getBirthDate());
         $spouse->setState($data->getState());
         $spouse->setCity($data->getCity());
         $spouse->setStreet($data->getStreet());
         $spouse->setZip($data->getZip());
         $spouse->setPhoneNumber($phoneNum);
         $spouse->setType(ClientAdditionalContact::TYPE_SPOUSE);
         $spouse->setMaritalStatus(Profile::CLIENT_MARITAL_STATUS_MARRIED);
     }
 }