public function setUp()
 {
     $this->curDate = new \DateTime('2014-11-29');
     $accountValues = array(array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 101000, 'date' => '2014-11-27'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 202000, 'date' => '2014-11-28'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 303000, 'date' => '2014-11-29'), array('client_portfolio_id' => 2, 'system_client_account_id' => 2, 'total_value' => 404000, 'date' => '2014-11-30'));
     $repository = new ClientAccountValueRepo();
     foreach ($accountValues as $value) {
         $model = new ClientAccountValueModel();
         $model->loadFromArray($value);
         $repository->save($model);
     }
     $transactionValues = array(array('account_id' => 2, 'transaction_type_id' => 24, 'closing_method_id' => 6, 'security_id' => 11, 'tx_date' => '2014-11-28', 'qty' => 30, 'net_amount' => 3000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 41, 'closing_method_id' => 6, 'security_id' => 482, 'tx_date' => '2014-11-28', 'qty' => 40, 'net_amount' => 4000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-28', 'qty' => 20, 'net_amount' => 2000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-29', 'qty' => 30, 'net_amount' => 2000, 'gross_amount' => 0), array('account_id' => 2, 'transaction_type_id' => 42, 'closing_method_id' => 6, 'security_id' => 13, 'tx_date' => '2014-11-30', 'qty' => 31, 'net_amount' => 2000, 'gross_amount' => 0));
     $repository = new TransactionRepo();
     foreach ($transactionValues as $value) {
         $model = new TransactionModel();
         $model->loadFromArray($value);
         $repository->save($model);
     }
     $accounts[6][] = $this->getModelMock('SystemClientAccount', array('id' => 2, 'client_id' => 6, 'account_number' => '409888117', 'closed' => '2014-11-29', 'status' => SystemAccount::STATUS_CLOSED));
     $calculator = $this->getMockBuilder('Pas\\TwrCalculator')->disableOriginalConstructor()->setMethods(array('getAllAccounts'))->getMock();
     $calculator->expects($this->any())->method('getAllAccounts')->will($this->returnValue($accounts));
     $calculator->run('2014-11-29');
     $calculator->run('2014-11-30');
 }
Beispiel #2
0
 /**
  * @param string $startDate
  * @param string $endDate
  */
 public function run($startDate, $endDate)
 {
     // Get all account by date from mongo
     $accountNumbers = $this->docPositionRepo->getUniqueAccount($startDate, $endDate);
     foreach ($accountNumbers as $accountNumber) {
         // Check account exists
         if (null == ($account = $this->getAccount($accountNumber))) {
             $this->docPositionRepo->changeStatusByAccountNumber($accountNumber, $startDate, $endDate, DocumentBaseRepo::STATUS_NOT_POSTED);
             continue;
         }
         // Check portfolio exists
         if (null == ($portfolio = $this->getPortfolio($account))) {
             $this->docPositionRepo->changeStatusByAccountNumber($accountNumber, $startDate, $endDate, DocumentBaseRepo::STATUS_NOT_POSTED);
             continue;
         }
         $model = new ClientAccountValueModel();
         // Get all position by account number
         $positions = $this->docPositionRepo->getAllByAccountNumber($accountNumber, $startDate, $endDate);
         foreach ($positions as $position) {
             $position['security_type'] == SecurityModel::SYMBOL_IDA12 || $position['symbol'] == SecurityModel::SYMBOL_CASH ? $model->setTotalCashInMoneyMarket($model->getTotalCashInMoneyMarket() + (double) $position['amount']) : $model->setTotalInSecurities($model->getTotalInSecurities() + (double) $position['amount']);
         }
         $model->setDate($startDate);
         $model->setClientPortfolioId($portfolio->getId());
         $model->setSystemClientAccountId($account->getId());
         // Save client account value
         $this->clientAccountValueRepo->save($model);
     }
     // Calculate client portfolio value
     $this->calculateClientPortfolioValue($startDate);
 }
 /**
  * @param ClientAccountValue $model
  * @return int|bool
  */
 public function save(ClientAccountValue $model)
 {
     $result = $this->fpdo->from($this->table)->where('system_client_account_id', $model->getSystemClientAccountId())->where('date = DATE(?)', $model->getDate())->limit(1)->fetch('id');
     return $result ? $this->update($result, $model) : $this->insert($model);
 }