]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Фильтры
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 17 Feb 2025 14:59:26 +0000 (17:59 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 17 Feb 2025 14:59:26 +0000 (17:59 +0300)
erp24/controllers/Products1cNomenclatureController.php
erp24/records/Products1cNomenclatureSearch.php [new file with mode: 0644]
erp24/views/products1c-nomenclature/index.php

index abfff6d683428ebba8e4fe20e4d132b6ce8e90c9..ab0d8ef65628668a31386a2a3d55ee99bba8c689 100644 (file)
@@ -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 (file)
index 0000000..100d509
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\base\Model;
+use yii\data\ActiveDataProvider;
+use yii_app\records\Products1cNomenclature;
+
+/**
+ * Products1cNomenclatureSearch represents the model behind the search form of `yii_app\records\Products1cNomenclature`.
+ */
+class Products1cNomenclatureSearch extends Products1cNomenclature
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id', 'location', 'name', 'type_num', 'category', 'subcategory', 'species', 'sort', 'measure', 'color', 'type'], 'safe'],
+            [['size'], 'integer'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function scenarios()
+    {
+        // bypass scenarios() implementation in the parent class
+        return Model::scenarios();
+    }
+
+    /**
+     * Creates data provider instance with search query applied
+     *
+     * @param array $params
+     *
+     * @return ActiveDataProvider
+     */
+    public function search($params)
+    {
+        $query = Products1cNomenclature::find();
+
+        // add conditions that should always apply here
+
+        $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;
+        }
+
+        // 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;
+    }
+}
index 55ce943d829b98c571407fd3c0318547765d1945..5d1790261b5c5f2ecf9331105d5f401debede526 100644 (file)
@@ -1,27 +1,28 @@
 <?php
 
+use kartik\grid\ActionColumn;
+use kartik\grid\GridView;
 use yii_app\records\Products1cNomenclature;
 use yii\helpers\Html;
 use yii\helpers\Url;
-use yii\grid\ActionColumn;
-use yii\grid\GridView;
 
 /** @var yii\web\View $this */
+/** @var yii_app\records\Products1cNomenclatureSearch $searchModel */
 /** @var yii\data\ActiveDataProvider $dataProvider */
 
-$this->title = 'Товары с категориями';
+$this->title = 'Products1c Nomenclatures';
 $this->params['breadcrumbs'][] = $this->title;
 ?>
-<div class="products1c-nomenclature-index p-4">
+<div class="products1c-nomenclature-index">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
-
     <?= GridView::widget([
         'dataProvider' => $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]);
                 }
             ],
         ],
-    ]); ?>
+    ]);  ?>
 
 
 </div>
+
+