Exemplo n.º 1
0
 /**
  * @param SystemClientAccountModel $account
  */
 public function calculateValue(SystemClientAccountModel $account)
 {
     $todayDate = $this->getCurDate();
     $yesterdayDate = $this->getModifyDate('-1 day');
     // Get today account value
     $todayValue = $this->accountValueRepo->getTodayValue($account->getId(), $todayDate);
     // Get yesterday account value
     $yesterdayValue = $this->accountValueRepo->getYesterdayValue($account->getId(), $todayDate);
     // Calculate NET Cash Flow
     $yesterdayNetCashFlow = Functions::calculateCashFlow($this->transactionRepo->sumContribution($account->getId(), $yesterdayDate), $this->transactionRepo->sumWithdrawal($account->getId(), $yesterdayDate, TransactionRepo::AMOUNT_TYPE_NET));
     // Calculate today NET TWR
     $todayNetTWR = Functions::calculateTodayTwr($todayValue, $yesterdayNetCashFlow, $yesterdayValue);
     // Calculate GROSS Cash Flow
     $yesterdayGrossCashFlow = Functions::calculateCashFlow($this->transactionRepo->sumContribution($account->getId(), $yesterdayDate), $this->transactionRepo->sumWithdrawal($account->getId(), $yesterdayDate, TransactionRepo::AMOUNT_TYPE_GROSS));
     // Calculate today GROSS TWR
     $todayGrossTWR = Functions::calculateTodayTwr($todayValue, $yesterdayGrossCashFlow, $yesterdayValue);
     $model = new AccountTwrValueModel();
     $model->setDate($todayDate->format('Y-m-d'));
     $model->setNetValue($todayNetTWR);
     $model->setGrossValue($todayGrossTWR);
     $model->setAccountNumber($account->getAccountNumber());
     // Save today TWR value
     $this->valueRepo->save($model);
     Factory::get($account->getClientId())->addTodayValue($todayValue);
     Factory::get($account->getClientId())->addYesterdayValue($yesterdayValue);
     Factory::get($account->getClientId())->addYesterdayNetCashFlow($yesterdayNetCashFlow);
     Factory::get($account->getClientId())->addYesterdayGrossCashFlow($yesterdayGrossCashFlow);
 }
 /**
  * @param AccountTwrValue $model
  * @return mixed
  */
 public function save(AccountTwrValue $model)
 {
     $result = $this->fpdo->from($this->table)->where('date = DATE(?)', $model->getDate())->where('account_number', $model->getAccountNumber())->limit(1)->fetch('id');
     return $result ? $this->update($result, $model) : $this->insert($model);
 }