/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Autorizantes::find()->joinWith('persona');
     $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['autorizantes.defaultPageSize'];
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['id_uf' => SORT_ASC], 'enableMultiSort' => false]]);
     // Agregado a mano, para que incluya el ordenamiento por tipo de documento
     $dataProvider->sort->attributes['apellido'] = ['asc' => ['personas.apellido' => SORT_ASC], 'desc' => ['personas.apellido' => SORT_DESC]];
     $dataProvider->sort->attributes['nombre'] = ['asc' => ['personas.nombre' => SORT_ASC], 'desc' => ['personas.nombre' => SORT_DESC]];
     $dataProvider->sort->attributes['nombre2'] = ['asc' => ['personas.nombre2' => SORT_ASC], 'desc' => ['personas.nombre2' => SORT_DESC]];
     $dataProvider->sort->attributes['nro_doc'] = ['asc' => ['personas.nro_doc' => SORT_ASC], 'desc' => ['personas.nro_doc' => 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(['id' => $this->id, 'id_uf' => $this->id_uf, 'id_persona' => $this->id_persona]);
     $query->andFilterWhere(['like', 'apellido', $this->apellido])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'nombre2', $this->nombre2])->andFilterWhere(['like', 'nro_doc', $this->nro_doc]);
     return $dataProvider;
 }
 public function actionBuscaUltIngreso($grupo, $id)
 {
     // $grupo puede ser 'ingpersonas' o 'ingvehiculos'
     if (empty($id)) {
         return;
     }
     if ($grupo !== 'ingpersonas' && $grupo !== 'ingvehiculos') {
         return;
     }
     if ($grupo == 'ingpersonas') {
         $ult = Accesos::find()->where(['id_persona' => $id])->andWhere(['>', 'id_concepto', 0])->orderBy(['id' => SORT_DESC])->asArray()->one();
     } else {
         $ult = Accesos::find()->where(['ing_id_vehiculo' => $id])->andWhere(['>', 'id_concepto', 0])->orderBy(['id' => SORT_DESC])->asArray()->one();
     }
     Yii::trace($ult);
     \Yii::$app->response->format = 'json';
     $a = Accesos::findOne($ult['id']);
     if (!empty($a)) {
         $raux = '';
         foreach ($a->accesosAutorizantes as $aa) {
             // se debe controlar que los autorizantes del ultimo ingreso sigan siendo autorizantes
             $aut = Autorizantes::find()->where(['id_uf' => $aa->id_uf, 'id_persona' => $aa->id_persona])->one();
             if (!empty($aut)) {
                 $raux = $this->actionAddLista('autorizantes', $aut->id);
             }
         }
         $ult['motivo_baja'] = $raux;
     } else {
         $ult = 'notFound';
     }
     return $ult;
 }