]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
добавил имя товара
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 28 Aug 2024 15:16:08 +0000 (18:16 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 28 Aug 2024 15:16:08 +0000 (18:16 +0300)
erp24/records/SelfCostProduct.php
erp24/records/SelfCostProductSearch.php
erp24/views/self-cost-product/index.php

index 7e916e48cd897485037ec4814a74dcd8ad53d37e..1da5b7f2cb671e744d2625aecd995f4a3ad86d2f 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace yii_app\records;
 
+use yii_app\records\Products1c;
 
 /**
  * This is the model class for table "self_cost_product".
@@ -45,11 +46,18 @@ class SelfCostProduct extends \yii\db\ActiveRecord
     {
         return [
             'id' => 'ID',
-            'date' => 'Date',
-            'store_id' => 'Store ID',
-            'product_guid' => 'Product Guid',
-            'price' => 'Price',
-            'updated_at' => 'Updated At',
+            'date' => 'Дата',
+            'store_id' => 'ID магазина',
+            'product_guid' => 'Guid Товара',
+            'price' => 'Цена',
+            'updated_at' => 'Обновлено',
         ];
     }
+
+
+    public function getProduct1C()
+    {
+        return $this->hasOne(Products1c::class, ['id' => 'product_guid'])
+            ->where(['tip' => 'products']);
+    }
 }
index 63d00b1925e19cd3b6cd35a728ffe4ac3d1a8bae..9f8de1cc57cd98805508ca31d118a18001133fc7 100644 (file)
@@ -5,21 +5,27 @@ namespace yii_app\records;
 use yii\base\Model;
 use yii\data\ActiveDataProvider;
 use yii_app\records\SelfCostProduct;
+use yii_app\records\Products1c;
 
 class SelfCostProductSearch extends SelfCostProduct
 {
+    public $product_name; // добавляем новое свойство для фильтрации по имени
+
     public function rules()
     {
         return [
             [['id', 'store_id'], 'integer'],
-            [['date', 'product_guid', 'updated_at'], 'safe'],
+            [['date','product_guid', 'product_name', 'updated_at'], 'safe'],
             [['price'], 'number'],
         ];
     }
 
     public function search($params)
     {
-        $query = SelfCostProduct::find();
+        $query = SelfCostProduct::find()
+            ->alias('scp')
+            ->joinWith(['product1C p'], false)
+            ->where(['p.tip' => 'products']);
 
         $dataProvider = new ActiveDataProvider([
             'query' => $query,
@@ -33,24 +39,30 @@ class SelfCostProductSearch extends SelfCostProduct
             ],
         ]);
 
+        $dataProvider->sort->attributes['product_name'] = [
+            'asc' => ['p.name' => SORT_ASC],
+            'desc' => ['p.name' => SORT_DESC],
+        ];
+
         $this->load($params);
 
         if (!$this->validate()) {
-            // если валидация не удалась, не возвращаем записи
             $query->where('0=1');
             return $dataProvider;
         }
 
         // Фильтрация по параметрам
         $query->andFilterWhere([
-            'id' => $this->id,
-            'store_id' => $this->store_id,
-            'price' => $this->price,
-            'date' => $this->date,
+            'scp.id' => $this->id,
+            'scp.store_id' => $this->store_id,
+            'scp.price' => $this->price,
+            'scp.date' => $this->date,
+
         ]);
 
-        $query->andFilterWhere(['like', 'product_guid', $this->product_guid]);
+        $query->andFilterWhere(['like', 'p.name', $this->product_name])
+            ->andFilterWhere(['like', 'scp.product_guid', $this->product_guid]);
 
         return $dataProvider;
     }
-}
\ No newline at end of file
+}
index bca9b39330a66cb580ab0d0d50021adbb031816b..ffc74a8d4d06374828a7edb2208641642a20d3b5 100644 (file)
@@ -25,7 +25,7 @@ $this->params['breadcrumbs'][] = $this->title;
 
         <div class="row">
 
-            <div class="col-3"><?= $form->field($searchModel, 'date', [])->input('date')->label('Дата') ?></div>
+            <div class="col-2"><?= $form->field($searchModel, 'date', [])->input('date')->label('Дата') ?></div>
             <div class="col-3">
 
                 <?= $form->field($searchModel, 'store_id')->widget(Select2::class, [
@@ -37,8 +37,10 @@ $this->params['breadcrumbs'][] = $this->title;
                     ],
                 ])->label('Магазин ID') ?>
             </div>
-            <div class="col-3"> <?= $form->field($searchModel, 'product_guid')->label('Товар GUID') ?></div>
-            <div class="col-3"><?= $form->field($searchModel, 'price')->label('Цена') ?></div>
+            <div class="col-2"> <?= $form->field($searchModel, 'product_name')->label('Имя Товара') ?></div>
+            <div class="col-3"> <?= $form->field($searchModel, 'product_guid')->label('Код Товара') ?></div>
+
+            <div class="col-2"><?= $form->field($searchModel, 'price')->label('Цена') ?></div>
         </div>
 
 
@@ -62,7 +64,16 @@ $this->params['breadcrumbs'][] = $this->title;
             'id',
             'date:text:Дата',
             'store_id:text:Магазин',
-            'product_guid:text:GUID товара',
+            [
+                'attribute' => 'product_name',
+                'value' => 'product1C.name',
+                'label' => 'Имя товара'
+            ],
+            [
+                'attribute' => 'product_guid',
+                'value' => 'product_guid',
+                'label' => 'Код товара'
+            ],
             'price:text:Цена',
             'updated_at:text:Обновлено',