コード例 #1
0
 /**
  * Добавляем перевод со счёта на счёт
  *
  * @param float  $money
  * @param float  $convert
  * @param float  $exchangeRate
  * @param date   $date
  * @param int    $fromAccount
  * @param int    $toAccount
  * @param string $comment
  * @param array $tags
  * @return int
  */
 function addTransfer($money, $convert, $exchangeRate, $date, $fromAccount, $toAccount, $comment, array $tags = array(), $accepted = 1, $chain = 0, $reloadUser = true)
 {
     $accounts = $this->_user->getUserAccounts();
     $categoryId = null;
     if (in_array($accounts[$toAccount]['account_type_id'], array(Account_Collection::ACCOUNT_TYPE_CREDIT, Account_Collection::ACCOUNT_TYPE_CREDITCARD, Account_Collection::ACCOUNT_TYPE_LOANGET)) && in_array($accounts[$fromAccount]['account_type_id'], array(Account_Collection::ACCOUNT_TYPE_CASH, Account_Collection::ACCOUNT_TYPE_DEBETCARD, Account_Collection::ACCOUNT_TYPE_DEPOSIT, Account_Collection::ACCOUNT_TYPE_LOANGIVE, Account_Collection::ACCOUNT_TYPE_ELECTPURSE, Account_Collection::ACCOUNT_TYPE_BANKACC))) {
         $categoryId = $this->_user->getUserDebtCategoryId();
     }
     $values = array('user_id' => $this->_user->getId(), 'money' => abs($money) * -1, 'date' => $date, 'cat_id' => $categoryId, 'account_id' => $fromAccount, 'comment' => $comment, 'transfer_account_id' => $toAccount, 'type' => 2, 'exchange_rate' => $exchangeRate, 'transfer_amount' => $this->_convertAmount($fromAccount, $toAccount, $money, $convert), 'tags' => implode(', ', $tags), 'accepted' => !empty($accepted) ? (int) $accepted : 0, 'chain_id' => !empty($chain) ? (int) $chain : 0);
     $lastId = $this->_addOperation($values);
     if ($reloadUser) {
         $this->_user->initUserAccounts();
         $this->_user->save();
     }
     return $lastId;
 }