/**
  * 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());
 }
Пример #2
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     foreach ($this->strategyModels as $index => $value) {
         $ceModel = new CeModel();
         $ceModel->setName($value);
         $ceModel->setType(CeModel::TYPE_CUSTOM);
         $ceModel->setRiskRating(0);
         $manager->persist($ceModel);
         $this->addReference('strategy-' . ($index + 1), $ceModel);
     }
     $manager->flush();
 }
Пример #3
0
 public function setUp()
 {
     $questions = array();
     for ($i = 0; $i < 4; $i++) {
         $question = new RiskQuestion();
         $question->setTitle('Question ' . ($i + 1));
         for ($j = 0; $j < 4; $j++) {
             $answer = new RiskAnswer();
             $answer->setTitle('Answer ' . ($i + 1) . ' - ' . ($j + 1));
             $answer->setQuestion($question);
             $answer->setPoint($j);
             $question->addAnswer($answer);
         }
         $questions[] = $question;
     }
     $userAnswers = array();
     foreach ($questions as $key => $question) {
         $userAnswer = new ClientQuestionnaireAnswer();
         $userAnswer->setQuestion($question);
         $questionAnswers = $question->getAnswers();
         $userAnswer->setAnswer($questionAnswers[$key]);
         $userAnswers[] = $userAnswer;
     }
     $portfolio = new CeModel();
     for ($i = 0; $i < 4; $i++) {
         $modelMock = $this->getMock('Wealthbot\\AdminBundle\\Entity\\CeModel', array('getId'));
         $modelMock->expects($this->any())->method('getId')->will($this->returnValue($i + 1));
         $modelMock->setName('Model ' . ($i + 1));
         $modelMock->setRiskRating($i + 1);
         $portfolio->addChildren($modelMock);
     }
     $riaCompanyInformation = new RiaCompanyInformation();
     $riaCompanyInformation->setPortfolioModel($portfolio);
     $ria = new User();
     $ria->setRoles(array('ROLE_RIA'));
     $ria->setRiaCompanyInformation($riaCompanyInformation);
     $userProfile = new Profile();
     $userProfile->setRia($ria);
     $user = new User();
     $user->setRoles(array('ROLE_CLIENT'));
     $user->setProfile($userProfile);
     $this->riskTolerance = new RiskTolerance($user, $userAnswers);
 }
 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();
 }
Пример #5
0
 function load(ObjectManager $manager)
 {
     foreach ($this->models as $index => $item) {
         /** @var CeModel $strategy */
         $strategy = $this->getReference('strategy-' . $item['parent_index']);
         $model = new CeModel();
         $model->setName($item['name']);
         $model->setParent($strategy);
         $model->setRiskRating($item['risk_rating']);
         $model->setType($strategy->getType());
         $manager->persist($model);
         $this->addReference('model-' . ($index + 1), $model);
         foreach ($item['entities'] as $entityItem) {
             /** @var SecurityAssignment $securityAssignment */
             $securityAssignment = $this->getReference('model-security-assignment-' . $entityItem['security_assignment_index']);
             $entity = new CeModelEntity();
             $entity->setModel($model);
             $entity->setSubclass($securityAssignment->getSubclass());
             $entity->setAssetClass($securityAssignment->getSubclass()->getAssetClass());
             $entity->setSecurityAssignment($securityAssignment);
             $entity->setPercent($entityItem['percent']);
             $model->addModelEntity($entity);
         }
     }
     $manager->flush();
 }
 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.'));
     }
 }
 protected function updateMuniSubstitution(FormInterface $form, $subclass)
 {
     if (!$subclass instanceof Subclass) {
         $subclass = $this->em->getRepository('WealthbotAdminBundle:Subclass')->find($subclass);
     }
     if ($this->user->hasRole('ROLE_ADMIN') || $this->user->hasRole('ROLE_SUPER_ADMIN') || $this->user->hasRole('ROLE_RIA') && $this->user->getRiaCompanyInformation()->getUseMunicipalBond()) {
         /** @var SecurityAssignmentRepository $repo */
         $repo = $this->em->getRepository('WealthbotAdminBundle:SecurityAssignment');
         $parentModel = $this->ceModel->getParent();
         $existMuniSubstitution = $repo->hasMuniSubstitution($parentModel, $subclass, $this->user);
         if ($existMuniSubstitution) {
             $queryBuilder = $repo->getAvailableMuniSubstitutionsQuery($parentModel->getId(), $subclass->getId());
             $form->add($this->factory->createNamed('muniSubstitution', 'entity', null, array('class' => 'WealthbotAdminBundle:SecurityAssignment', 'property' => 'security.name', 'required' => false, 'empty_value' => 'Choose Muni Substitution', 'query_builder' => $queryBuilder)));
         }
     }
 }
 protected function updateSecurity(FormInterface $form, $subclassId, $currentEntityId = null)
 {
     $entities = $this->portfolioModel->getModelEntities();
     $securitiesIds = array();
     //TODO discuss with Andrey about this code
     if ($currentEntityId) {
         foreach ($entities as $entity) {
             if (!$currentEntityId || $currentEntityId != $entity->getId()) {
                 $securitiesIds[] = $entity->getSecurityAssignmentId();
             }
         }
     }
     $form->add($this->factory->createNamed('security', 'entity', null, array('class' => 'WealthbotAdminBundle:SecurityAssignment', 'property' => 'security.name', 'empty_value' => 'Choose Security', 'query_builder' => function (EntityRepository $er) use($subclassId, $securitiesIds) {
         $qb = $er->createQueryBuilder('s');
         $qb->where('s.subclass_id = :subclassId AND s.ria_user_id IS NULL');
         $qb->andWhere('s.muni_substitution = 0');
         if (!empty($securitiesIds)) {
             $qb->andWhere($qb->expr()->notIn('s.id', $securitiesIds));
         }
         $qb->setParameter('subclassId', $subclassId)->orderBy('s.id', 'ASC');
         return $qb;
     }, 'attr' => is_null($subclassId) ? array('disabled' => 'disabled') : array())));
 }