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); }
/** * Set account_id for owners in $this->owners array * * @param ClientAccount $account */ protected function saveAccountOwners(ClientAccount $account) { if (empty($this->owners) && $account->getAccountOwners()->isEmpty()) { $owner = new ClientAccountOwner(); $owner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF); $owner->setClient($account->getClient()); $owner->setAccount($account); $account->addAccountOwner($owner); $this->em->persist($owner); } else { $repo = $this->em->getRepository('WealthbotClientBundle:ClientAccountOwner'); foreach ($this->owners as $ownerItem) { $owner = new ClientAccountOwner(); $owner->setOwnerType($ownerItem['owner_type']); $owner->setAccount($account); if ($ownerItem['owner_type'] === ClientAccountOwner::OWNER_TYPE_SELF) { $client = $this->em->getRepository('WealthbotUserBundle:User')->find($ownerItem['owner_client_id']); if ($client) { $exist = $repo->findOneBy(array('owner_type' => $ownerItem['owner_type'], 'owner_client_id' => $client->getId(), 'account_id' => $account->getId())); if (!$exist) { $owner->setClient($client); $this->em->persist($owner); } } } else { $contact = $this->em->getRepository('WealthbotClientBundle:ClientAdditionalContact')->find($ownerItem['owner_contact_id']); if ($contact) { $exist = $repo->findOneBy(array('owner_type' => $ownerItem['owner_type'], 'owner_contact_id' => $contact->getId(), 'account_id' => $account->getId())); if (!$exist) { $owner->setContact($contact); $this->em->persist($owner); } } } $account->addAccountOwner($owner); } } $this->em->persist($account); $this->em->flush(); }
private function updateFields(FormInterface $form) { $choices = ClientAccountOwner::getOwnerTypeChoices(); if ($this->isJoint) { if (!$this->client->isMarried()) { unset($choices['spouse']); } $form->add($this->factory->createNamed('owner_types', 'choice', null, array('mapped' => false, 'choices' => $choices, 'expanded' => true, 'multiple' => true))); } else { unset($choices['other']); $form->add($this->factory->createNamed('owner_types', 'choice', null, array('mapped' => false, 'choices' => $choices, 'expanded' => true, 'multiple' => false))); } }
/** * 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; }
private function createClientAccounts(ObjectManager $manager, User $clientUser) { $lastAccount = null; foreach ($this->accounts as $index => $item) { /** @var AccountGroupType $groupType */ $groupType = $this->getReference('client-account-group-type-' . $item['group_key'] . '-' . $item['type_key']); $account = new ClientAccount(); $account->setGroupType($groupType); $account->setClient($clientUser); $account->setFinancialInstitution($item['financial_institution']); $account->setValue($item['value']); $account->setMonthlyContributions($item['monthly_contributions']); $account->setMonthlyDistributions($item['monthly_distributions']); $account->setSasCash($item['sas_cash']); $accountOwner = new ClientAccountOwner(); $accountOwner->setAccount($account); $accountOwner->setClient($clientUser); $accountOwner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF); if (isset($item['consolidator_key']) && null !== $item['consolidator_key']) { /** @var ClientAccount $consolidator */ $consolidator = $this->getReference('user-client-account-' . $item['consolidator_key']); $account->setConsolidator($consolidator); } if (isset($item['funds']) && $item['group_key'] === AccountGroup::GROUP_EMPLOYER_RETIREMENT) { foreach ($item['funds'] as $fundItem) { // ToDo: CE-402: check that code is not needed more // $outsideFund = $manager->getRepository('WealthbotAdminBundle:Security')->findOneBySymbol($fundItem['symbol']); // if (!$outsideFund) { // /** @var SecurityType $securityType */ // $securityType = $this->getReference('security-type-' . $fundItem['type']); // // $outsideFund = new Security(); // $outsideFund->setName($fundItem['name']); // $outsideFund->setSymbol($fundItem['symbol']); // $outsideFund->setSecurityType($securityType); // $outsideFund->setExpenseRatio($fundItem['exp_ratio']); // } // $securityAssignment = new SecurityAssignment(); // $securityAssignment->setSecurity($outsideFund); // $securityAssignment->setRia($clientUser->getRia()); Deprecated // $securityAssignment->setIsPreferred(false); // $accountOutsideFund = new AccountOutsideFund(); // $accountOutsideFund->setAccount($account); // $accountOutsideFund->setSecurityAssignment($securityAssignment); // $accountOutsideFund->setIsPreferred(false); // $account->addAccountOutsideFund($accountOutsideFund); // // $manager->persist($accountOutsideFund); } } $manager->persist($account); $manager->persist($accountOwner); $this->addReference('user-client-account-' . ($index + 1), $account); if (!$account->isRetirementType()) { $lastAccount = $account; } } if ($lastAccount) { $systemAccount = new SystemAccount(); $systemAccount->setClient($clientUser); $systemAccount->setClientAccount($lastAccount); $systemAccount->setAccountNumber('916985328'); $systemAccount->setAccountDescription($lastAccount->getOwnersAsString() . ' ' . $lastAccount->getTypeName()); $systemAccount->setType($lastAccount->getSystemType()); $systemAccount->setSource(SystemAccount::SOURCE_SAMPLE); $clientUser->addSystemAccount($systemAccount); $this->addReference('system-account', $systemAccount); $manager->persist($systemAccount); } }
/** * @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; }