S
S
Svetlana Galenko2019-05-31 15:23:56
Yii
Svetlana Galenko, 2019-05-31 15:23:56

How to sum up the total amount of all payments from the database in yii and display it on the screen?

Good afternoon, the question arose, how to add up the total amount of all payments from the database in yii and display it on the screen?
UserPayout.php:

class UserPayout extends CActiveRecord
{
  public
        $id,
  $user_id,
        $system,
        $currency,
        $purse,
        $sum,
        $create_time,
        $status;

  public function tableName()
  {
    return '{{users_payouts}}';
  }

  public function rules()
  {
    return array(	
      // create
      array('sum, system, purse, currency', 'required', 'on' => self::SCENARIO_CREATE),
      array('sum', 'numerical', 'integerOnly'=>true, 'on' => self::SCENARIO_CREATE, 'message'=>'Сумма должна быть целым числом.'),
      array('sum', 'checkSumValue', 'on' => self::SCENARIO_CREATE),
      array('currency', 'isCurrencyValid', 'on' => self::SCENARIO_CREATE),
            array('purse', 'isPurseValid', 'on' => self::SCENARIO_CREATE),
      
      // update
      array('id', 'required', 'on' => self::SCENARIO_UPDATE),
      
      // system & currency update
      array('currency', 'safe', 'on' => self::SCENARIO_SYSTEM_UPDATE),
      array('system', 'safe', 'on' => self::SCENARIO_CURRENCY_UPDATE),

      // search
                       array('id, username_search, system, currency, purse, sum, data, create_time, status, from_date, to_date', 'safe', 'on'=>self::SCENARIO_SEARCH),

      // rules
      array('id', 'exist', 'attributeName'=>'id'),
      array('system', 'in', 'range' => $this->getSystemValidValues()),
      array('currency', 'in', 'range' => ICurrency::getValidValues()),
      array('sum', 'length', 'min'=>1, 'max'=>8),
      array('purse', 'filter', 'filter' => array($obj=new CHtmlPurifier(),'purify')),
    );
  }
}

You need to display here the sum of all payments, namely $sum:
Example:
<h2>Всего выплат в рублях: <?= (new UserPayout)->find('sum')->count()?> Р</h2>

With this code, I do not add up the total amount of payments, but only the number of users to whom the amount was paid is displayed. Help me please..(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coderisimo, 2019-06-01
@swallow_97

$query = (new \yii\db\Query())->from('users_payouts');
// вот это будет сумма 
$sum = $query->sum('sum');
echo $sum;

M
Maxim Timofeev, 2017-06-20
@webov_web

the usual wizard, the network is full of examples:
https://yandex.ru/search/?text=wizard%20jquery&cli ...
www.jquery-steps.com/Examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question