]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-282 Нужно сделать интерфейс настройки магазина
authormarina <m.zozirova@gmail.com>
Thu, 23 Jan 2025 13:19:51 +0000 (16:19 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 23 Jan 2025 13:19:51 +0000 (16:19 +0300)
erp24/controllers/CityStoreParamsController.php
erp24/controllers/MatrixTypeController.php [new file with mode: 0644]
erp24/records/CityStoreParams.php
erp24/records/MatrixType.php
erp24/views/city-store-params/index.php
erp24/views/matrix-type/create.php [new file with mode: 0644]
erp24/views/matrix-type/index.php [new file with mode: 0644]
erp24/views/matrix-type/update.php [new file with mode: 0644]
erp24/views/matrix-type/view.php [new file with mode: 0644]
erp24/web/js/city-store-params/city-store-params.js

index c6df86061494532c25ad2ffff1dae84a0204a7ac..bf8df63869a8772883e4806b67439cf36c17d21c 100644 (file)
@@ -3,8 +3,6 @@
 namespace app\controllers;
 
 use Yii;
-use yii\base\Action;
-use yii\data\ActiveDataProvider;
 use yii\helpers\ArrayHelper;
 use yii\web\Controller;
 use yii\web\NotFoundHttpException;
@@ -12,11 +10,10 @@ use yii\filters\VerbFilter;
 use yii\web\Response;
 use yii_app\records\Admin;
 use yii_app\records\AdminGroup;
-use yii_app\records\City;
 use yii_app\records\CityStore;
 use yii_app\records\CityStoreParams;
-use yii_app\records\Cluster;
 use yii_app\records\ClusterAdmin;
+use yii_app\records\MatrixType;
 use yii_app\records\StoreCityList;
 use yii_app\records\StoreDynamic;
 use yii_app\records\StoreType;
@@ -47,13 +44,21 @@ class CityStoreParamsController extends Controller
      */
     public function actionIndex()
     {
-        $dataProvider = new ActiveDataProvider([
-            'query' => CityStoreParams::find(),
-        ]);
-
-        return $this->render('index', [
-            'dataProvider' => $dataProvider,
-        ]);
+        $model = !empty(Yii::$app->request->post('id'))
+            ? $this->findModel(Yii::$app->request->post('id'))
+            : new CityStoreParams();
+
+        if ($model->load(Yii::$app->request->post())) {
+            if ($model->validate()) {
+                $model->save();
+                return $this->redirect(['view', 'id' => $model->id]);
+            } else {
+
+            var_dump($model->getErrors(), $model->matrix_type);
+            die();
+            }
+        }
+        return $this->render('index');
     }
 
     /**
@@ -62,7 +67,8 @@ class CityStoreParamsController extends Controller
      * @return mixed
      * @throws NotFoundHttpException
      */
-    public function actionView($id)
+    public
+    function actionView($id)
     {
         return $this->render('view', [
             'model' => $this->findModel($id),
@@ -73,7 +79,8 @@ class CityStoreParamsController extends Controller
      * Создание новой записи
      * @return mixed
      */
-    public function actionCreate()
+    public
+    function actionCreate()
     {
         $model = new CityStoreParams();
 
@@ -92,7 +99,8 @@ class CityStoreParamsController extends Controller
      * @return mixed
      * @throws NotFoundHttpException
      */
-    public function actionUpdate($id)
+    public
+    function actionUpdate($id)
     {
         $model = $this->findModel($id);
 
@@ -111,7 +119,8 @@ class CityStoreParamsController extends Controller
      * @return CityStoreParams
      * @throws NotFoundHttpException
      */
-    protected function findModel($id)
+    protected
+    function findModel($id)
     {
         if (($model = CityStoreParams::findOne($id)) !== null) {
             return $model;
@@ -120,12 +129,12 @@ class CityStoreParamsController extends Controller
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 
-    public function actionEdit()
+    public
+    function actionEdit()
     {
-
         Yii::$app->response->format = Response::FORMAT_JSON;
 
-        $data = Yii::$app->request->get();
+        $data = Yii::$app->request->post(); // Используем POST
         $addressCity = $data['address_city'] ?? '';
         $addressRegion = $data['address_region'] ?? '';
         $addressDistrict = $data['address_district'] ?? '';
@@ -135,9 +144,12 @@ class CityStoreParamsController extends Controller
             ->andWhere(['=', 'visible', CityStore::IS_VISIBLE])
             ->all();
 
-        return ArrayHelper::map($stores, 'id', function ($store) {
-            return $store->id . ' ' . $store->name;
-        });
+        return [
+            'success' => true,
+            'data' => ArrayHelper::map($stores, 'id', function ($store) {
+                return $store->id . ' ' . $store->name;
+            }),
+        ];
     }
 
     public function actionGetData()
@@ -145,60 +157,38 @@ class CityStoreParamsController extends Controller
         Yii::$app->response->format = Response::FORMAT_JSON;
 
         $storeId = Yii::$app->request->get('selected_store');
+        $params = CityStoreParams::findOne(['store_id' => $storeId]);
 
         $store = CityStore::findOne($storeId);
+        if (!$store) return ['success' => false, 'message' => 'Магазин не найден'];
 
-        if ($store === null) {
-            return [
-                'success' => false,
-                'message' => 'Магазин не найден',
-            ];
-        }
-
-        $name = $store->name;
-        $type = $store->type;
-        $region = StoreCityList::findOne($store->region)->name ?? '';
-        $city = StoreCityList::findOne($store->city)->name ?? '';
-        $district = StoreCityList::findOne($store->district) ?? '';
-
-        $bushId = StoreDynamic::findOne(['store_id' => $storeId, 'active' => 1, 'category' => 1])->value_int ?? '';
-        $territorialManagerId = ClusterAdmin::findOne(['cluster_id' => $bushId])->admin_id ?? '';
-        $territorialManager = empty($territorialManagerId) ? null : Admin::findOne($territorialManagerId)->name_full;
-
-        $bushChefFloristId = StoreDynamic::findOne(['store_id' => $storeId, 'active' => 1, 'category' => 2])->value_int ?? '';
-        $bushChefFlorist = empty($bushChefFloristId) ? null : Admin::findOne($bushChefFloristId)->name_full;
-
-        $storeArea = CityStoreParams::findOne($storeId)->store_area ?? null;
-        $showcaseVolume = CityStoreParams::findOne($storeId)->showcase_volume ?? null;
-        $freezeArea = CityStoreParams::findOne($storeId)->freeze_area ?? null;
-        $freezeVolume = CityStoreParams::findOne($storeId)->freeze_volume ?? null;
-
-        $storeTypeArray = ArrayHelper::map(StoreType::find()->all(), 'id', 'name');
-        $regionArray = ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name');
-        $cityArray = ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_CITY]), 'id', 'name');
-        $districtArray = ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_DISTRICT]), 'id', 'name');
-        $bushChefFloristArray = ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name');
+        $bushId = StoreDynamic::findOne(['store_id' => $storeId, 'category' => 1, 'active' => 1])->value_int ?? null;
+        $territorialManagerId = ClusterAdmin::findOne(['active' => 1, 'cluster_id' => $bushId])->admin_id ?? null;
 
         return [
             'success' => true,
             'data' => [
-                'name' => $name,
-                'type' => $type,
-                'region' => $region,
-                'city' => $city,
-                'district' => $district,
-                'territorialManager' => $territorialManager,
-                'bushChefFlorist' => $bushChefFlorist,
-                'storeArea' => $storeArea,
-                'showcaseVolume' => $showcaseVolume,
-                'freezeArea' => $freezeArea,
-                'freezeVolume' => $freezeVolume,
-                'storeTypeArray' => $storeTypeArray,
-                'regionArray' => $regionArray,
-                'cityArray' => $cityArray,
-                'districtArray' => $districtArray,
-                'bushChefFloristArray' => $bushChefFloristArray,
-            ],
+                'id' => $params->id ?? null,
+                'storeId' => $storeId,
+                'name' => $store->name,
+                'type' => $params->stores_type ?? $store->type ?? null,
+                'region' => $params->address_region ?? $store->region ?? null,
+                'city' => $params->address_city ?? $store->city ?? null,
+                'district' => $params->address_district ?? $store->district ?? null,
+                'territorialManagerId' => $territorialManagerId,
+                'territorialManager' => !empty($territorialManagerId) ? Admin::findOne($territorialManagerId)->name_full : null,
+                'bushChefFloristId' => $params->bush_chef_florist ?? StoreDynamic::findOne(['store_id' => $storeId, 'active' => 1, 'category' => 2])->value_int ?? null,
+                'storeArea' => $params->store_area ?? null,
+                'showcaseVolume' => $params->showcase_volume ?? null,
+                'freezeArea' => $params->freeze_area ?? null,
+                'freezeVolume' => $params->freeze_volume ?? null,
+                'storeTypeArray' => ArrayHelper::map(StoreType::find()->all(), 'id', 'name'),
+                'regionArray' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name'),
+                'cityArray' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_CITY]), 'id', 'name'),
+                'districtArray' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_DISTRICT]), 'id', 'name'),
+                'bushChefFloristArray' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name'),
+                'matrixTypeArray' => ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'),
+            ]
         ];
     }
 }
diff --git a/erp24/controllers/MatrixTypeController.php b/erp24/controllers/MatrixTypeController.php
new file mode 100644 (file)
index 0000000..8ce94d4
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii_app\records\MatrixType;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * MatrixTypeController implements the CRUD actions for MatrixType model.
+ */
+class MatrixTypeController extends Controller
+{
+    public function behaviors()
+    {
+        return [
+            'verbs' => [
+                'class' => VerbFilter::class,
+                'actions' => [
+                    'delete' => ['POST'],
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * Lists all MatrixType models.
+     * @return mixed
+     */
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => MatrixType::find(),
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+
+    /**
+     * Displays a single MatrixType model.
+     * @param int $id
+     * @return mixed
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionView($id)
+    {
+        return $this->render('view', [
+            'model' => $this->findModel($id),
+        ]);
+    }
+
+    /**
+     * Creates a new MatrixType model.
+     * If creation is successful, the browser will be redirected to the 'view' page.
+     * @return mixed
+     */
+    public function actionCreate()
+    {
+        $model = new MatrixType();
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('create', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Updates an existing MatrixType model.
+     * If update is successful, the browser will be redirected to the 'view' page.
+     * @param int $id
+     * @return mixed
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionUpdate($id)
+    {
+        $model = $this->findModel($id);
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('update', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Deletes an existing MatrixType model.
+     * If deletion is successful, the browser will be redirected to the 'index' page.
+     * @param int $id
+     * @return mixed
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionDelete($id)
+    {
+        $this->findModel($id)->delete();
+
+        return $this->redirect(['index']);
+    }
+
+    /**
+     * Finds the MatrixType model based on its primary key value.
+     * @param int $id
+     * @return MatrixType the loaded model
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    protected function findModel($id)
+    {
+        if (($model = MatrixType::findOne($id)) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
index 8ef05165c1471e2cfe24bfb751c379851f118d35..d57008d318d01a991f48a14f7177b241f2e502cc 100644 (file)
@@ -3,7 +3,11 @@
 namespace yii_app\records;
 
 use Yii;
+use yii\behaviors\BlameableBehavior;
+use yii\behaviors\TimestampBehavior;
 use yii\db\ActiveRecord;
+use yii\db\Expression;
+use yii\filters\VerbFilter;
 
 /**
  * This is the model class for table "{{%city_store_params}}".
@@ -36,13 +40,30 @@ class CityStoreParams extends ActiveRecord
         return '{{%city_store_params}}';
     }
 
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+            [
+                'class' => BlameableBehavior::class,
+                'createdByAttribute' => 'created_by',
+                'updatedByAttribute' => 'updated_by',
+            ],
+        ];
+    }
+
     /**
      * {@inheritdoc}
      */
     public function rules()
     {
         return [
-            [['store_id', 'created_by', 'created_at'], 'required'],
+            [['store_id'], 'required'],
             [['store_id', 'stores_type', 'territorial_manager', 'bush_chef_florist', 'created_by', 'updated_by'], 'integer'],
             [['store_area', 'showcase_volume', 'freeze_area', 'freeze_volume'], 'number'],
             [['created_at', 'updated_at'], 'safe'],
@@ -75,4 +96,8 @@ class CityStoreParams extends ActiveRecord
             'updated_at' => 'Дата обновления',
         ];
     }
+
+    public function getStore() {
+        return $this->hasOne(CityStore::class, ['id' => 'store_id']);
+    }
 }
index 98faee6c676f4ed9fd1744c292884b00b5e0e0bb..d9831c89366538f9647f850b9a2ed76c1d53e428 100644 (file)
@@ -49,7 +49,7 @@ class MatrixType extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['name', 'created_by', 'created_at'], 'required'],
+            [['name'], 'required'],
             [['created_by', 'updated_by'], 'integer'],
             [['created_at', 'updated_at'], 'safe'],
             [['name'], 'string', 'max' => 255],
index 921c2f292ed8cebce99596c9e4ad6b861f79ea25..11a3db411d44ab0eda8a1cc67d8c259cbc063955 100644 (file)
@@ -6,7 +6,7 @@ use yii\helpers\Html;
 use yii\helpers\Url;
 use yii_app\records\Admin;
 use yii_app\records\AdminGroup;
-use yii_app\records\City;
+use yii_app\records\MatrixType;
 use yii_app\records\StoreCityList;
 use yii_app\records\StoreType;
 
@@ -20,7 +20,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
 ?>
 <div class="container mt-4 border-bottom">
     <div class="row">
-
         <div class="col-md-2">
             <div class="card p-3 bg-light shadow-sm">
                 <?= Html::dropDownList('address_region', null,
@@ -31,7 +30,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                     Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']);
                 ?>
             </div>
-
         </div>
         <div class="col-md-2">
             <div class="card p-3 bg-light shadow-sm">
@@ -41,8 +39,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                 ?>
             </div>
         </div>
-
-
         <div class="col-md-2 border-end border-2">
             <div class="card p-3 bg-light shadow-sm">
                 <?= Html::dropDownList('address_district', null,
@@ -51,7 +47,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                 ?>
             </div>
         </div>
-
         <div class="col-md-2 border-end border-2">
             <div class="card p-3 bg-light shadow-sm">
                 <?= Html::dropDownList('store_type', null,
@@ -61,7 +56,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                 <?= Html::a('Редактировать', [\yii\helpers\Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']); ?>
             </div>
         </div>
-
         <div class="col-md-2 border-end border-2">
             <div class="card p-3 bg-light shadow-sm">
                 <?= Html::dropDownList('territorial_manager', null,
@@ -71,14 +65,10 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
             </div>
         </div>
     </div>
-
     <div class="row mt-3">
         <div class="col-md-2"></div>
-
         <div class="col-md-2"></div>
-
         <div class="col-md-2"></div>
-
         <div class="col-md-2 border-end border-2">
             <div class="card p-3 bg-light shadow-sm">
                 <?= Html::dropDownList('bush_chef_florist', null,
@@ -87,9 +77,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                 ?>
             </div>
         </div>
-
         <div class="col-md-2"></div>
-
         <div class="col-md-2 d-flex justify-content-center align-items-center">
             <div class="card p-45 bg-light shadow-sm w-100">
                 <?= Html::button('Применить', ['class' => 'btn btn-primary w-100', 'id' => 'apply-button']); ?>
@@ -97,32 +85,32 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
         </div>
     </div>
 </div>
-
-
+<?php $form = \yii\widgets\ActiveForm::begin(); ?>
 <div class="container mt-4">
     <div class="row">
         <div class="col-md-3">
-            <div class="form-group">
-                <?= Html::dropDownList('selected_store', null, [], [
-                    'multiple' => true,
-                    'size' => 16,
-                    'class' => 'form-control',
-                    'id' => 'selected-store',
-                ]) ?>
-                <?= Html::button('Редактировать', ['class' => 'btn btn-primary w-100 mt-2 py-1', 'id' => 'edit-button']); ?>
-            </div>
+            <?= Html::dropDownList('CityStoreParams[selected_store]', null, [], [
+                'multiple' => true,
+                'size' => 16,
+                'class' => 'form-control',
+                'id' => 'selected-store',
+            ]) ?>
+            <?= Html::button('Редактировать', ['class' => 'btn btn-primary w-100 mt-2 py-1', 'id' => 'edit-button']); ?>
         </div>
         <div class="col-md-9">
             <div class="form-group">
                 <div class="row">
                     <div class="col-md-3 d-flex align-items-center gap-3">
+                        <?= Html::hiddenInput('CityStoreParams[id]') ?>
+                        <?= Html::hiddenInput('CityStoreParams[store_id]') ?>
+                        <?= Html::hiddenInput('CityStoreParams[territorial_manager]') ?>
                         <?= Html::label('Название', null); ?>
                         <?= Html::tag('span', null, ['id' => 'store-name', 'class' => 'h5']); ?>
                     </div>
                     <div class="col-md-4">
-                        <?= Html::dropDownList('store_type', null,
+                        <?= Html::dropDownList('CityStoreParams[store_type]', null,
                             ArrayHelper::map(StoreType::find()->all(), 'id', 'name'),
-                            ['prompt' => 'Тип магазина', 'class' => 'form-select', 'id' => 'store_type']); ?>
+                            ['prompt' => 'Тип магазина', 'class' => 'form-select', 'id' => 'store-type']); ?>
                         <?= Html::a('Редактировать', [\yii\helpers\Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']); ?>
                     </div>
                 </div>
@@ -132,22 +120,21 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                     </div>
                     <div class="col-md-3">
                         <?= Html::label('Регион'); ?>
-                        <?= Html::dropDownList('region', null, [], ['prompt' => 'Регион', 'class' => 'form-select', 'id' => 'region']); ?>
+                        <?= Html::dropDownList('CityStoreParams[address_region]', null, [], ['prompt' => 'Регион', 'class' => 'form-select', 'id' => 'region']); ?>
                     </div>
                     <div class="col-md-3">
                         <?= Html::label('Город'); ?>
-                        <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select', 'id' => 'city']); ?>
+                        <?= Html::dropDownList('CityStoreParams[address_city]', null, [], ['prompt' => 'Город', 'class' => 'form-select', 'id' => 'city']); ?>
                     </div>
                     <div class="col-md-3">
                         <?= Html::label('Район'); ?>
-                        <?= Html::dropDownList('district', null, [], ['prompt' => 'Район', 'class' => 'form-select', 'id' => 'district']); ?>
+                        <?= Html::dropDownList('CityStoreParams[address_district]', null, [], ['prompt' => 'Район', 'class' => 'form-select', 'id' => 'district']); ?>
                     </div>
                 </div>
                 <div class="row">
                     <div class="col-md-2">
                         <?= Html::label('Территориально управляющий', null); ?>
                         <?= Html::a('Редактировать', [Url::to('/store_type')], ['class' => 'd-block mb-5 text-decoration-none']); ?>
-
                     </div>
                     <div class="col-md-9">
                         <?= Html::tag('span', null, ['id' => 'territorial-manager', 'class' => 'h5']); ?>
@@ -157,59 +144,54 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                     <div class="col-md-2">
                         <?= Html::label('КШФ') ?>
                         <?= Html::a('Редактировать', [Url::to('/store_type')], ['class' => 'd-block mb-5 text-decoration-none']); ?>
-
                     </div>
                     <div class="col-md-9">
-                        <?= Html::dropDownList('bush-chef-florist', null, [], ['prompt' => 'Кустовой шеф-флорист', 'class' => 'form-select', 'id' => 'bush-chef-florist']); ?>
+                        <?= Html::dropDownList('CityStoreParams[bush_chef_florist]', null, [], ['prompt' => 'Кустовой шеф-флорист', 'class' => 'form-select', 'id' => 'bush-chef-florist']); ?>
                     </div>
                 </div>
                 <div class="row">
                     <div class="col-md-4">
                         <?= Html::label('Площадь (M2)', null, ['class' => 'form-label']); ?>
-                        <?= Html::input('text', 'store_area', null, [
+                        <?= Html::input('text', 'CityStoreParams[store_area]', null, [
                             'id' => 'store-area',
                             'class' => 'form-control',
                             'placeholder' => 'Введите число',
                             'oninput' => 'validateDecimal(this)'
                         ]); ?>
-
                         <?= Html::label('Витрина (M3)', null, ['class' => 'form-label']); ?>
-                        <?= Html::input('text', 'showcase_volume', null, [
+                        <?= Html::input('text', 'CityStoreParams[showcase_volume]', null, [
                             'id' => 'showcase-volume',
                             'class' => 'form-control',
                             'placeholder' => 'Введите число',
                             'oninput' => 'validateDecimal(this)'
                         ]); ?>
-
                         <?= Html::label('Холодильник (M2)', null, ['class' => 'form-label']); ?>
-                        <?= Html::input('text', 'freeze_area', null, [
+                        <?= Html::input('text', 'CityStoreParams[freeze_area]', null, [
                             'id' => 'freeze-area',
                             'class' => 'form-control',
                             'placeholder' => 'Введите число',
                             'oninput' => 'validateDecimal(this)'
                         ]); ?>
-
                         <?= Html::label('Холодильник (M3)', null, ['class' => 'form-label']); ?>
-                        <?= Html::input('text', 'freeze_volume', null, [
+                        <?= Html::input('text', 'CityStoreParams[freeze_volume]', null, [
                             'id' => 'freeze-volume',
                             'class' => 'form-control',
                             'placeholder' => 'Введите число',
                             'oninput' => 'validateDecimal(this)'
                         ]); ?>
                     </div>
-
-
                     <div class="col-md-8">
                         <div class="container mt-5">
                             <?= DualListbox::widget([
-                                'name' => 'matrix_type',
-                                'items' => ArrayHelper::map(\yii_app\records\MatrixType::find()->all(), 'id', 'name'),
+                                'name' => 'CityStoreParams[matrix_type]',
+                                'items' => ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'),
                                 'options' => [
                                     'size' => false
                                 ],
                                 'clientOptions' => [
+                                    'id' => 'matrix-type',
                                     'moveOnSelect' => false,
-                                    'nonSelectedListLabel' => "Тип матрицы <br>" . Html::a('Редактировать', '#'),
+                                    'nonSelectedListLabel' => "Тип матрицы <br>" . Html::a('Редактировать', [Url::to('/matrix-type')]),
                                     'selectedListLabel' => "&nbsp;<br><br>",
                                     'showFilterInputs' => false,
                                     'clearButton' => false,
@@ -220,10 +202,9 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
                     <div class="d-flex justify-content-end">
                         <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success btn']) ?>
                     </div>
-
                 </div>
-
             </div>
         </div>
+        <?php \yii\widgets\ActiveForm::end(); ?>
     </div>
 </div>
diff --git a/erp24/views/matrix-type/create.php b/erp24/views/matrix-type/create.php
new file mode 100644 (file)
index 0000000..5dc689c
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/* @var $this yii\web\View */
+/* @var $model yii_app\records\MatrixType */
+/* @var $form yii\widgets\ActiveForm */
+
+$this->title = 'Создать новый тип матрицы';
+$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="matrix-type-create">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <div class="matrix-type-form">
+
+        <?php $form = ActiveForm::begin(); ?>
+
+        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+        <div class="form-group">
+            <?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
+        </div>
+
+        <?php ActiveForm::end(); ?>
+
+    </div>
+
+</div>
diff --git a/erp24/views/matrix-type/index.php b/erp24/views/matrix-type/index.php
new file mode 100644 (file)
index 0000000..88de352
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/* @var $this yii\web\View */
+/* @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Типы матриц';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="matrix-type-index">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать новый тип матрицы', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'filterModel' => null,
+        'columns' => [
+            'id',
+            'name',
+            'created_at',
+            'updated_at',
+            [
+                'class' => 'yii\grid\ActionColumn',
+                'template' => '{view} {update} {delete}',
+            ],
+        ],
+    ]); ?>
+</div>
diff --git a/erp24/views/matrix-type/update.php b/erp24/views/matrix-type/update.php
new file mode 100644 (file)
index 0000000..f04ec34
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/* @var $this yii\web\View */
+/* @var $model yii_app\records\MatrixType */
+/* @var $form yii\widgets\ActiveForm */
+
+$this->title = 'Редактировать тип матрицы: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="matrix-type-update">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <div class="matrix-type-form">
+
+        <?php $form = ActiveForm::begin(); ?>
+
+        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+        <div class="form-group">
+            <?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
+        </div>
+
+        <?php ActiveForm::end(); ?>
+
+    </div>
+
+</div>
diff --git a/erp24/views/matrix-type/view.php b/erp24/views/matrix-type/view.php
new file mode 100644 (file)
index 0000000..bf4d315
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+use yii\helpers\Html;
+
+/* @var $this yii\web\View */
+/* @var $model yii_app\records\MatrixType */
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="matrix-type-view">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы уверены, что хотите удалить этот элемент?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <table class="table table-striped">
+        <tr>
+            <th>Название типа матрицы</th>
+            <td><?= Html::encode($model->name) ?></td>
+        </tr>
+        <tr>
+            <th>Дата создания</th>
+            <td><?= Html::encode($model->created_at) ?></td>
+        </tr>
+        <tr>
+            <th>Дата обновления</th>
+            <td><?= Html::encode($model->updated_at) ?></td>
+        </tr>
+    </table>
+
+</div>
index e40b86946bba81e436be010d341c6ace4b8f3f2a..cb246fea4515039ac992250df9d7f49f66b6452e 100644 (file)
-$(document).ready(function () {
-    function sendData() {
-        var formData = {
+function sendData() {
+    $.ajax({
+        url: '/city-store-params/edit',
+        type: 'GET',
+        data: {
             address_city: $('#address_city').val(),
             address_region: $('#address_region').val(),
             address_district: $('#address_district').val(),
             store_type: $('#store_type').val(),
             territorial_manager: $('#territorial_manager').val(),
             bush_chef_florist: $('#bush_chef_florist').val(),
-        };
+        },
+        success: function (response) {
+            if (response?.success) {
+                $('#selected-store').html(Object.entries(response.data).map(([key, value]) =>
+                    `<option value="${key}">${value}</option>`).join(''));
+            } else {
+                console.error("Ошибка: Невозможно получить данные.");
+            }
+        },
+        error: function (xhr, status, error) {
+            console.error("Ошибка AJAX: " + error);
+        }
+    });
+}
 
-        // Отправка данных через AJAX
-        $.ajax({
-            url: 'city-store-params/edit', // URL контроллера и экшн
-            type: 'GET', // Метод запроса
-            data: formData, // Данные формы
-            success: function (response) {
-                // Ответ от сервера (список магазинов или другие данные)
-                if (response && typeof response === 'object') {
-                    // Обновляем dropdown
-                    var options = '';
-                    $.each(response, function (key, value) {
-                        options += '<option value="' + key + '">' + value + '</option>';
-                    });
+$('#apply-button').on('click', function () {
+    sendData();
+});
 
-                    $('#selected-store').html(options);
-                }
-            },
-            error: function (xhr, status, error) {
-                console.error("Ошибка AJAX: " + error);
-            }
-        });
-    }
+$('#edit-button').on('click', function () {
+    getData()
+});
+function getData() {
+    var formData = {
+        selected_store: $('#selected-store').val(),
+    };
 
-    $('#apply-button').on('click', function () {
-        sendData();
-    });
+    $.ajax({
+        url: '/city-store-params/get-data',
+        type: 'GET',
+        data: formData,
+        success: function (response) {
+            var data = response.data;
+
+            $('#store-area').val(data.storeArea);
+            $('#showcase-volume').val(data.showcaseVolume);
+            $('#freeze-area').val(data.freezeArea);
+            $('#freeze-volume').val(data.freezeVolume);
+
+            $('#store-name').text(data.name);
 
-    $('#edit-button').on('click', function () {
-        getData()
+            $('#territorial-manager').text(data.territorialManagerId ? getNameFromArray(data.territorialManagerId, data.bushChefFloristArray) : '');
+            $('#bush-chef-florist').text(data.bushChefFloristId ? getNameFromArray(data.bushChefFloristId, data.bushChefFloristArray) : '');
+
+            $('input[name="CityStoreParams[id]"]').val(data.id);
+            $('input[name="CityStoreParams[store_id]"]').val(data.storeId);
+            $('input[name="CityStoreParams[territorial_manager]"]').val(data.territorialManagerId);
+
+            $('#store_type').val(data.type);
+            $('#region').val(data.region);
+            $('#city').val(data.city);
+            $('#district').val(data.district);
+            $('#territorial-manager').text(data.territorialManager);
+
+            populateSelect('#store-type', data.storeTypeArray, data.type);
+            populateSelect('#region', data.regionArray, data.region);
+            populateSelect('#city', data.cityArray, data.city);
+            populateSelect('#district', data.districtArray, data.district);
+            populateSelect('#bush-chef-florist', data.bushChefFloristArray, data.bushChefFloristId);
+            populateSelect('#matrix-type', data.matrixTypeArray);
+        },
+        error: function (xhr, status, error) {
+            console.error("Ошибка AJAX: " + error);
+            alert("Произошла ошибка при отправке данных.");
+        }
     });
+}
 
-    function getData() {
-        var formData = {
-            selected_store: $('#selected-store').val(),
-        };
+function getNameFromArray(id, array) {
+    return array[id] || '';
+}
 
-        $.ajax({
-            url: '/city-store-params/get-data',
-            type: 'GET',
-            data: formData,
-            success: function (response) {
-                var data = response.data;
-                $('#store_type').val(data.type);
-                $('#region').val(data.region);
-                $('#city').val(data.city);
-                $('#district').val(data.district);
-                $('#store-name').text(data.name);
-                $('#freeze-volume').text(data.freezeVolume);
-                $('#freeze-area').text(data.freezeArea);
-                $('#showcase-volume').text(data.showcaseVolume);
-                $('#store-area').text(data.storeArea);
-                $('#territorial-manager').text(data.territorialManager);
-                $('#bush-chef-florist').text(data.bushChefFlorist);
-            },
-            error: function (xhr, status, error) {
-                console.error("Ошибка AJAX: " + error);
-                alert("Произошла ошибка при отправке данных.");
-            }
-        });
-    }
-});
+function populateSelect(selector, values, selectedValue = null) {
+    var select = $(selector);
+    select.empty();
+
+    select.append($('<option>', {
+        value: '',
+        text: 'Выберите значение',
+    }));
 
+    $.each(values, function (key, value) {
+        select.append($('<option>', {
+            value: key,
+            text: value
+        }));
+    });
 
+    if (selectedValue !== null) {
+        select.val(selectedValue);
+    }
+}