public function executeIndex(sfWebRequest $request) { // System balance $this->sysBalance = BalanceSystem::getCurrentBalanceInstance(); $this->balanceUser = BalanceUserTable::getInstance(); // sorting if ($request->getParameter('sort') && $this->isValidSortColumn($request->getParameter('sort'))) { $this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type'))); } // pager if ($request->getParameter('page')) { $this->setPage($request->getParameter('page')); } $this->pager = $this->getPager(); $this->sort = $this->getSort(); }
public function puserDailyPayment(User $oUser, BalanceSystem $oBalanceSystem, array &$aTariffs) { $this->setPeriod(Period::getCurrentPeriod()); $this->setOperation('charges_service'); $fAmount = $aTariffs[$oUser->getTariff()]; $this->setAmount($fAmount); // Sender $this->setIdSender($oUser->getId()); $this->setSenderBalanceBefore($oUser->getBalans()); // Set user balance and save $itog = $oUser->getBalans() - $fAmount; if ($itog < 0) { $oUser->setIsBlocked(1); $oUser->save(); return; } $oUser->setBalans($oUser->getBalans() - $fAmount); $oUser->save(); // $this->setSenderBalanceAfter($oUser->getBalans()); // Recipient - Read2Read $this->setIdReceiver(0); $this->setReceiverBalanceBefore(0); $this->setReceiverBalanceAfter(0); $sGetMethod = 'getCharges' . ucfirst($oUser->getTariff()); $sSetMethod = 'setCharges' . ucfirst($oUser->getTariff()); $bal = $oBalanceSystem->{$sGetMethod}(); $bal += $fAmount; $oBalanceSystem->{$sSetMethod}($bal); $oBalanceSystem->save(); $oBalanceUser = BalanceUserTable::getByUserIdAndPeriodId($oUser->getId()); $oBalanceUser->setUsePayment($oBalanceUser->getUsePayment() + $fAmount); $oBalanceUser->save(); // Save transaction $this->save(); if ($itog < $fAmount) { $oUser->setIsBlocked(1); $oUser->save(); } }
public static function processMP($mpfile) { $paid = 0; foreach ($mpfile as $str) { $pm = explode(';', $str); if (!preg_match('/^MassPay Transaction.*payId:([\\d]+)$/', str_replace('"', '', $pm[6]), $pId)) { continue; } else { $paid += BalanceUserTable::setPaid($pId[1], floatval($pm[2])); } } return $paid; }
/** * Return object BalanceUser by period ID. If $period_id return * BalanceUser by current period * * @param int $period_id * @return insrance BalanceUser */ public function getUserBalanceByPeriodId($period_id = 0) { if (is_null($period_id)) { $balance = false; } else { $balance = BalanceUserTable::getByUserIdAndPeriodId($this->getId(), $period_id); } return $balance; }
public static function countWeights(Period $period) { // общая сумма продаж $tSum = BalanceSystemTable::getInstance()->findOneByIdPeriod($period->getId())->getToPayPUsers(); $q = UserTable::addPUserQuery()->execute(); foreach ($q as $user) { if (($bu = BalanceUserTable::getByUserIdAndPeriodId($user->getId(), $period->getId())) !== false) { $uWeight = $bu->getPayable() * 100 / $tSum; $user->setWeight((double) $uWeight); $user->save(); } } }