Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Sublocal::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['idSubLocal' => $this->idSubLocal, 'idLocal' => $this->idLocal]);
     $query->andFilterWhere(['like', 'Nome', $this->Nome]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionSublocalselected($idLocal, $idSublocal)
 {
     $countSublocais = SubLocal::find()->where(['idLocal' => $idLocal])->count();
     $subLocal = Sublocal::find()->where(['idLocal' => $idLocal])->all();
     if ($countSublocais > 0) {
         foreach ($subLocal as $branch) {
             if ($branch->idSubLocal == $idSublocal) {
                 echo "<option value='" . $branch->idSubLocal . "' selected>" . $branch->Nome . "</option>";
             } else {
                 echo "<option value='" . $branch->idSubLocal . "'>" . $branch->Nome . "</option>";
             }
         }
     } else {
         echo "<options>Não possui sublocal</options>";
     }
 }
Exemplo n.º 3
0
 public function relatorio($params)
 {
     $query = Ocorrencia::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $databkp = $this->data;
     if ($this->dataInicial != null) {
         list($dia, $mes, $ano) = split('[/]', $this->dataInicial);
         $this->dataInicial = $ano . '-' . $mes . '-' . $dia;
     }
     if ($this->dataFinal != null) {
         list($dia, $mes, $ano) = split('[/]', $this->dataFinal);
         $this->dataFinal = $ano . '-' . $mes . '-' . $dia;
     }
     //       if ($this->idLocal!=null)
     $sublocal = Sublocal::find()->where(['=', 'idLocal', $this->idLocal])->all();
     //$model->idSubLocal = $sublocal->Nome;
     $query->andFilterWhere(['status' => $this->status, 'idCategoria' => $this->idCategoria, 'idNatureza' => $this->idNatureza, 'periodo' => $this->periodo]);
     $query->andFilterWhere(['>=', 'data', $this->dataInicial]);
     $query->andFilterWhere(['<=', 'data', $this->dataFinal]);
     if ($this->idLocal != null) {
         $connection = \Yii::$app->db;
         $stringsql = "SELECT idSubLocal as idsublocal FROM sublocal WHERE idLocal = " . $this->idLocal;
         $sqlOcorrencia = $connection->createCommand($stringsql);
         $rstocorencia = $sqlOcorrencia->queryAll();
         $arraysublocal = array();
         $i = 0;
         foreach ($rstocorencia as $reg) {
             $arraysublocal[$i] = $reg['idsublocal'];
             $i = $i + 1;
         }
         $query->andFilterWhere(['IN', 'idSubLocal', $arraysublocal]);
     }
     return $dataProvider;
 }