From: fomichev Date: Mon, 17 Feb 2025 14:59:26 +0000 (+0300) Subject: Фильтры X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=3b546a35710dba76162766d4b06e6a325636d220;p=erp24_rep%2Fyii-erp24%2F.git Фильтры --- diff --git a/erp24/controllers/Products1cNomenclatureController.php b/erp24/controllers/Products1cNomenclatureController.php index abfff6d6..ab0d8ef6 100644 --- a/erp24/controllers/Products1cNomenclatureController.php +++ b/erp24/controllers/Products1cNomenclatureController.php @@ -3,7 +3,7 @@ namespace app\controllers; use yii_app\records\Products1cNomenclature; -use yii\data\ActiveDataProvider; +use yii_app\records\Products1cNomenclatureSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -38,28 +38,18 @@ class Products1cNomenclatureController extends Controller */ public function actionIndex() { - $dataProvider = new ActiveDataProvider([ - 'query' => Products1cNomenclature::find(), - /* - 'pagination' => [ - 'pageSize' => 50 - ], - 'sort' => [ - 'defaultOrder' => [ - 'id' => SORT_DESC, - ] - ], - */ - ]); + $searchModel = new Products1cNomenclatureSearch(); + $dataProvider = $searchModel->search($this->request->queryParams); return $this->render('index', [ + 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single Products1cNomenclature model. - * @param string $id GUID - уникальный номер номенклатуры в 1С + * @param string $id GUID * @return string * @throws NotFoundHttpException if the model cannot be found */ @@ -95,7 +85,7 @@ class Products1cNomenclatureController extends Controller /** * Updates an existing Products1cNomenclature model. * If update is successful, the browser will be redirected to the 'view' page. - * @param string $id GUID - уникальный номер номенклатуры в 1С + * @param string $id GUID * @return string|\yii\web\Response * @throws NotFoundHttpException if the model cannot be found */ @@ -115,7 +105,7 @@ class Products1cNomenclatureController extends Controller /** * Deletes an existing Products1cNomenclature model. * If deletion is successful, the browser will be redirected to the 'index' page. - * @param string $id GUID - уникальный номер номенклатуры в 1С + * @param string $id GUID * @return \yii\web\Response * @throws NotFoundHttpException if the model cannot be found */ @@ -129,7 +119,7 @@ class Products1cNomenclatureController extends Controller /** * Finds the Products1cNomenclature model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. - * @param string $id GUID - уникальный номер номенклатуры в 1С + * @param string $id GUID * @return Products1cNomenclature the loaded model * @throws NotFoundHttpException if the model cannot be found */ diff --git a/erp24/records/Products1cNomenclatureSearch.php b/erp24/records/Products1cNomenclatureSearch.php new file mode 100644 index 00000000..100d509a --- /dev/null +++ b/erp24/records/Products1cNomenclatureSearch.php @@ -0,0 +1,78 @@ + $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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'size' => $this->size, + ]); + + $query->andFilterWhere(['ilike', 'id', $this->id]) + ->andFilterWhere(['ilike', 'location', $this->location]) + ->andFilterWhere(['ilike', 'name', $this->name]) + ->andFilterWhere(['ilike', 'type_num', $this->type_num]) + ->andFilterWhere(['ilike', 'category', $this->category]) + ->andFilterWhere(['ilike', 'subcategory', $this->subcategory]) + ->andFilterWhere(['ilike', 'species', $this->species]) + ->andFilterWhere(['ilike', 'sort', $this->sort]) + ->andFilterWhere(['ilike', 'measure', $this->measure]) + ->andFilterWhere(['ilike', 'color', $this->color]) + ->andFilterWhere(['ilike', 'type', $this->type]); + + return $dataProvider; + } +} diff --git a/erp24/views/products1c-nomenclature/index.php b/erp24/views/products1c-nomenclature/index.php index 55ce943d..5d179026 100644 --- a/erp24/views/products1c-nomenclature/index.php +++ b/erp24/views/products1c-nomenclature/index.php @@ -1,27 +1,28 @@ title = 'Товары с категориями'; +$this->title = 'Products1c Nomenclatures'; $this->params['breadcrumbs'][] = $this->title; ?> -
+

title) ?>

- $dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'kartik\grid\SerialColumn'], 'id', 'location', 'name', @@ -36,13 +37,16 @@ $this->params['breadcrumbs'][] = $this->title; 'color', [ 'class' => ActionColumn::class, + 'template' => '{view}', 'urlCreator' => function ($action, Products1cNomenclature $model, $key, $index, $column) { return Url::toRoute([$action, 'id' => $model->id]); } ], ], - ]); ?> + ]); ?>
+ +