public static function getCurrentBalanceInstance() { $sysBalance = BalanceSystemTable::getInstance()->findOneByIdPeriod(Period::getCurrentPeriod()->getId()); if (!$sysBalance) { $sysBalance = new BalanceSystem(); $sysBalance->setPeriod(Period::getCurrentPeriod()); $sysBalance->countInBalance(); $sysBalance->save(); } return $sysBalance; }
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(); } }