public function actionIndex()
 {
     $endDateStat = Carbon::create()->timezone("Asia/Irkutsk");
     $startDateYearStat = clone $endDateStat;
     $startDateMonthStat = clone $startDateYearStat;
     $startDateYearStat->subYear()->addMonth()->firstOfMonth();
     $startDateMonthStat->subDays(29)->startOfDay();
     $endDateStat->addDay()->startOfDay();
     $payYearStat = Pay::find()->select('SUM(`bonus_cash`) `sum_bonus_cash`, COUNT(*) `count`, SUM(`cash`) `sum_cash`, MONTH(`create_at`) `month`')->where("`create_at` BETWEEN '{$startDateYearStat->toDateTimeString()}' and '{$endDateStat->toDateTimeString()}'")->groupBy('`month`')->orderBy('create_at')->all();
     $payMonthStat = Pay::find()->select('SUM(`bonus_cash`) `sum_bonus_cash`, COUNT(*) `count`, SUM(`cash`) `sum_cash`, DATE_FORMAT(`create_at`,"%e/%m") `date`')->where("`create_at` BETWEEN '{$startDateMonthStat->toDateTimeString()}' and '{$endDateStat->toDateTimeString()}'")->groupBy('`date`')->orderBy('`create_at`')->all();
     return $this->render('index', ['payStat' => $payYearStat, 'payMonthStat' => $payMonthStat]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Pay::find()->joinWith(['profile', 'ticket']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['create_at' => SORT_DESC]]]);
     /**
      * Настройка параметров сортировки
      * Важно: должна быть выполнена раньше $this->load($params)
      * statement below
      */
     $dataProvider->sort->attributes['userFullName'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC, Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC, Profile::tableName() . '.surname' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, Pay::tableName() . '.user_id' => $this->user_id, 'ticket_id' => $this->ticket_id, 'current_cost' => $this->current_cost, 'cash' => $this->cash, 'bonus_cash' => $this->bonus_cash]);
     $query->andFilterWhere($this->getBetweenDatesFilterArray('create_at', ' - ', 'Y-m-d H:i:s'))->andFilterWhere(['like', 'comment', $this->comment]);
     $query->andFilterWhere(['like', 'CONCAT(" ", ' . Profile::tableName() . '.name, ' . Profile::tableName() . '.surname) ', $this->userFullName]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPay()
 {
     return $this->hasOne(Pay::className(), ['id' => 'pay_id']);
 }
 /**
  * Finds the Pay model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Pay the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelAll($id)
 {
     if (($model = Pay::find()->where(['id' => $id])->all()) !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
 /**
  * Displays a single User model.
  * @return mixed
  */
 public function actionViewPay($id)
 {
     $paidEmployment = new ActiveDataProvider(['query' => PaidEmployment::find()->select(['{{%paid_employment}}.timetable_id', '{{%paid_employment}}.date', '{{%timetable}}.start', '{{%timetable}}.end', '{{%group}}.name'])->joinWith('timetable.group')->where(['pay_id' => $id])->orderBy('date'), 'pagination' => ['pageSize' => 30], 'sort' => false]);
     $model = Pay::find()->where('id = :id AND user_id=' . Yii::$app->user->id, [':id' => $id])->one();
     if (!$model) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     return $this->render('view_pay', ['model' => $model, 'paidEmployment' => $paidEmployment]);
 }