/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ingreso::find(); //->where();//(['autoSave'=>'N']); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['descripcion', 'fechaEntrada', 'fechaBaja', 'observaciones', 'personaName' => ['asc' => ['concat(coalesce(persona.apellido,""),coalesce(persona.nombre,""))' => SORT_ASC], 'desc' => ['concat(coalesce(persona.apellido,""),coalesce(persona.nombre,""))' => SORT_DESC], 'label' => 'Persona']]]); $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'); $query->joinWith(['persona']); return $dataProvider; } $query->andFilterWhere(['ingreso.id' => $this->id, 'fechaEntrada' => $this->fechaEntrada, 'fechaBaja' => $this->fechaBaja, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'observaciones', $this->observaciones]); if (trim($this->personaName) != '') { $query->joinWith(['persona' => function ($q) { $q->where('concat(coalesce(persona.apellido,""),coalesce(persona.nombre,"")) LIKE "%' . $this->personaName . '%"'); }]); } else { $query->joinWith('persona'); } return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIngresos() { return $this->hasMany(Ingreso::className(), ['persona_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getIngreso() { return $this->hasOne(Ingreso::className(), ['id' => 'ingreso_id']); }
public function getAll() { return Ingreso::all(); }
/** * Finds the Ingreso model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ingreso the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ingreso::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }