'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], ['types', 'each', 'rule' => ['integer']], ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Transfer::find(); $query->innerJoinWith('account'); if ( !RoleDefinition::isAdmin() ){ $query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' ); $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); $query->andWhere(['account.type' => Account::TYPE_ALL ]); if ( RoleDefinition::isReception()){ $query->andWhere(['transfer.id_user' => Yii::$app->user->id ]); } } $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $query->addSelect( ['*' ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'transfer.id_account' => $this->id_account, 'transfer.type' => $this->type, 'transfer.id_user' => $this->id_user, ]); $created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ]; $paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ]; $query->andFilterWhere(['or' , $created_condition , $paid_condition]); return $dataProvider; } public function totalsTransfers( ){ $accountTotals = []; $fullTotal = [ 'label' => Yii::t('common/transfer', 'Total'), 'money' => 0 ]; $accounts = Account::read(); $accountMap = ArrayHelper::map( $accounts ,'id_account','name' ); $idUser = $this->id_user; $this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap); } }