/**
  * Create and save new client account owner
  *
  * @param ClientAccount $account
  * @param $ownerType
  * @return ClientAccountOwner
  */
 private function createAccountOwnerByType(ClientAccount $account, $ownerType)
 {
     $owner = new ClientAccountOwner();
     $owner->setOwnerType($ownerType);
     $owner->setAccount($account);
     switch ($ownerType) {
         case ClientAccountOwner::OWNER_TYPE_SELF:
             $owner->setClient($account->getClient());
             break;
         case ClientAccountOwner::OWNER_TYPE_SPOUSE:
             $owner->setContact($account->getClient()->getSpouse());
             break;
         case ClientAccountOwner::OWNER_TYPE_OTHER:
             $contactData = $this->getOtherContact();
             $existContact = $this->em->getRepository('WealthbotClientBundle:ClientAdditionalContact')->findOneBy(array('client_id' => $account->getClientId(), 'first_name' => $contactData->getFirstName(), 'middle_name' => $contactData->getMiddleName(), 'last_name' => $contactData->getLastName(), 'relationship' => $contactData->getRelationship(), 'type' => ClientAccountOwner::OWNER_TYPE_OTHER));
             if ($contactData->getId() && !$existContact) {
                 $contact = new ClientAdditionalContact();
                 $contact->setFirstName($contactData->getFirstName());
                 $contact->setMiddleName($contactData->getMiddleName());
                 $contact->setLastName($contactData->getLastName());
                 $contact->setRelationship($contactData->getRelationship());
                 $contact->setType(ClientAccountOwner::OWNER_TYPE_OTHER);
             } elseif (!$contactData->getId() && $existContact) {
                 $contact = $existContact;
             } else {
                 $contact = $contactData;
             }
             $contact->setClient($account->getClient());
             $owner->setContact($contact);
             $this->em->persist($contact);
             $this->em->persist($owner);
             break;
     }
     $account->addAccountOwner($owner);
     $this->em->persist($owner);
     $this->em->flush();
     return $owner;
 }
Esempio n. 2
0
 private function createClientAdditionalContact(array $data, User $clientUser)
 {
     $additionalContact = new ClientAdditionalContact();
     $additionalContact->setClient($clientUser);
     if ($data['state']) {
         $additionalContact->setState($this->getReference('state-' . $data['state']));
     }
     $additionalContact->setFirstName($data['first_name']);
     $additionalContact->setLastName($data['last_name']);
     $additionalContact->setMiddleName($data['middle_name']);
     $additionalContact->setStreet($data['street']);
     $additionalContact->setCity($data['city']);
     $additionalContact->setZip($data['zip']);
     $additionalContact->setIsDifferentAddress($data['is_different_address']);
     $additionalContact->setBirthDate(new \DateTime($data['birth_date']));
     $additionalContact->setPhoneNumber($data['phone_number']);
     $additionalContact->setSsnTin($data['ssn_tin']);
     $additionalContact->setIncomeSource($data['income_source']);
     $additionalContact->setIsSeniorPoliticalFigure($data['is_senior_political_figure']);
     $additionalContact->setIsPubliclyTradedCompany($data['is_publicly_traded_company']);
     $additionalContact->setIsBrokerSecurityExchangePerson($data['is_broker_security_exchange_person']);
     $additionalContact->setEmail($data['email']);
     $additionalContact->setType($data['type']);
     $additionalContact->setEmploymentType($data['employment_type']);
     return $additionalContact;
 }
 protected function onSuccess(ClientAccount $account, $withMaritalStatus)
 {
     /** @var AccountOwnerInterface $data */
     $data = $this->form->getData();
     $isPrimaryApplicant = $data instanceof UserAccountOwnerAdapter;
     if (true === $withMaritalStatus && $isPrimaryApplicant) {
         /** @var $profile Profile */
         $profile = $account->getClient()->getProfile();
         $spouse = $account->getClient()->getSpouse();
         $maritalStatus = $this->form->get('marital_status')->getData();
         if ($maritalStatus == Profile::CLIENT_MARITAL_STATUS_MARRIED) {
             if (!$spouse) {
                 $spouse = new ClientAdditionalContact();
                 $spouse->setClient($account->getClient());
                 $spouse->setType(ClientAdditionalContact::TYPE_SPOUSE);
             }
             if ($this->form->has('spouse_first_name')) {
                 $spouse->setFirstName($this->form->get('spouse_first_name')->getData());
             }
             if ($this->form->has('spouse_middle_name')) {
                 $spouse->setMiddleName($this->form->get('spouse_middle_name')->getData());
             }
             if ($this->form->has('spouse_last_name')) {
                 $spouse->setLastName($this->form->get('spouse_last_name')->getData());
             }
             if ($this->form->has('spouse_birth_date')) {
                 $spouse->setBirthDate($this->form->get('spouse_birth_date')->getData());
             }
         }
         $profile->setMaritalStatus($maritalStatus);
         $this->em->persist($profile);
     }
     $account->setStepAction($isPrimaryApplicant ? ClientAccount::STEP_ACTION_PERSONAL : ClientAccount::STEP_ACTION_ADDITIONAL_PERSONAL);
     $account->setIsPreSaved($this->request->isXmlHttpRequest());
     $this->em->persist($data->getObjectToSave());
     $this->em->persist($account);
     $this->em->flush();
 }