public function testSetMuniSecurity() { $security = new Security(); $security->setId(45); $this->subclass->setMuniSecurity($security); $this->assertEquals(45, $this->subclass->getMuniSecurity()->getId()); }
/** * Sell subclass * Return sold amount * * @param Subclass $subclass * @param Account $account * @param float $amount * @param boolean $dryRun * @return float * @throws \Exception */ public function sellSubclass(Subclass $subclass, Account $account, $amount, $dryRun = false) { /** @var LotRepository $lotRepository */ $lotRepository = $this->getRepository('Lot'); $requiredCash = $amount; $amountSum = 0; $lots = $lotRepository->findOrderedLots($subclass->getSecurity(), $account); /** @var Lot $lot */ foreach ($lots as $lot) { if ($lot->getIsMuni()) { $securityToSell = $subclass->getMuniSecurity(); } else { $securityToSell = $subclass->getSecurity(); } if ($this->checkShortTermRedemption($securityToSell, $lot) && !$this->checkShortTermGain($lot)) { $sellAmount = $this->sellLot($lot, $securityToSell, $account, $requiredCash, $dryRun); if (!$dryRun && $lot->getAmount() == 0) { $lots->remove($lot->getId()); } $requiredCash -= $sellAmount; $amountSum += $sellAmount; if ($requiredCash <= 0) { break; } } } if ($dryRun) { $account->setCashForBuy($account->getCashForBuy() + $amountSum); } return $amountSum; }