/**
  * Process suggested portfolio
  *
  * @param User $user
  * @param CeModel $suggestedModel
  * @param $withdrawAge
  * @throws \InvalidArgumentException
  */
 protected function processSuggestedPortfolio(User $user, CeModel $suggestedModel, $withdrawAge)
 {
     $session = $this->getOption('session');
     if (!$session instanceof Session) {
         throw new \InvalidArgumentException('Option session must be instance of Session.');
     }
     $session->set('ria.risk_profiling.suggested_portfolio', $suggestedModel->getId());
 }
 public function onBind(FormEvent $event)
 {
     $form = $event->getForm();
     /** @var CeModelEntity $data */
     $data = $event->getData();
     $stock = 0;
     $bond = 0;
     /** @var \Wealthbot\AdminBundle\Repository\CeModelEntityRepository $modelRepo */
     $modelRepo = $this->em->getRepository('WealthbotAdminBundle:CeModel');
     $modelEntities = $this->em->getRepository('WealthbotAdminBundle:CeModelEntity')->findBy(array('modelId' => $this->portfolioModel->getId()));
     foreach ($modelEntities as $entity) {
         if (!$data->getId() || $data->getId() != $entity->getId()) {
             if ($entity->getAssetClass()->getType() == 'Stocks') {
                 $stock += $entity->getPercent();
             }
             if ($entity->getAssetClass()->getType() == 'Bonds') {
                 $bond += $entity->getPercent();
             }
         }
     }
     $overAll = $stock + $bond + $data->getPercent();
     if ($this->portfolioModel->isStrategy()) {
         $percentage = BaselinePortfolio::$modelPercentage[$this->portfolioModel->getParent()->getSlug()];
         $overAllStock = $data->getPercent() + $stock;
         $overAllBond = $data->getPercent() + $bond;
         if ($data->getAssetClass()->getType() == 'Stocks') {
             if ($overAllStock > $percentage['stock']) {
                 $form->get('percent')->addError(new \Symfony\Component\Form\FormError('Sum of the stocks percents must be equal :value.', array(':value' => $percentage['stock'])));
             }
         }
         if ($data->getAssetClass()->getType() == 'Bonds') {
             if ($overAllBond > $percentage['bond']) {
                 $form->get('percent')->addError(new \Symfony\Component\Form\FormError('Sum of the bonds percents must be equal :value.', array(':value' => $percentage['bond'])));
             }
         }
     }
     if ($overAll > 100) {
         $form->get('percent')->addError(new \Symfony\Component\Form\FormError('Sum of the percents must be equal 100.'));
     }
 }
 public function bind(FormEvent $event)
 {
     /** @var $data CeModelEntity */
     $data = $event->getData();
     if ($data === null) {
         return;
     }
     $em = $this->em;
     $form = $event->getForm();
     /** @var $ceModelEntityRepo CeModelEntityRepository */
     $ceModelEntityRepo = $em->getRepository('WealthbotAdminBundle:CeModelEntity');
     if ($data->getSubclass()) {
         $exist = $ceModelEntityRepo->isExistSameSubclassesForModel($this->ceModel->getId(), $data->getSubclass()->getId(), $this->isQualifiedModel, $data->getId());
         if ($exist) {
             if ($data->getId()) {
                 if ($exist->getId() != $data->getId()) {
                     $form->get('subclass')->addError(new FormError('You already hold this subclass in the model.'));
                 }
             } else {
                 $form->get('subclass')->addError(new FormError('You already hold this subclass in the model.'));
             }
         }
     }
     //TODO: Andrey
     $stock = 0;
     $bond = 0;
     $modelEntities = $ceModelEntityRepo->findBy(array('modelId' => $this->ceModel->getId(), 'isQualified' => $this->isQualifiedModel));
     foreach ($modelEntities as $entity) {
         if (!$data->getId() || $data->getId() != $entity->getId()) {
             if ($entity->getAssetClass()->getType() == 'Stocks') {
                 $stock += $entity->getPercent();
             }
             if ($entity->getAssetClass()->getType() == 'Bonds') {
                 $bond += $entity->getPercent();
             }
         }
     }
     $overAll = $stock + $bond + $data->getPercent();
     if ($overAll > 100) {
         $form->get('percent')->addError(new FormError('Sum of the percents must be equal 100.'));
     }
 }
 public function bind(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     $em = $this->em;
     if ($data === null) {
         return;
     }
     if ($data->getSubclass() && $data->getSecurityAssignment()) {
         $exist = $em->getRepository('WealthbotAdminBundle:CeModelEntity')->findOneBy(array('modelId' => $this->portfolioModel->getId(), 'assetClassId' => $data->getAssetClass()->getId(), 'subclassId' => $data->getSubclass()->getId(), 'securityAssignmentId' => $data->getSecurityAssignemnt()->getId(), 'isQualified' => $this->isQualifiedModel));
         if ($exist) {
             if ($data->getId()) {
                 if ($exist->getId() != $data->getId()) {
                     $form->get('subclass')->addError(new FormError('You already hold this subclass in the model.'));
                 }
             } else {
                 $form->get('subclass')->addError(new FormError('You already hold this subclass in the model.'));
             }
         }
     }
 }
 public function hasMuniSubstitution(CeModel $parentModel, Subclass $subclass, User $user)
 {
     $qb = $this->createQueryBuilder("s");
     /*if($user->hasRole('ROLE_RIA') || $user->hasRole('ROLE_SUPER_ADMIN')){
           $qb->where("s.ria_user_id IS NULL");
       }else{
           $qb->where("s.ria_user_id = :ria_user_id")->setParameter("ria_user_id", $user->getId());
       }*/
     $qb->andWhere("s.model_id = :model_id")->andWhere("s.subclass_id = :subclass_id")->andWhere("s.muni_substitution = 1")->setParameter("model_id", $parentModel->getId())->setParameter("subclass_id", $subclass->getId())->setMaxResults(1);
     return $qb->getQuery()->getOneOrNullResult();
 }