public function setUp()
 {
     $this->condition = new TransferInformationConsolidatorCondition();
     $this->consolidatorMock = $this->getMock('Wealthbot\\ClientBundle\\Entity\\ClientAccount', null);
     $this->accountMock = $this->getMock('Wealthbot\\ClientBundle\\Entity\\ClientAccount', null);
     $this->transferInformationMock = $this->getMock('Wealthbot\\ClientBundle\\Entity\\TransferInformation', null);
     $userMock = $this->getUserMock();
     $this->accountMock->setClient($userMock);
     $this->consolidatorMock->setClient($userMock);
     $primaryOwner = new ClientAccountOwner();
     $primaryOwner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF);
     $primaryOwner->setClient($userMock);
     $secondaryOwner = new ClientAccountOwner();
     $secondaryOwner->setOwnerType(ClientAccount::OWNER_SPOUSE);
     $secondaryOwner->setContact($this->getAdditionalContactMock());
     $this->consolidatorMock->addAccountOwner($primaryOwner)->addAccountOwner($secondaryOwner);
     $this->accountMock->setConsolidator($this->consolidatorMock);
     $this->transferInformationMock->setClientAccount($this->accountMock);
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * @param ObjectManager $manager
  * @param array $data
  * @param User $clientUser
  * @return ClientAccount
  */
 private function createClientAccount(ObjectManager $manager, array $data, User $clientUser)
 {
     $securityRepository = $manager->getRepository('WealthbotAdminBundle:Security');
     $account = new ClientAccount();
     $account->setClient($clientUser);
     $account->setGroupType($this->getReference('client-account-group-type-' . $data['group_type_key']));
     $account->setFinancialInstitution($data['financial_institution']);
     $account->setValue($data['value']);
     $account->setMonthlyContributions($data['monthly_contributions']);
     $account->setMonthlyDistributions($data['monthly_distributions']);
     $account->setSasCash($data['sas_cash']);
     $account->setProcessStep($data['process_step']);
     $account->setStepAction($data['step_action']);
     $account->setIsPreSaved($data['is_pre_saved']);
     $account->setUnconsolidated($data['unconsolidated']);
     if ($data['consolidator_index']) {
         $consolidator = $clientUser->getClientAccounts()->get($data['consolidator_index'] - 1);
         $account->setConsolidator($consolidator);
     }
     foreach ($data['owners'] as $ownerType) {
         $accountOwner = new ClientAccountOwner();
         if ($ownerType === ClientAccountOwner::OWNER_TYPE_SELF) {
             $accountOwner->setClient($clientUser);
         } else {
             $accountOwner->setContact($clientUser->getAdditionalContacts()->first());
         }
         $accountOwner->setOwnerType($ownerType);
         $accountOwner->setAccount($account);
         $account->addAccountOwner($accountOwner);
     }
     $manager->persist($account);
     $manager->flush();
     $manager->refresh($account);
     if (isset($data['account_contribution'])) {
         $accountContribution = new AccountContribution();
         $accountContribution->setAccount($account);
         $accountContribution->setType($data['account_contribution']['type']);
         $accountContribution->setTransactionFrequency($data['account_contribution']['transaction_frequency']);
         $account->setAccountContribution($accountContribution);
         $manager->persist($accountContribution);
     }
     if (isset($data['securities'])) {
         foreach ($data['securities'] as $securityItem) {
             //ToDo: CE-402. Check that code is not needed more.
             //                $security = $securityRepository->findOneBySymbol($securityItem['symbol']);
             //                if (!$security) {
             //                    /** @var SecurityType $securityType */
             //                    $securityType = $this->getReference('security-type-' . $securityItem['type']);
             //
             //                    $security = new Security();
             //                    $security->setName($securityItem['name']);
             //                    $security->setSymbol($securityItem['symbol']);
             //                    $security->setSecurityType($securityType);
             //                    $security->setExpenseRatio($securityItem['exp_ratio']);
             //                }
             //                $securityAssignment = new SecurityAssignment();
             //                $securityAssignment->setSecurity($security);
             //                $securityAssignment->setRia($clientUser->getRia()); Deprecated
             //                $accountOutsideFund = new AccountOutsideFund();
             //                $accountOutsideFund->setAccount($account);
             //                $accountOutsideFund->setSecurityAssignment($securityAssignment);
             //                $accountOutsideFund->setIsPreferred(false);
             //
             //                $manager->persist($accountOutsideFund);
         }
     }
     $manager->persist($account);
     $manager->flush();
     $this->addReference('client-account-' . $account->getId(), $account);
     return $account;
 }