]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавлена страница с магазинами в меню
authorvladfo <fvv2011@gmail.com>
Tue, 8 Oct 2024 12:53:33 +0000 (15:53 +0300)
committervladfo <fvv2011@gmail.com>
Tue, 8 Oct 2024 12:53:33 +0000 (15:53 +0300)
erp24/controllers/StoreController.php
erp24/records/CityStore.php
erp24/views/store/index.php [new file with mode: 0644]

index 20666274cd220233aa8854c03db5880ae201a98d..71cfe336a86c07f1eaca24e9b17edb5ea90ad831 100755 (executable)
@@ -2,10 +2,29 @@
 
 namespace app\controllers;
 
+use yii\data\ActiveDataProvider;
 use yii\web\Controller;
+use yii_app\records\CityStore;
 
 class StoreController extends Controller
 {
     public function actionStats() { return $this->render('stats'); }
+
+    public function actionIndex()
+    {
+        // Создаем DataProvider, чтобы получить магазины, у которых visible = 1
+        $dataProvider = new ActiveDataProvider([
+            'query' => CityStore::find()
+                ->where(['visible' => 1])
+                ->with(['city', 'cluster', 'administrator']), // Загружаем связанные данные
+            'pagination' => [
+                'pageSize' => 20,
+            ],
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
     public function actionItemmatrix() { return $this->render('itemmatrix'); }
 }
\ No newline at end of file
index 3e32d5b0078f0fad5139aa898d88ac8a911f3c91..f5da7e8f9ec5955c21e3f7ae151b6b94b0fb6c40 100755 (executable)
@@ -337,4 +337,20 @@ class CityStore extends ActiveRecord
 
         return $query;
     }
+
+    public function getCity()
+    {
+        return $this->hasOne(City::class, ['id_city' => 'city_id']);
+    }
+
+    public function getCluster()
+    {
+        return $this->hasOne(Cluster::class, ['id' => 'cluster_id']);
+    }
+
+    public function getAdministrator()
+    {
+        return $this->hasOne(Admin::class, ['id' => 'administrator_id']);
+    }
+
 }
\ No newline at end of file
diff --git a/erp24/views/store/index.php b/erp24/views/store/index.php
new file mode 100644 (file)
index 0000000..cc2e939
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Список магазинов';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="store-index p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать магазин', ['/city-store/create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            [
+                'attribute' => 'name',
+                'label' => 'Наименование магазина',
+            ],
+            [
+                'attribute' => 'city.city_name_ru',
+                'label' => 'Город',
+                'value' => function ($model) {
+                    return $model->city ? $model->city->city_name_ru : '(Не указан)';
+                },
+            ],
+            [
+                'attribute' => 'cluster.name',
+                'label' => 'Куст',
+                'value' => function ($model) {
+                    return $model->cluster ? $model->cluster->name : '(Не указан)';
+                },
+            ],
+            [
+                'attribute' => 'administrator.name',
+                'label' => 'Администратор',
+                'value' => function ($model) {
+                    return $model->administrator ? $model->administrator->name : '(Не указан)';
+                },
+            ],
+
+            [
+                'class' => 'yii\grid\ActionColumn',
+                'template' => '{view} {update}', // Убираем действие удаления
+                'buttons' => [
+                    'view' => function ($url, $model, $key)  {
+
+                            return Html::a(Html::img('@web/images/icon-view.svg', ['alt' => 'View Icon', 'style' => 'width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em;']), [
+                                '/city-store/view',
+                                'id' => $model->id,
+
+                            ], [
+                                'class' => 'btn btn-primary btn-sm',
+                                'title' => 'Просмотр',
+                                'data-bs-toggle' => 'tooltip', // Подсказка на иконке
+                                'data-bs-placement' => 'top',
+                            ]);
+
+
+                    },
+                    'update' => function ($url, $model, $key)  {
+
+                            return Html::a(Html::img('@web/images/icon-edit.svg', ['alt' => 'Edit Icon', 'style' => 'width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em;']), [
+                                '/city-store/update',
+                                'id' => $model->id,
+
+                            ], [
+                                'class' => 'btn btn-success btn-sm',
+                                'title' => 'Редактировать',
+                                'data-bs-toggle' => 'tooltip',
+                                'data-bs-placement' => 'top',
+                            ]);
+
+                    },
+
+                ],
+            ],
+
+        ],
+    ]); ?>
+</div>