public function findById($id) { $sql = "SELECT rq.*, ra.job_id FROM " . self::TABLE_REBALANCER_QUEUE . " rq\n LEFT JOIN " . self::TABLE_REBALANCER_ACTION . " ra On ra.id = rq.rebalancer_action_id\n WHERE rq.id = :id\n "; $result = $this->db->queryOne($sql, array('id' => $id)); if (empty($result)) { return null; } /** @var QueueItem $item */ $item = $this->bindObject($result); if (isset($result['security_id'])) { $security = new Security(); $security->setId($result['security_id']); $item->setSecurity($security); } if (isset($result['system_client_account_id'])) { $account = new Account(); $account->setId($result['system_client_account_id']); $item->setAccount($account); } if (isset($result['lot_id'])) { $lot = new Lot(); $lot->setId($result['lot_id']); $item->setLot($lot); } return $item; }
public function testIsShortTerm() { $now = new \DateTime(); $this->lot->getInitial()->setDate($now->modify('-1 month')); $this->assertTrue($this->lot->isShortTerm()); $now = new \DateTime(); $this->lot->getInitial()->setDate($now->modify('-10 year -1 month')); $this->assertFalse($this->lot->isShortTerm()); $this->lot->setStatus(Lot::LOT_INITIAL); $now = new \DateTime(); $this->lot->setDate($now->modify('-1 month')); $this->assertTrue($this->lot->isShortTerm()); $now = new \DateTime(); $this->lot->setDate($now->modify('-1 year -1 month')); $this->assertFalse($this->lot->isShortTerm()); }
/** * Check short term redemption * 6.F step in spec * * @param Security $security * @param Lot $lot * @return bool */ public function checkShortTermRedemption(Security $security, Lot $lot) { $client = $this->getClient(); /** @var SecurityTransactionRepository $repository */ $repository = $this->getRepository('SecurityTransaction'); $securityTransaction = $repository->findOneByPortfolioAndSecurity($client->getPortfolio(), $security); if ($securityTransaction && $securityTransaction->isRedemptionFeeSpecified()) { return $lot->interval() <= $securityTransaction->getRedemptionPenaltyInterval(); } return false; }
/** * Find initial lot by lot * If lot in argument is initial then returns it * * @param Lot $lot * @return Lot */ public function getInitialLot(Lot $lot) { if ($lot->isInitial()) { return $lot; } $params = array('id' => $lot->getInitialLotId()); return $this->findOneBy($params); }
public function testLotOrderForMuni() { $positions = array(array('client_system_account_id' => 222, 'muni_id' => 78, 'security_id' => 22222), array('client_system_account_id' => 333, 'muni_id' => null, 'security_id' => 33333)); /** @var LotRepository $mockRepository */ $mockRepository = $this->getMockBuilder('Model\\WealthbotRebalancer\\Repository\\LotRepository')->disableOriginalConstructor()->setMethods(array('getPositionsByPortfolio', 'getLastPositionLots'))->getMock(); $mockRepository->expects($this->any())->method('getPositionsByPortfolio')->will($this->returnValue($positions)); $mockRepository->expects($this->any())->method('getLastPositionLots')->will($this->returnCallback(function (Portfolio $portfolio, $securityId, $clientSystemAccountId, $isMuni = false) { $lotCollection = new LotCollection(); $lot = new Lot(); $lot->setIsMuni($isMuni); $lotCollection->add($lot); return $lotCollection; })); $mockRepository->expects($this->any())->method('findLotsByAccountAndSecurity')->will($this->returnCallback(function (Portfolio $portfolio, $securityId, $clientSystemAccountId, $isMuni = false) { $lotCollection = new LotCollection(); $lot = new Lot(); $lot->setIsMuni($isMuni); $lotCollection->add($lot); return $lotCollection; })); $lotCollection = $mockRepository->findLotsBySubclass(new Portfolio(), new Subclass(), new Account()); $lot1 = $lotCollection->first(); $this->assertFalse($lot1->getIsMuni()); $lot2 = $lotCollection->next(); $this->assertTrue($lot2->getIsMuni()); $lot3 = $lotCollection->next(); $this->assertFalse($lot3->getIsMuni()); //-------------------------------------------------------------------------------------------------------------/ $account = new Account(); $client = new Client(); $client->setPortfolio(new Portfolio()); $account->setClient($client); $lotCollection = $mockRepository->findLotsByAccountAndSecurity($account, new Security()); $lot1 = $lotCollection->first(); $this->assertFalse($lot1->getIsMuni()); $lot2 = $lotCollection->next(); $this->assertTrue($lot2->getIsMuni()); $lot3 = $lotCollection->next(); $this->assertFalse($lot3->getIsMuni()); }