/** * Creates a new Relatorio model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $modelRelatorio = new Relatorio(); if ($modelRelatorio->load(Yii::$app->request->post()) && $modelRelatorio->save()) { return $this->redirect(['relatorio' . strtolower($modelRelatorio->tipo), 'id' => $modelRelatorio->idrelatorio]); } else { $modelRelatorio->inicio_intervalo = date('Y-m-d'); $modelRelatorio->fim_intervalo = date('Y-m-d'); return $this->render('create', ['modelRelatorio' => $modelRelatorio, 'tiposRelatorio' => $this->tiposRelatorio]); } }
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]); } }