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;
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;
*/
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');
}
/**
* @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()
+ public
+ function actionCreate()
{
$model = new CityStoreParams();
* @return mixed
* @throws NotFoundHttpException
*/
- public function actionUpdate($id)
+ public
+ function actionUpdate($id)
{
$model = $this->findModel($id);
* @return CityStoreParams
* @throws NotFoundHttpException
*/
- protected function findModel($id)
+ protected
+ function findModel($id)
{
if (($model = CityStoreParams::findOne($id)) !== null) {
return $model;
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'] ?? '';
->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()
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'),
+ ]
];
}
}
--- /dev/null
+<?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.');
+ }
+}
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}}".
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'],
'updated_at' => 'Дата обновления',
];
}
+
+ public function getStore() {
+ return $this->hasOne(CityStore::class, ['id' => 'store_id']);
+ }
}
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],
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;
?>
<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,
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">
?>
</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,
?>
</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,
<?= 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,
</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,
?>
</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']); ?>
</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>
</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']); ?>
<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' => " <br><br>",
'showFilterInputs' => false,
'clearButton' => false,
<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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
-$(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);
+ }
+}