Пример #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;
 }
Пример #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);
     }
 }
Пример #3
0
 public function createAccountAction(Request $request)
 {
     if (!$request->isMethod("post") || !$request->isXmlHttpRequest()) {
         throw $this->createNotFoundException('Page not found.');
     }
     $client = $this->getUser();
     if (!$client || !$client->hasRole('ROLE_CLIENT')) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Client does not exist.'));
     }
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     $adm = $this->get('wealthbot_docusign.account_docusign.manager');
     $group = $request->get('group');
     $allowedGroups = AccountGroup::getGroupChoices();
     if (!in_array($group, $allowedGroups)) {
         throw new HttpException(400, 'Invalid group type');
     }
     $groupTypeId = null;
     $groupType = null;
     $clientAccount = new ClientAccount();
     if ($group === AccountGroup::GROUP_DEPOSIT_MONEY || $group === AccountGroup::GROUP_FINANCIAL_INSTITUTION) {
         $groupType = $this->getAccountGroupType();
         $clientAccount->setGroupType($groupType);
     }
     $form = $this->createForm(new TypedClientAccountFormType($em, $client, $groupType, $group), $clientAccount);
     $formHandler = new ClientAccountFormHandler($form, $request, $adm, $this->getAccountOwners(), $this->getIsConsolidateAccount());
     $process = $formHandler->process();
     if ($process) {
         $this->removeAccountGroup();
         $this->removeAccountType();
         $this->removeAccountGroupType();
         $this->removeAccountOwners();
         /** @var ClientAccount $clientAccount */
         $clientAccount = $form->getData();
         if ($group == 'employer_retirement') {
             $responseData = $this->processEmployerRetirementAccountForm($clientAccount);
         } else {
             $responseData = $this->processAccountForm();
             $isType = $clientAccount->getGroupName() === AccountGroup::GROUP_DEPOSIT_MONEY;
             $systemAccounts = $em->getRepository('WealthbotClientBundle:SystemAccount')->findByClientIdAndType($client->getId(), $clientAccount->getSystemType());
             $responseData['in_right_box'] = $isType || count($systemAccounts) < 1 ? false : true;
             $responseData['transfer_url'] = $this->generateUrl('rx_client_dashboard_select_system_account', array('account_id' => $clientAccount->getId()));
         }
         $this->removeIsConsolidateAccount();
         $this->removeAccountStep();
         return $this->getJsonResponse($responseData);
     }
     $message = $this->getTitleMessageForAccountForm($group, $groupType);
     return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView('WealthbotClientBundle:Profile:_client_accounts_form.html.twig', array('form' => $form->createView(), 'group' => $group, 'hide_submit_button' => true, 'title_message' => $message))));
 }