From 7256ab9f78683a27d8d6cb44dac26b248de5456b Mon Sep 17 00:00:00 2001 From: marina Date: Thu, 23 Jan 2025 20:48:14 +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 | 132 ++++++---- .../m250123_164600_update_column_name.php | 25 ++ erp24/records/CityStoreParams.php | 42 ++- erp24/views/city-store-params/_form.php | 45 ---- erp24/views/city-store-params/create.php | 20 -- erp24/views/city-store-params/index.php | 243 ++++-------------- erp24/views/city-store-params/update.php | 211 ++++++++++++++- erp24/views/city-store-params/view.php | 95 +++++-- .../js/city-store-params/city-store-params.js | 80 +++--- 9 files changed, 500 insertions(+), 393 deletions(-) create mode 100644 erp24/migrations/m250123_164600_update_column_name.php delete mode 100644 erp24/views/city-store-params/_form.php delete mode 100644 erp24/views/city-store-params/create.php diff --git a/erp24/controllers/CityStoreParamsController.php b/erp24/controllers/CityStoreParamsController.php index b0565ef7..d87fe8c3 100644 --- a/erp24/controllers/CityStoreParamsController.php +++ b/erp24/controllers/CityStoreParamsController.php @@ -3,6 +3,7 @@ namespace app\controllers; use Yii; +use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -12,6 +13,7 @@ use yii_app\records\Admin; use yii_app\records\AdminGroup; 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; @@ -44,24 +46,16 @@ class CityStoreParamsController extends Controller */ public function actionIndex() { - $model = !empty(Yii::$app->request->post('id')) - ? $this->findModel(Yii::$app->request->post('id')) - : new CityStoreParams(); - - if ($model->load(Yii::$app->request->post())) { - if (is_array($model->matrix_type)) { - $model->matrix_type = implode(',', $model->matrix_type); - } - if ($model->validate()) { - $model->save(); - return $this->redirect(['view', 'id' => $model->id]); - } else { + $dataProvider = new ActiveDataProvider([ + 'query' => CityStoreParams::find(), + 'pagination' => [ + 'pageSize' => 20, + ], + ]); - var_dump($model->getErrors(), $model->matrix_type); - die(); - } - } - return $this->render('index'); + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); } /** @@ -70,50 +64,30 @@ class CityStoreParamsController extends Controller * @return mixed * @throws NotFoundHttpException */ - public - function actionView($id) + public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } - /** - * Создание новой записи - * @return mixed - */ - public - function actionCreate() - { - $model = new CityStoreParams(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } - return $this->render('create', [ - 'model' => $model, - ]); - } - - /** - * Обновление существующей записи - * @param int $id - * @return mixed - * @throws NotFoundHttpException - */ - public - function actionUpdate($id) + public function actionUpdate() { - $model = $this->findModel($id); + $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->save()) { - return $this->redirect(['view', 'id' => $model->id]); + 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()) { + $model->save(); + return $this->redirect(['view', 'id' => $model->id]); + } } - return $this->render('update', [ - 'model' => $model, - ]); + return $this->render('update'); } /** @@ -122,8 +96,7 @@ class CityStoreParamsController extends Controller * @return CityStoreParams * @throws NotFoundHttpException */ - protected - function findModel($id) + protected function findModel($id) { if (($model = CityStoreParams::findOne($id)) !== null) { return $model; @@ -132,19 +105,45 @@ 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->post(); // Используем POST + $data = Yii::$app->request->post(); $addressCity = $data['address_city'] ?? ''; $addressRegion = $data['address_region'] ?? ''; $addressDistrict = $data['address_district'] ?? ''; $storeType = $data['store_type'] ?? ''; + $territorialManager = $data['territorial_manager'] ?? ''; + $bushChefFlorist = $data['bush_chef_florist'] ?? ''; + + $territorialManagerQuery = StoreDynamic::find()->andFilterWhere(['category' => 1, 'active' => 1]); + $bushChefFloristQuery = StoreDynamic::find()->andFilterWhere(['category' => 2, 'active' => 1]); + + if ($territorialManager) { + $territorialManagerQuery->andFilterWhere(['value_int' => ClusterAdmin::find() + ->andFilterWhere(['admin_id' => $territorialManager, 'active' => 1]) + ->select('cluster_id') + ->column()]); + } + + if ($bushChefFlorist) { + $bushChefFloristQuery->andWhere(['value_int' => $bushChefFlorist]); + } + + $territorialManagerStoreIds = $territorialManagerQuery->select('store_id')->column(); + $bushChefFloristStoreIds = $bushChefFloristQuery->select('store_id')->column(); $stores = CityStore::find() - ->andWhere(['=', 'visible', CityStore::IS_VISIBLE]) + ->andFilterWhere([ + 'visible' => CityStore::IS_VISIBLE, + 'city' => $addressCity, + 'district' => $addressRegion, + 'type' => $addressDistrict, + 'type' => $storeType, + ]) + ->andFilterWhere(['in', 'id', $bushChefFloristStoreIds]) + ->andFilterWhere(['in', 'id', $territorialManagerStoreIds]) ->all(); return [ @@ -185,8 +184,10 @@ class CityStoreParamsController extends Controller 'showcaseVolume' => $params->showcase_volume ?? null, 'freezeArea' => $params->freeze_area ?? null, 'freezeVolume' => $params->freeze_volume ?? null, - 'matrixType' => $params->matrix_type ?? null, + 'matrixType' => !empty($params->matrix_type) ? explode(',', $params->matrix_type) : null, + 'bushId' => $bushId, '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'), @@ -195,4 +196,21 @@ class CityStoreParamsController extends Controller ] ]; } + + public function actionGetTerritorialManager($bushId) + { + 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; + + return [ + 'success' => true, + 'data' => [ + 'territorialManagerId' => $territorialManagerId, + 'territorialManager' => $territorialManager, + ] + ]; + } } diff --git a/erp24/migrations/m250123_164600_update_column_name.php b/erp24/migrations/m250123_164600_update_column_name.php new file mode 100644 index 00000000..8c981879 --- /dev/null +++ b/erp24/migrations/m250123_164600_update_column_name.php @@ -0,0 +1,25 @@ +renameColumn('city_store_params', 'stores_type', 'store_type'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->renameColumn('city_store_params', 'store_type', 'stores_type'); + } +} diff --git a/erp24/records/CityStoreParams.php b/erp24/records/CityStoreParams.php index c6a1ba5f..56d1b377 100644 --- a/erp24/records/CityStoreParams.php +++ b/erp24/records/CityStoreParams.php @@ -14,7 +14,7 @@ use yii\filters\VerbFilter; * * @property int $id * @property int $store_id - * @property int|null $stores_type + * @property int|null $store_type * @property string|null $address_city * @property string|null $address_region * @property string|null $address_district @@ -65,7 +65,7 @@ class CityStoreParams extends ActiveRecord { return [ [['store_id'], 'required'], - [['store_id', 'stores_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', 'bush_id'], 'integer'], [['store_area', 'showcase_volume', 'freeze_area', 'freeze_volume'], 'number'], [['created_at', 'updated_at'], 'safe'], [['address_city', 'address_region', 'address_district', 'matrix_type'], 'string'], @@ -80,7 +80,7 @@ class CityStoreParams extends ActiveRecord return [ 'id' => 'ID', 'store_id' => 'ИД Магазина', - 'stores_type' => 'Тип магазина', + 'store_type' => 'Тип магазина', 'address_city' => 'Город, где расположен магазин', 'address_region' => 'Регион, где расположен магазин', 'address_district' => 'Район, где расположен магазин', @@ -102,4 +102,40 @@ class CityStoreParams extends ActiveRecord public function getStore() { return $this->hasOne(CityStore::class, ['id' => 'store_id']); } + + public function getUpdatedBy() { + return $this->hasOne(Admin::class, ['id' => 'updated_by']); + } + + public function getCreatedBy() { + return $this->hasOne(Admin::class, ['id' => 'created_by']); + } + + public function getTerritorialManager() { + return $this->hasOne(Admin::class, ['id' => 'territorial_manager']); + } + + public function getBushChefFlorist() { + return $this->hasOne(Admin::class, ['id' => 'bush_chef_florist']); + } + + public function getMatrixType() { + return $this->hasOne(MatrixType::class, ['id' => 'matrix_type']); + } + + public function getStoreType() { + return $this->hasOne(StoreType::class, ['id' => 'store_type']); + } + + public function getAddressRegion() { + return $this->hasOne(StoreCityList::class, ['id' => 'address_region']); + } + + public function getAddressDistrict() { + return $this->hasOne(StoreCityList::class, ['id' => 'address_district']); + } + + public function getAddressCity() { + return $this->hasOne(StoreCityList::class, ['id' => 'address_city']); + } } diff --git a/erp24/views/city-store-params/_form.php b/erp24/views/city-store-params/_form.php deleted file mode 100644 index 659e299c..00000000 --- a/erp24/views/city-store-params/_form.php +++ /dev/null @@ -1,45 +0,0 @@ - - -
- - - - field($model, 'store_id')->textInput() ?> - - field($model, 'stores_type')->textInput() ?> - - field($model, 'address_city')->textInput() ?> - - field($model, 'address_region')->textInput() ?> - - field($model, 'address_district')->textInput() ?> - - field($model, 'territorial_manager')->textInput() ?> - - field($model, 'bush_chef_florist')->textInput() ?> - - field($model, 'store_area')->textInput() ?> - - field($model, 'showcase_volume')->textInput() ?> - - field($model, 'freeze_area')->textInput() ?> - - field($model, 'freeze_volume')->textInput() ?> - - field($model, 'matrix_type')->textInput() ?> - -
- isNewRecord ? 'Create' : 'Save', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> -
- - - -
diff --git a/erp24/views/city-store-params/create.php b/erp24/views/city-store-params/create.php deleted file mode 100644 index d205694d..00000000 --- a/erp24/views/city-store-params/create.php +++ /dev/null @@ -1,20 +0,0 @@ -title = 'Create City Store Param'; -$this->params['breadcrumbs'][] = ['label' => 'City Store Params', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; -?> -
- -

title) ?>

- - render('_form', [ - 'model' => $model, - ]) ?> - -
diff --git a/erp24/views/city-store-params/index.php b/erp24/views/city-store-params/index.php index fc19d56b..03b8699d 100644 --- a/erp24/views/city-store-params/index.php +++ b/erp24/views/city-store-params/index.php @@ -1,210 +1,53 @@ title = 'City Store Params'; +$this->title = 'Список магазинов с настройками'; $this->params['breadcrumbs'][] = $this->title; - -$this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' => \yii\web\View::POS_END]); ?> -
-
-
-
- StoreCityList::TYPE_REGION]), 'id', 'name'), - ['prompt' => 'Выберите регион', 'class' => 'form-select', 'id' => 'address_region']); - ?> - 'd-block mt-2 text-decoration-none']); - ?> -
-
-
-
- StoreCityList::TYPE_CITY]), 'id', 'name'), - ['prompt' => 'Выберите город', 'class' => 'form-select', 'id' => 'address_city']); - ?> -
-
-
-
- StoreCityList::TYPE_DISTRICT]), 'id', 'name'), - ['prompt' => 'Выберите район', 'class' => 'form-select', 'id' => 'address_district']); - ?> -
-
-
-
- all(), 'id', 'name'), - ['prompt' => 'Выберите тип магазина', 'class' => 'form-select', 'id' => 'store_type']); - ?> - 'd-block mt-2 text-decoration-none']); ?> -
-
-
-
- AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), - ['prompt' => 'Выберите территориального управляющего', 'class' => 'form-select', 'id' => 'territorial_manager']); - ?> -
-
-
-
-
-
-
-
-
- \yii_app\records\AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'), - ['prompt' => 'Выберите кустового шеф флориста', 'class' => 'form-select', 'id' => 'bush_chef_florist']); - ?> -
-
-
-
-
- 'btn btn-primary w-100', 'id' => 'apply-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']); ?> -
-
- 'Тип магазина', 'class' => 'form-select', 'id' => 'store-type']); ?> - 'd-block mt-2 text-decoration-none']); ?> -
-
- 'Номер куста', 'class' => 'form-select', 'id' => 'store-type']); ?> -
-
-
-
- -
-
- - 'Регион', 'class' => 'form-select', 'id' => 'region']); ?> -
-
- - 'Город', 'class' => 'form-select', 'id' => 'city']); ?> -
-
- - 'Район', 'class' => 'form-select', 'id' => 'district']); ?> -
-
-
-
- - 'd-block mb-5 text-decoration-none']); ?> -
-
- 'territorial-manager', 'class' => 'h5']); ?> -
-
-
-
- -
-
- 'Кустовой шеф-флорист', '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)' - ]); ?> -
-
-
- 'CityStoreParams[matrix_type]', - 'items' => [], - 'options' => [ - 'size' => false - ], - 'clientOptions' => [ - 'id' => 'matrix-type', - 'moveOnSelect' => false, - 'nonSelectedListLabel' => "Тип матрицы
" . Html::a('Редактировать', [Url::to('/matrix-type')]), - 'selectedListLabel' => " 

", - 'showFilterInputs' => false, - 'clearButton' => false, - ], - ]); ?> -
-
-
- 'btn btn-success btn']) ?> -
-
-
-
- -
+
+ +

title) ?>

+ 'btn btn-success']) ?> + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'attribute' => 'store_id', + 'value' => function ($data) { + return $data->store->name ?? ''; + } + ], + [ + 'attribute' => 'store_type', + 'value' => function ($data) { + return $data->storeType->name ?? ''; + } + ], + [ + 'attribute' => 'address_region', + 'value' => function ($data) { + return $data->addressRegion->name ?? ''; + } + ], + [ + 'attribute' => 'created_by', + 'value' => function ($data) { + return $data->updatedBy->name_full ?? ''; + } + ], + 'created_at', + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view} {delete}', + ] + ], + 'layout' => '{items}', + ]); ?>
diff --git a/erp24/views/city-store-params/update.php b/erp24/views/city-store-params/update.php index 50aedbfe..5a828fba 100644 --- a/erp24/views/city-store-params/update.php +++ b/erp24/views/city-store-params/update.php @@ -1,20 +1,215 @@ title = 'Update City Store Param: ' . $model->id; -$this->params['breadcrumbs'][] = ['label' => 'City Store Params', 'url' => ['index']]; +$this->title = 'City Store Params'; $this->params['breadcrumbs'][] = $this->title; + +$this->title = "Настройка параметров магазина"; +$this->params['breadcrumbs'][] = $this->title; + +$this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' => \yii\web\View::POS_END]); ?> -
+

title) ?>

+ 'btn btn-primary mb-3']) ?> - render('_form', [ - 'model' => $model, - ]) ?> - +
+
+
+ StoreCityList::TYPE_REGION]), 'id', 'name'), + ['prompt' => 'Выберите регион', 'class' => 'form-select', 'id' => 'address_region']); + ?> + 'd-block mt-2 text-decoration-none']); + ?> +
+
+
+
+ StoreCityList::TYPE_CITY]), 'id', 'name'), + ['prompt' => 'Выберите город', 'class' => 'form-select', 'id' => 'address_city']); + ?> +
+
+
+
+ StoreCityList::TYPE_DISTRICT]), 'id', 'name'), + ['prompt' => 'Выберите район', 'class' => 'form-select', 'id' => 'address_district']); + ?> +
+
+
+
+ all(), 'id', 'name'), + ['prompt' => 'Выберите тип магазина', 'class' => 'form-select', 'id' => 'store_type']); + ?> + 'd-block mt-2 text-decoration-none']); ?> +
+
+
+
+ AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), + ['prompt' => 'Выберите территориального управляющего', 'class' => 'form-select', 'id' => 'territorial_manager']); + ?> +
+
+
+
+
+
+
+
+
+ \yii_app\records\AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'), + ['prompt' => 'Выберите кустового шеф флориста', 'class' => 'form-select', 'id' => 'bush_chef_florist']); + ?> +
+
+
+
+
+ 'btn btn-primary w-100', 'id' => 'apply-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']); ?> +
+
+ 'Тип магазина', 'class' => 'form-select', 'id' => 'store-type']); ?> + 'd-block mt-2 text-decoration-none']); ?> +
+
+ 'Номер куста', 'class' => 'form-select', 'id' => 'bush-id']); ?> +
+
+
+
+ +
+
+ + 'Регион', 'class' => 'form-select', 'id' => 'region']); ?> +
+
+ + 'Город', 'class' => 'form-select', 'id' => 'city']); ?> +
+
+ + 'Район', 'class' => 'form-select', 'id' => 'district']); ?> +
+
+
+
+ + 'd-block mb-5 text-decoration-none']); ?> +
+
+ 'territorial-manager', 'class' => 'h5']); ?> +
+
+
+
+ +
+
+ 'Кустовой шеф-флорист', '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)' + ]); ?> +
+
+
+ + 'd-block mb-5 text-decoration-none']); ?> + 'CityStoreParams[matrix_type]', + 'data' => [], + 'language' => 'ru-RU', + 'options' => [ + 'id' => 'matrix-type', + 'placeholder' => 'Выберите тип матрицы', + 'multiple' => true, + ], + ]); ?> +
+
+
+ 'btn btn-success']) ?> +
+
+
+
+ +
diff --git a/erp24/views/city-store-params/view.php b/erp24/views/city-store-params/view.php index dbf9c58e..b1827c04 100644 --- a/erp24/views/city-store-params/view.php +++ b/erp24/views/city-store-params/view.php @@ -3,57 +3,100 @@ use yii\helpers\Html; use yii\widgets\DetailView; use yii\widgets\ActiveForm; +use yii_app\records\MatrixType; /* @var $this yii\web\View */ /* @var $model yii_app\records\CityStoreParams */ -$this->title = "Параметры магазина: " . $model->store_id; +$this->title = "Параметры магазина# " . $model->store_id; $this->params['breadcrumbs'][] = ['label' => 'Параметры магазинов', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> -
+

title) ?>

+ 'btn btn-primary']) ?> + 'btn btn-warning']) ?> - -
+
Детали параметров магазина
$model, 'attributes' => [ 'id', - 'store_id', - 'stores_type', - 'address_city', - 'address_region', - 'address_district', - 'territorial_manager', - 'bush_chef_florist', + [ + 'attribute' => 'store_id', + 'value' => function ($data) { + return $data->store->name ?? ''; + } + ], + [ + 'attribute' => 'store_type', + 'value' => function ($data) { + return $data->storeType->name ?? ''; + } + ], + [ + 'attribute' => 'address_city', + 'value' => function ($data) { + return $data->addressCity->name ?? ''; + } + ], + [ + 'attribute' => 'address_region', + 'value' => function ($data) { + return $data->addressRegion->name ?? ''; + } + ], + [ + 'attribute' => 'address_district', + 'value' => function ($data) { + return $data->addressDistrict->name ?? ''; + } + ], + [ + 'attribute' => 'territorial_manager', + 'value' => function ($data) { + return $data->territorialManager->name_full ?? ''; + } + ], + [ + 'attribute' => 'bush_chef_florist', + 'value' => function ($data) { + return $data->bushChefFlorist->name_full ?? ''; + } + ], 'store_area', 'showcase_volume', 'freeze_area', 'freeze_volume', - 'matrix_type', - 'created_by', + [ + 'attribute' => 'matrix_type', + 'value' => function ($data) { + return implode(', ', MatrixType::find() + ->select('name') + ->where(['id' => explode(',', $data->matrix_type)]) + ->column()); + } + ], + [ + 'attribute' => 'created_by', + 'value' => function ($data) { + return $data->updatedBy->name_full ?? ''; + } + ], 'created_at', - 'updated_by', + [ + 'attribute' => 'updated_by', + 'value' => function ($data) { + return $data->updatedBy->name_full ?? ''; + } + ], 'updated_at', ], ]) ?>
- -

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

-
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 df5ec9c9..f68a1a79 100644 --- a/erp24/web/js/city-store-params/city-store-params.js +++ b/erp24/web/js/city-store-params/city-store-params.js @@ -31,6 +31,27 @@ $('#apply-button').on('click', function () { $('#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(), @@ -43,19 +64,14 @@ function getData() { 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); - $('#territorial-manager').text(data.territorialManagerId ? getNameFromArray(data.territorialManagerId, data.bushChefFloristArray) : ''); - $('#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); - - $('#store_type').val(data.type); $('#region').val(data.region); $('#city').val(data.city); $('#district').val(data.district); @@ -66,8 +82,8 @@ function getData() { 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); - // Заполнение DualListbox populateDualListbox(data.matrixTypeArray, data.matrixType); // matrixTypeArray и matrixType передаются с сервера }, error: function (xhr, status, error) { @@ -102,36 +118,32 @@ function populateSelect(selector, values, selectedValue = null) { } } -// Функция для заполнения DualListbox -function populateDualListbox(matrixTypeArray, selectedValues) { - var $nonSelectedList = $('#bootstrap-duallistbox-nonselected-list_CityStoreParams\\[matrix_type\\]'); - var $selectedList = $('#bootstrap-duallistbox-selected-list_CityStoreParams\\[matrix_type\\]'); +function populateDualListbox(matrixTypeArray, matrixType) { + var select = $('#matrix-type'); + if (!select.hasClass('select2-hidden-accessible')) { + select.select2({ + placeholder: 'Выберите тип матрицы', + multiple: true + }); + } + var selectData = Object.keys(matrixTypeArray).map(function (key) { + return { + id: key, + text: matrixTypeArray[key] + }; + }); + + select.empty().select2({ data: selectData }); + + select.val(matrixType).trigger('change'); +} + + + + - console.log("Matrix Type Array:", matrixTypeArray); // Отладка - console.log("Selected Values:", selectedValues); // Отладка - // Очистить оба списка - $nonSelectedList.empty(); - $selectedList.empty(); - // Заполняем список невыбранных значений (non-selected list) - $.each(matrixTypeArray, function (key, value) { - $nonSelectedList.append(''); - }); - // Если есть выбранные значения, добавляем их в список выбранных (selected list) - if (selectedValues && selectedValues.length > 0) { - selectedValues.forEach(function (selectedId) { - $selectedList.append(''); - }); - } - // Обновляем состояние виджета, вызываем trigger и возможно init для перерисовки - $nonSelectedList.trigger('change'); - $selectedList.trigger('change'); - // Повторно инициализируем виджет DualListbox, если это необходимо - if (typeof $('#matrix-type').bootstrapDualListbox === 'function') { - $('#matrix-type').bootstrapDualListbox('refresh'); // или аналогичная функция обновления - } -} -- 2.39.5