public function testBindAllocationForAccount()
 {
     $accountRepo = new AccountRepository();
     $account = $accountRepo->findOneByAccountNumber('744888386');
     $subclassesData = $this->subclassesData;
     $subclassesData['RWX']['security']['amount'] = 2156.54;
     $subclassesData['RWX']['security']['qty'] = 65;
     $subclassesData['DBC']['muni_security']['qty'] = 0;
     $subclassesData['DBC']['muni_security']['amount'] = 0;
     $subclassCollection = $this->repository->bindAllocations($this->portfolio, $account);
     $this->checkCollection($subclassCollection, $subclassesData);
 }
 public function testFindLotsBySubclass()
 {
     $subclassRepo = new SubclassRepository();
     $clientRepo = new ClientRepository();
     $portfolioRepo = new PortfolioRepository();
     $securityRepo = new SecurityRepository();
     $accountRepo = new AccountRepository();
     $security = $securityRepo->findOneBySymbol('RWX');
     $client = $clientRepo->findClientByEmail('*****@*****.**');
     $portfolioRepo->findPortfolioByClient($client);
     $subclass = $subclassRepo->findByNameForPortfolio('Short', $client->getPortfolio());
     $subclass->setSecurity($security);
     $lots = $this->repository->findLotsBySubclass($client->getPortfolio(), $subclass);
     $this->assertCount(2, $lots);
     /** @var Lot $lot */
     $lot = $lots->first();
     $this->assertEquals(390.49, $lot->getAmount());
     $this->assertEquals(10, $lot->getQuantity());
     $this->assertTrue($lot->isOpen());
     $this->assertFalse($lot->getIsMuni());
     $lot = $lots->next();
     $this->assertEquals(2156.54, $lot->getAmount());
     $this->assertEquals(65, $lot->getQuantity());
     $this->assertTrue($lot->isOpen());
     $this->assertFalse($lot->getIsMuni());
     //---------------------------------------------------------------------------------//
     $account = $accountRepo->findOneByAccountNumber('744888386');
     $lots = $this->repository->findLotsBySubclass($client->getPortfolio(), $subclass, $account);
     $this->assertCount(1, $lots);
     $lot = $lots->first();
     $this->assertEquals(2156.54, $lot->getAmount());
     $this->assertEquals(65, $lot->getQuantity());
     $this->assertTrue($lot->isOpen());
     $this->assertFalse($lot->getIsMuni());
     //---------------------------------------------------------------------------------//
     $security = $securityRepo->findOneBySymbol('VTI');
     $subclass->setSecurity($security);
     $lots = $this->repository->findLotsBySubclass($client->getPortfolio(), $subclass);
     $this->assertCount(1, $lots);
     $lot = $lots->first();
     $this->assertEquals(1000, $lot->getAmount());
     $this->assertEquals(100, $lot->getQuantity());
     $this->assertTrue($lot->isInitial());
     $this->assertTrue($lot->getIsMuni());
 }
 public function testDelete()
 {
     $securityRepository = new SecurityRepository();
     $security = $securityRepository->findOneBySymbol('VTI');
     $accountRepository = new AccountRepository();
     $account = $accountRepository->findOneByAccountNumber('916985328');
     $subclassRepo = new SubclassRepository();
     $subclass = $subclassRepo->findFirst();
     $riaRepo = new RiaRepository();
     $ria = $riaRepo->findOneBy(array('email' => '*****@*****.**'));
     $jobRepo = new JobRepository();
     $job = $jobRepo->findOneBy(array('user_id' => $ria->getId()));
     $rebalancerActionRepo = new RebalancerActionRepository();
     $rebalancerActions = $rebalancerActionRepo->bindForJob($job);
     $rebalancerAction = $rebalancerActions->first();
     $rebalancerQueue = new QueueItem();
     $rebalancerQueue->setSecurity($security);
     $rebalancerQueue->setAccount($account);
     $rebalancerQueue->setAmount(100.1);
     $rebalancerQueue->setRebalancerActionId($rebalancerAction->getId());
     $rebalancerQueue->setQuantity(10);
     $rebalancerQueue->setStatus(QueueItem::STATUS_BUY);
     $rebalancerQueue->setSubclass($subclass);
     $this->repository->save($rebalancerQueue);
     $last = $this->repository->findById($this->repository->getLastInsertId());
     $this->repository->delete($last);
     $deletedLast = $this->repository->findById($last->getId());
     $this->assertNull($deletedLast);
 }
 public function fakeStart($jobId)
 {
     /** @var JobRepository $jobRepo */
     $jobRepo = $this->getRepository('Job');
     /** @var Job $job */
     $job = $jobRepo->find($jobId);
     if (!$job) {
         return;
     }
     /** @var ClientRepository $clientRepo */
     $clientRepo = $this->getRepository('Client');
     /** @var RebalancerActionRepository $rebalancerActionRepo */
     $rebalancerActionRepo = $this->getRepository('RebalancerAction');
     $rebalancerActions = $rebalancerActionRepo->bindForJob($job);
     /** @var AccountRepository $accountRepo */
     $accountRepo = $this->getRepository('Account');
     /** @var LotRepository $lotRepository */
     $lotRepository = $this->getRepository('Lot');
     /** @var SecurityRepository $securityRepo */
     $securityRepo = $this->getRepository('Security');
     /** @var PortfolioRepository $portfolioRepo */
     $portfolioRepo = $this->getRepository('Portfolio');
     /** @var RebalancerQueueRepository $rebalancerQueueRepo */
     $rebalancerQueueRepo = $this->getRepository('RebalancerQueue');
     $account744888385 = $accountRepo->findOneByAccountNumber('744888385');
     $account744888386 = $accountRepo->findOneByAccountNumber('744888386');
     $securityRWX = $securityRepo->findOneBySymbol('RWX');
     $securityVTI = $securityRepo->findOneBySymbol('VTI');
     $subclassRepo = new SubclassRepository();
     /** @var RebalancerAction $rebalancerAction */
     foreach ($rebalancerActions as $rebalancerAction) {
         $rebalancerAction->setStatus($job->getRebalanceType());
         $client = $clientRepo->getClientByRebalancerAction($rebalancerAction);
         $portfolio = $portfolioRepo->findPortfolioByClient($client);
         $account744888385->setClient($client);
         $account744888386->setClient($client);
         $subclass = $subclassRepo->findByNameForPortfolio('Large Value', $portfolio);
         $queueItem = new QueueItem();
         $queueItem->setStatus(QueueItem::STATUS_SELL);
         $queueItem->setLot($lotRepository->findLastLotByAccountAndSecurity($account744888385, $securityRWX));
         $queueItem->setAccount($account744888385);
         $queueItem->setAmount(1000);
         $queueItem->setQuantity(50);
         $queueItem->setSecurity($securityRWX);
         $queueItem->setSubclass($subclass);
         $queueItem->setRebalancerActionId($rebalancerAction->getId());
         $rebalancerQueueRepo->save($queueItem);
         $queueItem = new QueueItem();
         $queueItem->setStatus(QueueItem::STATUS_BUY);
         $queueItem->setAccount($account744888386);
         $queueItem->setAmount(700);
         $queueItem->setQuantity(7);
         $queueItem->setSecurity($securityVTI);
         $queueItem->setSubclass($subclass);
         $queueItem->setRebalancerActionId($rebalancerAction->getId());
         $rebalancerQueueRepo->save($queueItem);
         $rebalancerActionRepo->saveStatus($rebalancerAction);
     }
     $jobRepo->finish($job);
 }