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() { $aTariffs = SettingTable::getAllTariffs(); $oBalanceSystem = BalanceSystem::getCurrentBalanceInstance(); $aPUsers = UserTable::getPUsersActive(); foreach ($aPUsers as $oPUser) { $transaction = new Transaction(); $transaction->puserDailyPayment($oPUser, $oBalanceSystem, $aTariffs); } }
public function executeProcessMP(sfWebRequest $request) { $this->executePpayment($request); $this->form->bind($request->getPostParameters(), $request->getFiles()); if ($this->form->isValid()) { $mpfile = file($this->form->getValue('mpfile')->getTempName()); $this->paid = BalanceSystem::ProcessMP($mpfile); $this->getUser()->setFlash('notice', 'Файл с выпиской обработан'); } $this->setTemplate('ppayment'); }
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 addFundsFin(Transaction $transaction) { if ($transaction->getIsPaid()) { // транзакция уже была обработана return false; } else { $transaction->addFundsFin(); } // set new balance $user = UserTable::getInstance()->findOneById($transaction->getIdReceiver()); $user->setBalans($transaction->getReceiverBalanceAfter()); $user->save(); $amount = $transaction->getAmount(); // write to BalanceUser instance if (!($userBalance = BalanceUserTable::getByUserIdAndPeriodId($user->getId()))) { $userBalance = new BalanceUser(); $userBalance->setPeriod(Period::getCurrentPeriod()); $userBalance->setUser($user); } $userBalance->setAddFunds($userBalance->getAddFunds() + $amount); $userBalance->save(); if (!($systemBalance = BalanceSystem::getCurrentBalanceInstance())) { sfContext::getInstance()->getLogger()->info('aS4W Error: getCurrentBalanceInstance return false'); return false; } if ($user->getUSerTypePrefix() == 'u') { $systemBalance->setDepositUser($systemBalance->getDepositUser() + $amount); } else { switch ($user->getTariff()) { case 'standart': $systemBalance->setDepositStandart($systemBalance->getDepositStandart() + $amount); break; case 'super': $systemBalance->setDepositSuper($systemBalance->getDepositSuper() + $amount); break; case 'expert': $systemBalance->setDepositExpert($systemBalance->getDepositExpert() + $amount); break; } } $systemBalance->save(); // If user blocked try UnBlock if ($user->is_blocked) { $user->tryUnBlockUser(); } return true; }
<div id="sf_admin_container"> <h1><?php echo __('Выплаты р_пользователям', array(), 'messages'); ?> </h1> <?php include_partial('balance/flashes'); ?> <div id="sf_admin_content"> <table cellspacing="0" width="100%"> <tr> <th width="20%">Итого к выплате</th> <th width="20%"> </th> <th width="20%"><?php echo number_format(BalanceSystem::genMassPayWM(false), 2, '.', ''); ?> </th> <th width="20%"><input type="button" value="Создать файл для массовых выплат" onclick="location.href='<?php echo url_for('@payment_getmp'); ?> '" /></th> <th> </th> </tr> <tr class="sf_admin_row odd"> <td colspan="3">Итого выплачено</td> <td> <form action="<?php echo url_for('@payment_processmp'); ?> " method="post" enctype="multipart/form-data">