/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Relatorio::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['idrelatorio' => SORT_DESC]]]);
     $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(['idrelatorio' => $this->idrelatorio, 'datageracao' => $this->datageracao, 'inicio_intervalo' => $this->inicio_intervalo, 'fim_intervalo' => $this->fim_intervalo, 'usuario_id' => Yii::$app->user->getId()]);
     $query->andFilterWhere(['like', 'nome', $this->nome])->andFilterWhere(['like', 'tipo', $this->tipo]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRelatorios()
 {
     return $this->hasMany(Relatorio::className(), ['usuario_id' => 'id']);
 }
 /**
  * Finds the Relatorio model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Relatorio the loaded modelRelatorio
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($modelRelatorio = Relatorio::findOne($id)) !== null) {
         return $modelRelatorio;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionRelatorio()
 {
     $model = new Relatorio();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validatedata() == false) {
             return $this->render('relatorio', ['model' => $model]);
         }
         /*       if($model->mesAno!=null) {
         
                   list ($mes, $ano) = split ('[-]', $model->mesAno);
                   $mes = $this->findMonthsNumber($mes);
                     
                   if ($mes < 10) {
                     $model->dataInicial = $ano."-0".$mes."-01";
                     $model->dataFinal = $ano."-0".$mes."-31";
                   } else {
                     $model->dataInicial = $ano."-".$mes."-01";
                     $model->dataFinal = $ano."-".$mes."-31";
                   }
                 }
         
                 if ($model->save()) {*/
         $searchModel = new OcorrenciaSearch();
         if ($model->idLocal != 0) {
             $params['idLocal'] = $model->idLocal;
         }
         if ($model->idCategoria != 0) {
             $params['idCategoria'] = $model->idCategoria;
         }
         if ($model->idNatureza != 0) {
             $params['idNatureza'] = $model->idNatureza;
         }
         if ($model->status != 0) {
             $params['status'] = $model->status;
         }
         if ($model->periodo != 0) {
             $params['periodo'] = $model->periodo;
         }
         if ($model->mesAno == null) {
             $params['dataInicial'] = $model->dataInicial;
             $params['dataFinal'] = $model->dataFinal;
         } else {
             list($mes, $ano) = split('[-]', $model->mesAno);
             $mes = $this->findMonthsNumber($mes);
             if ($mes < 10) {
                 $model->dataInicial = "01/" . "0" . $mes . "/" . $ano;
                 $model->dataFinal = "31/" . "0" . $mes . "/" . $ano;
                 $params['dataInicial'] = "01/" . "0" . $mes . "/" . $ano;
                 $params['dataFinal'] = "31/" . "0" . $mes . "/" . $ano;
             } else {
                 $model->dataInicial = "01/" . $mes . "/" . $ano;
                 $model->dataFinal = "31/" . $mes . "/" . $ano;
                 $params['dataInicial'] = "01/" . $mes . "/" . $ano;
                 $params['dataFinal'] = "31/" . $mes . "/" . $ano;
             }
         }
         $dataProvider = $searchModel->relatorio(['OcorrenciaSearch' => $params]);
         //                return $this->redirect(['view', 'id' => $model->idOcorrencia]);
         return $this->render('indexrelatorio', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     } else {
         return $this->render('relatorio', ['model' => $model]);
     }
 }