/** * 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; }
/** * Deletes an existing Reports model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $report_max_id = Reports::find()->max('id'); $state_max_id = \backend\models\State::find()->max('id'); $state_model_with_max_id = \backend\models\State::findOne($state_max_id); /* * if $state_model_with_max_id->input == 0 , * then the last model in the state table is a report * otherwise it would have been an order */ if ($id == $report_max_id && $state_model_with_max_id->input == 0) { /* * TRANSACTION */ $this->findModel($id)->delete(); $state_model_with_max_id->delete(); /* * TRANSACTION */ return $this->redirect(['index']); } else { throw new \yii\web\ForbiddenHttpException('You can NOT delete this report! ' . 'Please, contact the Admin for more information.'); } }