/** * finds the row of summed fields from reports * @return type query */ private function sumOfReports() { $q = Reports::find(); $q->joinWith(['user']); $q->select(['" " as `id`', ' " " as `user_id`', 'sum(revenue)', 'sum(expense_on_goods)', 'sum(other_expenses)', 'sum(salary)', '" " as`day_type`', '" " as `date`', '" " as `created_at`', '" " as `updated_at`'])->from('reports'); return $q; }
/** * * @return ActiveDataProvider */ public function searchPerformance() { $userID = Yii::$app->user->identity->id; $query = Reports::find()->select(['MONTH(date) as "month"', 'SUM(revenue) as "totalRevenue"', 'AVG(salary) as "averageSalaryPerDay"', 'COUNT(id) as "numberOfWorkedDays"', 'SUM(salary) as "totalSalary"'])->from('reports')->andFilterWhere(['user_id' => $userID])->andFilterWhere(['<=', "date", Date('Y-m-d')])->andFilterWhere(['>=', "date", $this->currentDateMinusSixMonths()])->groupBy("MONTH(date)")->orderBy('date'); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
/** * Finds the Reports model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Reports the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Reports::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }