/** * @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); }
/** * Update * * @param int $id * @param ClientAccountValue $model * @return bool */ public function update($id, ClientAccountValue $model) { return $this->fpdo->update($this->table, array('total_value' => $model->getTotalValue(), 'total_in_securities' => $model->getTotalInSecurities(), 'total_cash_in_account' => $model->getTotalCashInAccount(), 'total_cash_in_money_market' => $model->getTotalCashInMoneyMarket(), 'sas_cash' => $model->getSasCash(), 'cash_buffer' => $model->getCashBuffer(), 'billing_cash' => $model->getBillingCash()), $id)->execute(); }