public function createBankInformationAction(Request $request)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     $repo = $em->getRepository('WealthbotClientBundle:ClientAccount');
     $client = $this->getUser();
     $accountId = (int) $request->get('account_id');
     $account = null;
     if ($accountId !== 0) {
         /** @var ClientAccount $account */
         $account = $repo->findOneBy(array('id' => $accountId, 'client_id' => $client->getId()));
     }
     $bankInfo = null;
     $form = $this->createForm(new BankInformationFormType());
     $formHandler = new BankInformationFormHandler($form, $request, $em, array('client' => $client));
     if ($request->isMethod('post')) {
         if ($formHandler->process()) {
             // Only if bank information has been created on the client account management page
             if ($accountId === 0) {
                 $event = new WorkflowEvent($client, $bankInfo, Workflow::TYPE_PAPERWORK);
                 $this->get('event_dispatcher')->dispatch(ClientEvents::CLIENT_WORKFLOW, $event);
             }
         } else {
             return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView('WealthbotClientBundle:DashboardTransfer:_create_bank_account_form.html.twig', array('form' => $form->createView(), 'account_id' => $accountId))));
         }
     }
     $response = array('status' => 'success');
     if ($accountId !== 0) {
         $transferForm = $this->createForm(new TransferFundingDistributingFormType($em, $account), array('funding' => $account->getAccountContribution()));
         $transferFormChildren = $transferForm->createView()->vars['form']->getChildren();
         $response['form_fields'] = $this->renderView('WealthbotClientBundle:Transfer:_bank_transfer_form_fields.html.twig', array('form' => $transferFormChildren['funding'], 'account' => $account));
     } else {
         $response['bank_account_item'] = $this->renderView('WealthbotClientBundle:Dashboard:_bank_account_item.html.twig', array('bank_account' => $bankInfo));
     }
     return $this->getJsonResponse($response);
 }
Ejemplo n.º 2
0
 public function editBankInformationAction(Request $request)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     $documentSignatureManager = $this->get('wealthbot_docusign.document_signature.manager');
     $repo = $em->getRepository('WealthbotClientBundle:BankInformation');
     $accountRepo = $em->getRepository('WealthbotClientBundle:ClientAccount');
     $client = $this->getUser();
     $accountId = (int) $request->get('account_id');
     $account = null;
     $bankInfo = $repo->findOneBy(array('id' => $request->get('bank_id'), 'client_id' => $client->getId()));
     if (!$bankInfo) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Bank information does not exist.'));
     }
     if ($accountId !== 0) {
         $account = $accountRepo->findOneBy(array('id' => $accountId, 'client_id' => $client->getId()));
         if (!$account) {
             return $this->getJsonResponse(array('status' => 'error', 'message' => 'Account does not exist.'));
         }
     }
     $responseStatus = 'success';
     $form = $this->createForm(new BankInformationFormType(), $bankInfo);
     $formHandler = new BankInformationFormHandler($form, $request, $em, array('client' => $client));
     if ($request->isMethod('post')) {
         if ($formHandler->process()) {
             $response = array('status' => 'success');
             $signatures = $documentSignatureManager->createBankInformationSignature($bankInfo);
             if (count($signatures)) {
                 $response['content'] = $this->renderView('WealthbotClientBundle:Transfer:_bank_information_sign.html.twig', array('signatures' => $signatures));
             }
             if ($accountId !== 0) {
                 $transferForm = $this->createForm(new TransferFundingDistributingFormType($em, $account), array('funding' => $account->getAccountContribution()));
                 $transferFormChildren = $transferForm->createView()->vars['form']->getChildren();
                 $response['form_fields'] = $this->renderView('WealthbotClientBundle:Transfer:_bank_transfer_form_fields.html.twig', array('form' => $transferFormChildren['funding'], 'account' => $account));
             } else {
                 // Only if bank information has been updated on the client account management page
                 $event = new WorkflowEvent($client, $bankInfo, Workflow::TYPE_PAPERWORK, $signatures);
                 $this->get('event_dispatcher')->dispatch(ClientEvents::CLIENT_WORKFLOW, $event);
                 $response['bank_account_id'] = $bankInfo->getId();
                 $response['bank_account_item'] = $this->renderView('WealthbotClientBundle:Dashboard:_bank_account_item.html.twig', array('bank_account' => $bankInfo));
                 $this->dispatchHistoryEvent($client, 'Updated bank information');
             }
             return $this->getJsonResponse($response);
         } else {
             $responseStatus = 'error';
         }
     }
     return $this->getJsonResponse(array('status' => $responseStatus, 'content' => $this->renderView('WealthbotClientBundle:Transfer:_edit_bank_account_form.html.twig', array('form' => $form->createView(), 'bank' => $bankInfo, 'account_id' => $accountId))));
 }