protected function consolidateAccount(ClientAccount $account)
 {
     if ($this->needConsolidate()) {
         parent::consolidateAccount($account);
         $account->setUnconsolidated(false);
     } else {
         $account->setUnconsolidated(true);
         $account->setConsolidator(null);
     }
 }
 public function editAccountAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         throw $this->createNotFoundException();
     }
     $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 */
     /** @var $clientAccountRepo ClientAccountRepository */
     $em = $this->get('doctrine.orm.entity_manager');
     $adm = $this->get('wealthbot_docusign.account_docusign.manager');
     $clientAccountRepo = $em->getRepository('WealthbotClientBundle:ClientAccount');
     $account = $clientAccountRepo->find($request->get('id'));
     if (!$account) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Account does not exist.'));
     }
     $form = $this->createForm(new ClientAccountFormType($client, $account->getGroupName()), $account);
     $formHandler = new ClientAccountFormHandler($form, $request, $adm);
     $process = $formHandler->process();
     if ($request->isMethod('post')) {
         if ($process) {
             $retirementAccounts = $clientAccountRepo->findByClientIdAndGroup($client->getId(), AccountGroup::GROUP_EMPLOYER_RETIREMENT);
             $total = $clientAccountRepo->getTotalScoreByClientId($client->getId());
             return $this->getJsonResponse(array('status' => 'success', 'accounts' => $this->renderView('WealthbotClientBundle:Profile:_accounts_list.html.twig', array('client' => $client, 'total' => $total, 'show_action_btn' => true)), 'retirement_accounts' => $this->renderView('WealthbotClientBundle:Profile:_retirement_accounts_list.html.twig', array('retirement_accounts' => $retirementAccounts))));
         } else {
             $status = 'error';
         }
     } else {
         $status = 'success';
     }
     return $this->getJsonResponse(array('status' => $status, 'form' => $this->renderView('WealthbotClientBundle:Profile:_edit_client_account_form.html.twig', array('form' => $form->createView(), 'account' => $account))));
 }