public function saveAssumptionAction(Request $request)
 {
     $user = $this->getUser();
     /** @var $parentModel CeModel */
     $parentModel = $user->getRiaCompanyInformation()->getPortfolioModel();
     if (!$parentModel) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Ria does not have models.'));
     }
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     /** @var $modelManager CeModelManager */
     $modelManager = $this->get('wealthbot_admin.ce_model_manager');
     /** @var $portfolioInfoManager PortfolioInformationManager */
     $portfolioInfoManager = $this->get('wealthbot_admin.portfolio_information_manager');
     $model = $modelManager->findCeModelBySlugAndOwnerId($request->get('slug'), $user->getId());
     $isQualified = false;
     /** @var RiaCompanyInformation $riaCompanyInformation */
     $riaCompanyInformation = $user->getRiaCompanyInformation();
     $isUseQualified = $user->getRiaCompanyInformation()->getIsUseQualifiedModels();
     if ($isUseQualified) {
         if ($request->get('is_qualified') !== null) {
             $isQualified = $request->get('is_qualified');
             $this->setIsQualifiedModel($isUseQualified);
         }
     }
     $form = $this->createForm(new CeModelFormType($em, $user, $parentModel, true), $model);
     $formHandler = new CeModelFormHandler($form, $request, $em, array('is_show_assumption' => true));
     if ($formHandler->process()) {
         return $this->getJsonResponse(array('status' => 'success', 'models_list' => $this->renderView('WealthbotRiaBundle:Models:_models_list.html.twig', array('models' => $modelManager->getChildModels($parentModel), 'active_model_id' => $model->getId())), 'model_view' => $this->renderView('WealthbotRiaBundle:Models:_model_view.html.twig', array('portfolio_information' => $portfolioInfoManager->getPortfolioInformation($user, $model, $isQualified), 'form' => $this->createForm(new CeModelEntityFormType($model, $em, $user))->createView(), 'is_use_qualified' => $isUseQualified, 'is_show_municipal_bond' => $riaCompanyInformation->getUseMunicipalBond(), 'is_show_tax_loss_harvesting' => $riaCompanyInformation->getIsTaxLossHarvesting()))));
     }
     return $this->getJsonResponse(array('status' => 'error', 'content' => $this->renderView('WealthbotRiaBundle:Models:_edit_form.html.twig', array('form' => $form->createView(), 'model' => $model))));
 }
 public function editAction(Request $request)
 {
     $this->checkAccess(Acl::PERMISSION_EDIT);
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     $id = $request->get('id');
     $modelEntity = $em->getRepository('WealthbotAdminBundle:CeModelEntity')->find($id);
     if (!$modelEntity) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Model Entity with id: ' . $id . ' does not exist.'));
     }
     $model = $modelEntity->getModel();
     $form = $this->createForm(new CeModelEntityFormType($model, $em, $this->getUser()), $modelEntity);
     $formHandler = new CeModelFormHandler($form, $request, $em);
     if ($request->isMethod('post')) {
         if ($formHandler->process()) {
             $form = $this->createForm(new CeModelEntityFormType($model, $em, $this->getUser()));
             return $this->getJsonResponse(array('status' => 'success', 'form' => $this->renderView('WealthbotAdminBundle:Model:_form.html.twig', array('form' => $form->createView(), 'model' => $model)), 'content' => $this->renderView('WealthbotAdminBundle:Model:_model_row.html.twig', array('modelEntity' => $modelEntity))));
         }
         return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView('WealthbotAdminBundle:Model:_edit_form.html.twig', array('form' => $form->createView(), 'modelEntity' => $modelEntity))));
     }
     return $this->getJsonResponse(array('status' => 'success', 'form' => $this->renderView('WealthbotAdminBundle:Model:_edit_form.html.twig', array('form' => $form->createView(), 'modelEntity' => $modelEntity))));
 }