/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Veiculo::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(['renavam' => $this->renavam, 'num_patrimonio' => $this->num_patrimonio, 'potencia' => $this->potencia, 'id_modelo' => $this->id_modelo, 'id_cor' => $this->id_cor, 'id_tipo_combustivel' => $this->id_tipo_combustivel, 'ano_fabricacao' => $this->ano_fabricacao, 'ano_modelo' => $this->ano_modelo]); $query->andFilterWhere(['like', 'cidade', $this->cidade])->andFilterWhere(['like', 'chassi', $this->chassi])->andFilterWhere(['like', 'lotacao', $this->lotacao])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'observacao', $this->observacao])->andFilterWhere(['like', 'adquirido_de', $this->adquirido_de])->andFilterWhere(['like', 'uf_atual', $this->uf_atual])->andFilterWhere(['like', 'uf_anterior', $this->uf_anterior])->andFilterWhere(['like', 'placa_atual', $this->placa_atual])->andFilterWhere(['like', 'placa_anterior', $this->placa_anterior]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIdVeiculo() { return $this->hasOne(Veiculo::className(), ['renavam' => 'id_veiculo']); }
/** * @return \yii\db\ActiveQuery */ public function getVeiculos() { return $this->hasMany(Veiculo::className(), ['id_modelo' => 'id']); }
<div class="abastecimento-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'preco_litro')->textInput(); ?> <?php echo $form->field($model, 'id_posto')->dropDownList(ArrayHelper::map(PostoAbastecimento::find()->all(), 'id', 'nome'), ['prompt' => 'Selecione uma opção']); ?> <?php echo $form->field($model, 'id_veiculo')->dropDownList(ArrayHelper::map(Veiculo::find()->all(), 'renavam', 'placa_atual'), ['prompt' => 'Selecione uma opção']); ?> <?php echo $form->field($model, 'km')->textInput(); ?> <?php echo $form->field($model, 'id_motorista')->dropDownList(ArrayHelper::map(Motorista::find()->all(), 'cnh', 'nome'), ['prompt' => 'Selecione uma opção']); ?> <?php echo $form->field($model, 'data_abastecimento')->widget(DatePicker::className(), ['inline' => false, 'language' => 'pt', 'clientOptions' => ['autoclose' => true, 'format' => 'dd-mm-yyyy']]); ?> <div class="form-group"> <?php
/** * @return \yii\db\ActiveQuery */ public function getidveiculo() { return $this->hasOne(Veiculo::className(), ['idveiculo' => 'idveiculo']); }
/** * @return \yii\db\ActiveQuery */ public function getVeiculos() { return $this->hasMany(Veiculo::className(), ['id_tipo_combustivel' => 'id']); }
/** * Finds the Veiculo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Veiculo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Veiculo::find()->joinWith('atributoveiculo')->where(['veiculo.idveiculo' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Veiculo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Veiculo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Veiculo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }