From 9fef184f9b9825549041442d17667414ad07ecc9 Mon Sep 17 00:00:00 2001 From: marina Date: Mon, 27 Jan 2025 15:03:52 +0300 Subject: [PATCH] =?utf8?q?ERP-282=20=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20?= =?utf8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20=D0=B8=D0=BD=D1=82?= =?utf8?q?=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20=D0=BD=D0=B0=D1=81=D1=82?= =?utf8?q?=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?utf8?q?=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/CityStoreParamsController.php | 48 +++--- erp24/records/CityStoreParams.php | 8 +- erp24/views/city-store-params/index.php | 142 +++++++++++------- .../js/city-store-params/city-store-params.js | 55 +++---- 4 files changed, 138 insertions(+), 115 deletions(-) diff --git a/erp24/controllers/CityStoreParamsController.php b/erp24/controllers/CityStoreParamsController.php index a0ed126c..6f72e376 100644 --- a/erp24/controllers/CityStoreParamsController.php +++ b/erp24/controllers/CityStoreParamsController.php @@ -57,20 +57,38 @@ class CityStoreParamsController extends Controller public function actionIndex() { - $model = !empty(Yii::$app->request->post()['CityStoreParams']['id']) - ? $this->findModel(Yii::$app->request->post()['CityStoreParams']['id']) - : new CityStoreParams(); - - if ($model->load(Yii::$app->request->post())) { - $model->matrix_type = is_array($model->matrix_type) ? implode(',', $model->matrix_type) : $model->matrix_type; + $flash = 'info'; + $value = 'Для редактирования необходимо выбрать магазин!'; + if (Yii::$app->request->post()) { + $model = !empty(Yii::$app->request->post()['CityStoreParams']['id']) + ? $this->findModel(Yii::$app->request->post()['CityStoreParams']['id']) + : new CityStoreParams(); + + if ($model->load(Yii::$app->request->post())) { + $model->matrix_type = is_array($model->matrix_type) ? implode(',', $model->matrix_type) : $model->matrix_type; + } + + if ($model->validate()) { + if ($model->save()) { + $flash = 'success'; + $value = 'Новая запись успешно создана.'; + $selected_store = $model->id; + } + } else { + $flash = 'danger'; + $value = 'Ошибка при сохранении: ' . implode('. ', array_map(function ($error) { + return is_array($error) ? implode(', ', $error) : $error; + }, $model->getErrors())); + + } } - if ($model->validate()) { - $model->save(); - return $this->redirect(['view', 'id' => $model->id]); - } + Yii::$app->session->setFlash($flash, $value); - return $this->render('index'); + return $this->render('index', [ + 'select_store' => $selected_store ?? null, + 'flash' => $flash + ]); } /** @@ -149,7 +167,6 @@ class CityStoreParamsController extends Controller if (!$store) return ['success' => false, 'message' => 'Магазин не найден']; $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, @@ -161,17 +178,15 @@ class CityStoreParamsController extends Controller '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, + 'territorialManager' => $params->territorial_manager ?? StoreDynamic::findOne(['active' => 1, 'category' => 3])->value_int ?? 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, 'matrixType' => !empty($params->matrix_type) ? explode(',', $params->matrix_type) : null, - 'bushId' => $bushId, + 'territorialManagerArray' => ArrayHelper::map(Admin::findAll(['id' => StoreDynamic::find()->andWhere(['category' => 3, 'active' => 1])->select('value_int')->column()]), 'id', 'name'), 'storeTypeArray' => ArrayHelper::map(StoreType::find()->all(), 'id', 'name'), - 'bushArray' => ArrayHelper::map(Cluster::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'), @@ -185,7 +200,6 @@ class CityStoreParamsController extends Controller { Yii::$app->response->format = Response::FORMAT_JSON; - // Используем POST для получения bushId $territorialManagerId = ClusterAdmin::findOne(['cluster_id' => $bushId])->admin_id ?? null; $territorialManager = Admin::findOne($territorialManagerId)->name_full ?? null; diff --git a/erp24/records/CityStoreParams.php b/erp24/records/CityStoreParams.php index 3c991112..ec16b3c7 100644 --- a/erp24/records/CityStoreParams.php +++ b/erp24/records/CityStoreParams.php @@ -29,7 +29,6 @@ use yii\filters\VerbFilter; * @property string $created_at * @property int|null $updated_by * @property string|null $updated_at - * @property int $bush_id */ class CityStoreParams extends ActiveRecord { @@ -65,7 +64,7 @@ class CityStoreParams extends ActiveRecord { return [ [['store_id'], 'required'], - [['store_id', 'store_type', 'territorial_manager', 'bush_chef_florist', 'created_by', 'updated_by', 'bush_id'], 'integer'], + [['store_id', 'store_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'], [['address_city', 'address_region', 'address_district', 'matrix_type'], 'string'], @@ -91,7 +90,6 @@ class CityStoreParams extends ActiveRecord 'freeze_area' => 'Площадь холодильника', 'freeze_volume' => 'Объем холодильника', 'matrix_type' => 'Тип матрицы', - 'bush_id' => 'ИД куста', 'created_by' => 'ИД создателя', 'created_at' => 'Дата создания', 'updated_by' => 'ИД редактировавшего', @@ -138,8 +136,4 @@ class CityStoreParams extends ActiveRecord public function getAddressCity() { return $this->hasOne(StoreCityList::class, ['id' => 'address_city']); } - - public function getBush() { - return $this->hasOne(ClusterAdmin::class, ['id' => 'bush_id']); - } } diff --git a/erp24/views/city-store-params/index.php b/erp24/views/city-store-params/index.php index b923ae26..bfe23c8a 100644 --- a/erp24/views/city-store-params/index.php +++ b/erp24/views/city-store-params/index.php @@ -75,6 +75,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
+
registerJsFile('/js/city-store-params/city-store-params.js', ['position' ?>
-
'btn btn-primary w-100', 'id' => 'apply-button']); ?> @@ -95,7 +95,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- where(['visible' => CityStore::IS_VISIBLE])->orderBy('id')->all(), 'id', function ($store) { return $store->id . ' ' . $store->name; }), @@ -108,22 +108,24 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' 'btn btn-primary w-100 mt-2 py-1', 'id' => 'edit-button']); ?>
+ session->hasFlash($flash)): ?> + session->getFlash($flash), [ + 'class' => 'alert text-center alert-' . Html::encode($flash), + ]) ?> +
- 'store-name', 'class' => 'h5']); ?>
+ 'Тип магазина', 'class' => 'form-select', 'id' => 'store-type']); ?> 'd-block mt-2 text-decoration-none']); ?>
-
- 'Номер куста', 'class' => 'form-select', 'id' => 'bush-id']); ?> -
@@ -148,10 +150,10 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' 'd-block mb-5 text-decoration-none']); ?>
- 'territorial-manager', 'class' => 'h5']); ?> + 'Территориально управляющий', 'class' => 'form-select', 'id' => 'territorial-manager']); ?>
-
+
@@ -160,61 +162,87 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
-
- 'form-label']); ?> - 'store-area', - 'class' => 'form-control', - 'placeholder' => 'Введите число', - 'oninput' => 'validateDecimal(this)' - ]); ?> - - 'form-label']); ?> - 'showcase-volume', - 'class' => 'form-control', - 'placeholder' => 'Введите число', - 'oninput' => 'validateDecimal(this)' - ]); ?> - - 'form-label']); ?> - 'freeze-area', - 'class' => 'form-control', - 'placeholder' => 'Введите число', - 'oninput' => 'validateDecimal(this)' - ]); ?> - - 'form-label']); ?> - 'freeze-volume', - 'class' => 'form-control', - 'placeholder' => 'Введите число', - 'oninput' => 'validateDecimal(this)' - ]); ?> +
+ 'fs-6 pt-3']); ?> +
+
+ 'fs-6 pt-3 mb-1']); ?> + 'd-block text-decoration-none']); ?>
-
-
- - 'd-block mb-5 text-decoration-none']); ?> - 'CityStoreParams[matrix_type]', - 'data' => [], - 'language' => 'ru-RU', - 'options' => [ - 'id' => 'matrix-type', - 'placeholder' => 'Выберите тип матрицы', - 'multiple' => true, - ], - ]); ?> +
+
+
+
+
+ ['pt-2']]); ?> +
+
+ 'store-area', + 'class' => 'form-control', + 'placeholder' => 'Введите число', + 'oninput' => 'validateDecimal(this)' + ]); ?> +
+
+
+
+ ['pt-2']]); ?> +
+
+ 'showcase-volume', + 'class' => 'form-control', + 'placeholder' => 'Введите число', + 'oninput' => 'validateDecimal(this)' + ]); ?> +
+
+
+
+ ['pt-2']]); ?> +
+
+ 'freeze-area', + 'class' => 'form-control', + 'placeholder' => 'Введите число', + 'oninput' => 'validateDecimal(this)' + ]); ?> +
+
+
+
+ ['pt-2']]); ?> +
+
+ 'freeze-volume', + 'class' => 'form-control', + 'placeholder' => 'Введите число', + 'oninput' => 'validateDecimal(this)' + ]); ?> +
-
- 'btn btn-success']) ?> +
+ 'CityStoreParams[matrix_type]', + 'data' => [], + 'language' => 'ru-RU', + 'options' => [ + 'id' => 'matrix-type', + 'placeholder' => 'Выберите тип матрицы', + 'multiple' => true, + ], + ]); ?>
+
+ 'btn btn-success d-none px-8', 'id' => 'save-button']) ?> +
-
+
diff --git a/erp24/web/js/city-store-params/city-store-params.js b/erp24/web/js/city-store-params/city-store-params.js index 158c8014..fa0a55a5 100644 --- a/erp24/web/js/city-store-params/city-store-params.js +++ b/erp24/web/js/city-store-params/city-store-params.js @@ -32,26 +32,6 @@ $('#edit-button').on('click', function () { getData() }); -$('#bush-id').on('change', function () { - var bushId = $(this).val(); // Получаем значение выбранного bushId - - $.ajax({ - url: '/city-store-params/get-territorial-manager', - type: 'GET', - data: { bushId: bushId }, // Передаем bushId как часть массива - success: function (response) { - var data = response.data; - - $('#territorial-manager').text(data.territorialManager); - $('input[name="CityStoreParams[territorial_manager]"]').val(data.territorialManagerId); - }, - error: function (xhr, status, error) { - console.error("Ошибка AJAX: " + error); - alert("Произошла ошибка при отправке данных."); - } - }); -}); - function getData() { var formData = { selected_store: $('#selected-store').val(), @@ -68,23 +48,24 @@ function getData() { $('#showcase-volume').val(data.showcaseVolume); $('#freeze-area').val(data.freezeArea); $('#freeze-volume').val(data.freezeVolume); - $('#store-name').text(data.name);$('#bush-chef-florist').text(data.bushChefFloristId ? getNameFromArray(data.bushChefFloristId, data.bushChefFloristArray) : ''); + $('#store-name').text(data.name); + $('#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); $('#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('#bush-id', data.bushArray, data.bushId); + 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('#territorial-manager', data.territorialManagerArray, data.territorialManager, 'Территориально управляющий'); + populateDualListbox(data.matrixTypeArray, data.matrixType); - populateDualListbox(data.matrixTypeArray, data.matrixType); // matrixTypeArray и matrixType передаются с сервера + $('#save-button').removeClass('d-none'); }, error: function (xhr, status, error) { console.error("Ошибка AJAX: " + error); @@ -97,13 +78,13 @@ function getNameFromArray(id, array) { return array[id] || ''; } -function populateSelect(selector, values, selectedValue = null) { +function populateSelect(selector, values, selectedValue = null, defaultText = 'Выберите значение') { var select = $(selector); select.empty(); select.append($('