/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Wagon::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->joinWith('wagonStatusIdStatus'); $query->joinWith('stationStation'); $query->joinWith('kindOfWagonKind'); $query->andFilterWhere(['wagon_id' => $this->wagon_id, 'wagon_number' => $this->wagon_number, 'created_year' => $this->created_year, 'start_date' => $this->start_date]); $query->andFilterWhere(['like', 'wagon_status.status_id', $this->wagon_status_id_status]); $query->andFilterWhere(['like', 'station.station_id', $this->station_station_id]); $query->andFilterWhere(['like', 'kind_of_wagon.kind_id', $this->kind_of_wagon_kind_id]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getWagonWagon() { return $this->hasOne(Wagon::className(), ['wagon_id' => 'wagon_wagon_id']); }
<h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Date Repair', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'begin_day', 'value' => 'begin_day', 'contentOptions' => ['style' => 'width:10%'], 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'begin_day', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'repair_day', 'contentOptions' => ['style' => 'width:10%'], 'value' => function ($data) { $date = date("d-m-Y", strtotime($data["repair_day"])); $date2 = new DateTime($date); $date2->add(new DateInterval('P20M')); return $date2->format("Y-m-d"); }, 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'repair_day', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'repair_complete_day', 'contentOptions' => ['style' => 'width:10%'], 'value' => function ($data) { $date = date("d-m-Y", strtotime($data["repair_day"])); $date2 = new DateTime($date); $date2->add(new DateInterval('P20M')); $date2 = $date2->add(new DateInterval('P10D')); return $date2->format("Y-m-d"); }, 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'repair_complete_day', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'wagon_wagon_id', 'value' => 'wagonWagon.wagon_number', 'filter' => Html::activeDropDownList($searchModel, 'wagon_wagon_id', ArrayHelper::map(Wagon::find()->all(), 'wagon_id', 'wagon_number'), ['class' => 'form-control', 'prompt' => 'Please select...'])], ['attribute' => 'brand_repair_brand_repair_id', 'value' => 'brandRepairBrandRepair.name', 'filter' => Html::activeDropDownList($searchModel, 'brand_repair_brand_repair_id', ArrayHelper::map(\app\models\BrandRepair::find()->all(), 'brand_repair_id', 'name'), ['class' => 'form-control', 'prompt' => 'Please select...'])], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getWagons() { return $this->hasMany(Wagon::className(), ['wagon_status_id_status' => 'status_id']); }
/** * @return \yii\db\ActiveQuery */ public function getWagons() { return $this->hasMany(Wagon::className(), ['kind_of_wagon_kind_id' => 'kind_id']); }
/** * Finds the Wagon model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Wagon the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Wagon::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php echo $form->field($model, 'begin_day')->widget(DatePicker::className(), ['inline' => false, 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'repair_day')->widget(DatePicker::className(), ['inline' => false, 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'repair_complete_day')->widget(DatePicker::className(), ['inline' => false, 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'wagon_wagon_id')->dropDownList(ArrayHelper::map(Wagon::find()->all(), 'wagon_id', 'wagon_number'), ['prompt' => 'Số hiệu toa...']); ?> <?php echo $form->field($model, 'brand_repair_brand_repair_id')->dropDownList(ArrayHelper::map(BrandRepair::find()->all(), 'brand_repair_id', 'name'), ['prompt' => 'Hãng sửa chữa...']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>