From 0404ff603de1ea579f11b8a9c1f59f3e6cd6d440 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Wed, 28 Aug 2024 18:16:08 +0300 Subject: [PATCH] =?utf8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?utf8?q?=D0=B8=D0=BC=D1=8F=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/records/SelfCostProduct.php | 18 ++++++++++----- erp24/records/SelfCostProductSearch.php | 30 +++++++++++++++++-------- erp24/views/self-cost-product/index.php | 19 ++++++++++++---- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/erp24/records/SelfCostProduct.php b/erp24/records/SelfCostProduct.php index 7e916e48..1da5b7f2 100644 --- a/erp24/records/SelfCostProduct.php +++ b/erp24/records/SelfCostProduct.php @@ -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']); + } } diff --git a/erp24/records/SelfCostProductSearch.php b/erp24/records/SelfCostProductSearch.php index 63d00b19..9f8de1cc 100644 --- a/erp24/records/SelfCostProductSearch.php +++ b/erp24/records/SelfCostProductSearch.php @@ -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 +} diff --git a/erp24/views/self-cost-product/index.php b/erp24/views/self-cost-product/index.php index bca9b393..ffc74a8d 100644 --- a/erp24/views/self-cost-product/index.php +++ b/erp24/views/self-cost-product/index.php @@ -25,7 +25,7 @@ $this->params['breadcrumbs'][] = $this->title;
-
field($searchModel, 'date', [])->input('date')->label('Дата') ?>
+
field($searchModel, 'date', [])->input('date')->label('Дата') ?>
field($searchModel, 'store_id')->widget(Select2::class, [ @@ -37,8 +37,10 @@ $this->params['breadcrumbs'][] = $this->title; ], ])->label('Магазин ID') ?>
-
field($searchModel, 'product_guid')->label('Товар GUID') ?>
-
field($searchModel, 'price')->label('Цена') ?>
+
field($searchModel, 'product_name')->label('Имя Товара') ?>
+
field($searchModel, 'product_guid')->label('Код Товара') ?>
+ +
field($searchModel, 'price')->label('Цена') ?>
@@ -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:Обновлено', -- 2.39.5