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())); }
public function updateTransferFormAction(Request $request) { $em = $this->get('doctrine.orm.entity_manager'); $adm = $this->get('wealthbot_docusign.account_docusign.manager'); $account = $em->getRepository('WealthbotClientBundle:ClientAccount')->find($request->get('account_id')); if (!$account || $account->getClient() != $this->getUser()) { return $this->getJsonResponse(array('status' => 'error', 'message' => 'Account does not exist.')); } $accountIndex = $request->get('account_index', 1); $consolidatedAccounts = $account->getConsolidatedAccountsCollection(); $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); $transferInfo = $currentAccount->getTransferInformation(); if (!$transferInfo) { $transferInfo = new TransferInformation(); $transferInfo->setClientAccount($currentAccount); } if ($request->isMethod('post')) { $form = $this->createForm(new TransferInformationFormType($adm, true), $transferInfo); $form->bind($request); /** @var TransferInformation $transferInfo */ $transferInfo = $form->getData(); $transferInfo->setStatementDocument(null); // Remove answer if it value is null /** @var TransferCustodianQuestionAnswer $answer */ foreach ($transferInfo->getQuestionnaireAnswers() as $answer) { if (null === $answer->getValue()) { $transferInfo->removeQuestionnaireAnswer($answer); } } $isDocusignAllowed = $adm->isDocusignAllowed($transferInfo, array(new TransferInformationCustodianCondition(), new TransferInformationPolicyCondition(), new TransferInformationQuestionnaireCondition(), new TransferInformationConsolidatorCondition())); $adm->setIsUsedDocusign($currentAccount, $isDocusignAllowed); $form = $this->createForm(new TransferInformationFormType($adm, true), $transferInfo); $formView = $form->createView(); return $this->getJsonResponse(array('status' => 'success', 'custodian_questions_fields' => $this->renderView('WealthbotClientBundle:Transfer:_transfer_form_custodian_questions_fields.html.twig', array('form' => $formView)), 'account_discrepancies_fields' => $this->renderView('WealthbotClientBundle:Transfer:_transfer_form_account_discrepancies_fields.html.twig', array('form' => $formView)))); } return $this->getJsonResponse(array('status' => 'error', 'message' => 'The operation failed due to some errors.')); }