public function transferAction(Request $request)
 {
     /** @var $em EntityManager */
     /** @var $repo ClientAccountRepository  */
     $em = $this->get('doctrine.orm.entity_manager');
     $repo = $em->getRepository('WealthbotClientBundle:ClientAccount');
     $adm = $this->get('wealthbot_docusign.account_docusign.manager');
     $documentSignatureManager = $this->get('wealthbot_docusign.document_signature.manager');
     $client = $this->getUser();
     /** @var $account ClientAccount */
     $account = $repo->findOneBy(array('id' => $request->get('account_id'), 'client_id' => $client->getId()));
     if (!$account) {
         $this->createNotFoundException('You have not account with id: ' . $request->get('account_id') . '.');
     }
     $this->denyAccessForCurrentRetirementAccount($account);
     if (!$account->hasGroup(AccountGroup::GROUP_FINANCIAL_INSTITUTION)) {
         throw new AccessDeniedHttpException('Current account has not this step.');
     }
     $accountIndex = $request->get('account_index', 1);
     $consolidatedAccounts = $account->getConsolidatedAccountsCollection();
     $consolidatedAccounts->first();
     $transferAccounts = $consolidatedAccounts->getTransferAccounts();
     if ($transferAccounts->isEmpty()) {
         $this->createNotFoundException('You have not transfer accounts.');
     }
     if (!$transferAccounts->containsKey($accountIndex)) {
         throw $this->createNotFoundException('Page not found.');
     }
     $currentAccount = $transferAccounts->get($accountIndex);
     /** @var $information TransferInformation */
     $information = $currentAccount->getTransferInformation();
     if (!$information) {
         $information = new TransferInformation();
         $information->setClientAccount($currentAccount);
         $information->setFinancialInstitution($currentAccount->getFinancialInstitution());
     }
     $isPreSaved = $request->isXmlHttpRequest();
     $form = $this->createForm(new TransferInformationFormType($adm, $isPreSaved), $information);
     $formHandler = new TransferInformationFormHandler($form, $request, $em, array('client' => $client));
     if ($request->isMethod('post')) {
         if ($formHandler->process()) {
             /** @var TransferInformation $information */
             $information = $form->getData();
             $account->setStepAction(ClientAccount::STEP_ACTION_TRANSFER);
             $account->setIsPreSaved($isPreSaved);
             $isDocusignAllowed = $adm->isDocusignAllowed($information, array(new TransferInformationCustodianCondition(), new TransferInformationPolicyCondition(), new TransferInformationQuestionnaireCondition(), new TransferInformationConsolidatorCondition()));
             $adm->setIsUsedDocusign($account, $isDocusignAllowed);
             if (!$documentSignatureManager->isDocumentSignatureForObjectExist($information)) {
                 $documentSignatureManager->createSignature($information);
             }
             $redirectUrl = $this->getRedirectUrl($account, ClientAccount::STEP_ACTION_TRANSFER);
             if ($isPreSaved) {
                 return $this->getJsonResponse(array('status' => 'success', 'redirect_url' => $redirectUrl));
             }
             // If account has next consolidated transfer account than redirect to it
             // else redirect to another step
             if ($transferAccounts->containsNextKey($accountIndex)) {
                 return $this->redirect($this->generateUrl($this->getRoutePrefix() . 'transfer_transfer_account', array('account_id' => $account->getId(), 'account_index' => $accountIndex + 1)));
             } else {
                 return $this->redirect($redirectUrl);
             }
         } else {
             if ($isPreSaved) {
                 return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView($this->getTemplate('_transfer_form.html.twig'), array('account' => $account, 'current_account' => $currentAccount, 'account_index' => $accountIndex, 'form' => $form->createView()))));
             }
         }
     }
     return $this->render($this->getTemplate('transfer.html.twig'), array('client' => $client, 'account' => $account, 'transfer_accounts' => $transferAccounts, 'current_account' => $currentAccount, 'account_index' => $accountIndex, 'information' => $information, 'form' => $form->createView()));
 }