Beispiel #1
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;
 }
Beispiel #2
0
 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);
     }
 }
 /**
  * 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.'));
                 }
             }
         }
     }
 }