/** * 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; }
public function testSetTotalCash() { $this->account->setTotalCash(8000); $this->assertEquals(8000, $this->account->getTotalCash()); }