From: marina Date: Thu, 23 Jan 2025 13:19:51 +0000 (+0300) Subject: ERP-282 Нужно сделать интерфейс настройки магазина X-Git-Tag: 1.7~35^2~33 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2612d4d8eaa8af5623686b4e0b6027d3995dc07c;p=erp24_rep%2Fyii-erp24%2F.git ERP-282 Нужно сделать интерфейс настройки магазина --- diff --git a/erp24/controllers/CityStoreParamsController.php b/erp24/controllers/CityStoreParamsController.php index c6df8606..bf8df638 100644 --- a/erp24/controllers/CityStoreParamsController.php +++ b/erp24/controllers/CityStoreParamsController.php @@ -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 index 00000000..8ce94d47 --- /dev/null +++ b/erp24/controllers/MatrixTypeController.php @@ -0,0 +1,123 @@ + [ + '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.'); + } +} diff --git a/erp24/records/CityStoreParams.php b/erp24/records/CityStoreParams.php index 8ef05165..d57008d3 100644 --- a/erp24/records/CityStoreParams.php +++ b/erp24/records/CityStoreParams.php @@ -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']); + } } diff --git a/erp24/records/MatrixType.php b/erp24/records/MatrixType.php index 98faee6c..d9831c89 100644 --- a/erp24/records/MatrixType.php +++ b/erp24/records/MatrixType.php @@ -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], diff --git a/erp24/views/city-store-params/index.php b/erp24/views/city-store-params/index.php index 921c2f29..11a3db41 100644 --- a/erp24/views/city-store-params/index.php +++ b/erp24/views/city-store-params/index.php @@ -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' ?>
-
registerJsFile('/js/city-store-params/city-store-params.js', ['position' Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']); ?>
-
@@ -41,8 +39,6 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' ?>
- -
registerJsFile('/js/city-store-params/city-store-params.js', ['position' ?>
-
registerJsFile('/js/city-store-params/city-store-params.js', ['position' 'd-block mt-2 text-decoration-none']); ?>
-
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']); ?> @@ -97,32 +85,32 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- - +
-
- true, - 'size' => 16, - 'class' => 'form-control', - 'id' => 'selected-store', - ]) ?> - 'btn btn-primary w-100 mt-2 py-1', 'id' => 'edit-button']); ?> -
+ true, + 'size' => 16, + 'class' => 'form-control', + 'id' => 'selected-store', + ]) ?> + 'btn btn-primary w-100 mt-2 py-1', 'id' => 'edit-button']); ?>
+ + + 'store-name', 'class' => 'h5']); ?>
- all(), 'id', 'name'), - ['prompt' => 'Тип магазина', 'class' => 'form-select', 'id' => 'store_type']); ?> + ['prompt' => 'Тип магазина', 'class' => 'form-select', 'id' => 'store-type']); ?> 'd-block mt-2 text-decoration-none']); ?>
@@ -132,22 +120,21 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- 'Регион', 'class' => 'form-select', 'id' => 'region']); ?> + 'Регион', 'class' => 'form-select', 'id' => 'region']); ?>
- 'Город', 'class' => 'form-select', 'id' => 'city']); ?> + 'Город', 'class' => 'form-select', 'id' => 'city']); ?>
- 'Район', 'class' => 'form-select', 'id' => 'district']); ?> + 'Район', 'class' => 'form-select', 'id' => 'district']); ?>
'd-block mb-5 text-decoration-none']); ?> -
'territorial-manager', 'class' => 'h5']); ?> @@ -157,59 +144,54 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
'd-block mb-5 text-decoration-none']); ?> -
- 'Кустовой шеф-флорист', 'class' => 'form-select', 'id' => 'bush-chef-florist']); ?> + 'Кустовой шеф-флорист', 'class' => 'form-select', 'id' => 'bush-chef-florist']); ?>
'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)' ]); ?>
- -
'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' => "Тип матрицы
" . Html::a('Редактировать', '#'), + 'nonSelectedListLabel' => "Тип матрицы
" . Html::a('Редактировать', [Url::to('/matrix-type')]), 'selectedListLabel' => " 

", 'showFilterInputs' => false, 'clearButton' => false, @@ -220,10 +202,9 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
'btn btn-success btn']) ?>
-
-
+
diff --git a/erp24/views/matrix-type/create.php b/erp24/views/matrix-type/create.php new file mode 100644 index 00000000..5dc689ce --- /dev/null +++ b/erp24/views/matrix-type/create.php @@ -0,0 +1,33 @@ +title = 'Создать новый тип матрицы'; +$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ +

title) ?>

+ +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
+ +
diff --git a/erp24/views/matrix-type/index.php b/erp24/views/matrix-type/index.php new file mode 100644 index 00000000..88de352e --- /dev/null +++ b/erp24/views/matrix-type/index.php @@ -0,0 +1,34 @@ +title = 'Типы матриц'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => null, + 'columns' => [ + 'id', + 'name', + 'created_at', + 'updated_at', + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update} {delete}', + ], + ], + ]); ?> +
diff --git a/erp24/views/matrix-type/update.php b/erp24/views/matrix-type/update.php new file mode 100644 index 00000000..f04ec345 --- /dev/null +++ b/erp24/views/matrix-type/update.php @@ -0,0 +1,33 @@ +title = 'Редактировать тип матрицы: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ +

title) ?>

+ +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-primary']) ?> +
+ + + +
+ +
diff --git a/erp24/views/matrix-type/view.php b/erp24/views/matrix-type/view.php new file mode 100644 index 00000000..bf4d3156 --- /dev/null +++ b/erp24/views/matrix-type/view.php @@ -0,0 +1,42 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Типы матриц', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'method' => 'post', + ], + ]) ?> +

+ + + + + + + + + + + + + + +
Название типа матрицыname) ?>
Дата созданияcreated_at) ?>
Дата обновленияupdated_at) ?>
+ +
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 e40b8694..cb246fea 100644 --- a/erp24/web/js/city-store-params/city-store-params.js +++ b/erp24/web/js/city-store-params/city-store-params.js @@ -1,74 +1,103 @@ -$(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]) => + ``).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 += ''; - }); +$('#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($('