Esempio n. 1
0
 public function findSecuritiesByAccount(Account $account)
 {
     $sql = "SELECT s.id, s.name AS name, s.symbol AS symbol, sp.price AS price, pos.quantity AS qty,\n                  IFNULL((SELECT 1 FROM " . self::TABLE_CE_MODEL . " cem\n                            LEFT JOIN " . self::TABLE_CLIENT_PORTFOLIO . " cp ON (cp.portfolio_id = cem.id)\n                            LEFT JOIN " . self::TABLE_SECURITY_ASSIGNMENT . " sa ON sa.model_id = cem.id\n                          WHERE sa.security_id = s.id AND cp.is_active = 1 AND cem.owner_id = :client_id\n                        ), 0) as isPreferredBuy\n                FROM " . self::TABLE_POSITION . " pos\n                  LEFT JOIN " . self::TABLE_SYSTEM_ACCOUNT . " sca ON pos.client_system_account_id = sca.id\n                  LEFT JOIN " . self::TABLE_SECURITY . " s ON s.id = pos.security_id\n                  LEFT JOIN " . self::TABLE_SECURITY_PRICE . " sp ON (sp.security_id = s.id  AND sp.is_current = true)\n                WHERE sca.id = :account_id AND pos.status = :position_status;\n        ";
     $parameters = array('account_id' => $account->getId(), 'position_status' => Security::POSITION_STATUS_IS_OPEN, 'client_id' => $account->getClient()->getId());
     $result = $this->db->query($sql, $parameters);
     return $this->bindCollection($result);
 }
Esempio n. 2
0
 public function testSetClient()
 {
     $newClient = new Client();
     $newClient->setId(29);
     $this->account->setClient($newClient);
     $this->assertEquals(29, $this->account->getClient()->getId());
 }
Esempio n. 3
0
 /**
  * Checks if transaction is allowed
  *
  * @param  Account    $account [description]
  * @param  amountOfTransaction [$ value of transaction buy/sell]
  * @param  security            [which security are we selling?]
  * @param  txType              [type of transaction buy/sell]
  * @return [bool]      [true/false if transaction passes the filters or not]
  */
 public function checkTransaction(Account $account, $amountOfTransaction, $security = null, $txType = null)
 {
     $ria = $account->getClient()->getRia();
     $totalCash = $account->getTotalCash();
     if (empty($totalCash) || $totalCash == 0) {
         return false;
     }
     $txAmountPercent = round($amountOfTransaction / $totalCash * 100, 2);
     if (!is_null($security) && !is_null($txType)) {
         $client = $account->getClient();
         $repository = $this->getRepository('SecurityTransaction');
         $securityTransaction = $repository->findOneByPortfolioAndSecurity($client->getPortfolio(), $security);
         if ($txType === 'sell' && $amountOfTransaction >= $securityTransaction->getMinimumSell()) {
             return true;
         }
         if ($txType === 'buy' && $amountOfTransaction >= $securityTransaction->getMinimumBuy()) {
             return true;
         }
         $this->logger->logInfo("Minimum buy/sell failed for {$security->getId()}, RIA: {$ria->getId()}");
         return false;
     }
     //TODO: need more logging
     if (!$ria->getRiaCompanyInformation()->getUseTransactionFees()) {
         return true;
     }
     if ($amountOfTransaction >= $ria->getRiaCompanyInformation()->getTransactionMinAmount()) {
         return true;
     }
     if ($txAmountPercent >= $ria->getRiaCompanyInformation()->getTransactionMinAmountPercent()) {
         return true;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * @param Account $account
  * @param Security $security
  * @return LotCollection
  */
 public function findLotsByAccountAndSecurity(Account $account, Security $security)
 {
     $portfolio = $account->getClient()->getPortfolio();
     $positions = $this->getPositionsByPortfolio($portfolio, $account, $security);
     $lotCollection = new LotCollection();
     foreach ($positions as $position) {
         $lots = $this->getLastPositionLots($portfolio, $position['security_id'], $position['client_system_account_id']);
         foreach ($lots as $lot) {
             $lotCollection->add($lot);
         }
         if ($position['muni_id']) {
             $muniLots = $this->getLastPositionLots($portfolio, $position['muni_id'], $position['client_system_account_id'], true);
             foreach ($muniLots as $muniLot) {
                 $lotCollection->add($muniLot);
             }
         }
     }
     return $lotCollection;
 }