/** * 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 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 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(); } } }