]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-310] статистика по матрицам
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Feb 2025 11:08:41 +0000 (14:08 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Feb 2025 11:08:41 +0000 (14:08 +0300)
erp24/controllers/MatrixStatisticsController.php [new file with mode: 0644]
erp24/views/matrix-statistics/index.php [new file with mode: 0644]
erp24/web/js/matrix-statistics/index.js [new file with mode: 0644]

diff --git a/erp24/controllers/MatrixStatisticsController.php b/erp24/controllers/MatrixStatisticsController.php
new file mode 100644 (file)
index 0000000..969c5fa
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii\base\DynamicModel;
+use yii\helpers\ArrayHelper;
+use yii\web\Controller;
+use yii\web\Response;
+use yii_app\records\CityStore;
+use yii_app\records\CityStoreParams;
+use yii_app\records\StoreDynamic;
+
+class MatrixStatisticsController extends Controller {
+    public function actionIndex() {
+        $model = DynamicModel::validateData([
+            'year' => date('Y'),
+            'month' => date('m'),
+            'sale_type' => null,
+            'store_id' => null,
+            'city_id' => null,
+            'region_id' => null,
+            'raion_id' => null,
+            'store_type_id' => null,
+            'territory_manager_id' => null,
+            'kshf_id' => null,
+        ], [
+            [[
+                'year', 'month', 'store_id', 'city_id', 'region_id', 'raion_id', 'store_type_id',
+                'territory_manager_id', 'kshf_id'
+            ], 'safe']
+        ]);
+
+        $model->load(Yii::$app->request->get());
+
+        $years = [];
+        for ($i = 3; $i >= 0; $i--) {
+            $year = date("Y") - $i;
+            $years [$year] = $year;
+        }
+        $stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
+
+
+        return $this->render('index', compact('model', 'years', 'stores'));
+    }
+
+    public function actionGetStores() {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $data = Yii::$app->request->post();
+
+        $territorialManager = $data['territorial_manager_id'] ?? null;
+        $bushChefFlorist = $data['kshf_id'] ?? null;
+
+        $query = CityStore::find()
+            ->andWhere(['visible' => CityStore::IS_VISIBLE]);
+
+        if (!empty($data['city_id'])) {
+            $query->andWhere(['id' => CityStoreParams::find()
+                ->andWhere(['address_city' => $data['city_id']])
+                ->select('store_id')
+                ->column()]);
+        }
+
+        if (!empty($data['region_id'])) {
+            $query->andWhere(['id' => CityStoreParams::find()
+                ->andWhere(['address_region' => $data['region_id']])
+                ->select('store_id')
+                ->column()]);
+        }
+
+        if (!empty($data['raion_id'])) {
+            $query->andWhere(['id' => CityStoreParams::find()
+                ->andWhere(['address_district' => $data['raion_id']])
+                ->select('store_id')
+                ->column()]);
+        }
+
+        if (!empty($data['store_type_id'])) {
+            $query->andWhere(['id' => CityStoreParams::find()
+                ->andWhere(['store_type' => $data['store_type_id']])
+                ->select('store_id')
+                ->column()]);
+        }
+
+        if (!empty($territorialManager)) {
+            $territorialManagerStoreIds = StoreDynamic::find()
+                ->select('store_id')
+                ->where(['category' => 3, 'active' => 1, 'value_int' => $territorialManager])
+                ->column();
+
+            $query->andWhere(['in', 'id', $territorialManagerStoreIds ?: [-1]]);
+        }
+
+        if (!empty($bushChefFlorist)) {
+            $bushChefFloristStoreIds = StoreDynamic::find()
+                ->select('store_id')
+                ->where(['category' => 2, 'active' => 1, 'value_int' => $bushChefFlorist])
+                ->column();
+
+            $query->andWhere(['in', 'id', $bushChefFloristStoreIds ?: [-1]]);
+        }
+
+        $stores = $query->all();
+
+        return ArrayHelper::map($stores, 'id', 'name');
+    }
+}
diff --git a/erp24/views/matrix-statistics/index.php b/erp24/views/matrix-statistics/index.php
new file mode 100644 (file)
index 0000000..64ab08c
--- /dev/null
@@ -0,0 +1,148 @@
+<?php
+
+use yii\helpers\Html;
+use yii\base\DynamicModel;
+use yii\widgets\ActiveForm;
+use yii\helpers\ArrayHelper;
+
+use kartik\select2\Select2;
+use yii_app\helpers\HtmlHelper;
+use yii_app\records\StoreCityList;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
+use yii_app\records\StoreType;
+
+/* @var $model DynamicModel */
+/* @var $years array */
+/* @var $stores array */
+
+
+$this->registerJsFile('/js/matrix-statistics/index.js', ['position' => \yii\web\View::POS_END]);
+
+?>
+
+<div class="matrixStatisticsIndex m-5">
+
+    <h1>Статистика по продажам матрицы</h1>
+
+    <?php $form = ActiveForm::begin([
+        'id' => 'filter-form',
+        'method' => 'GET',
+        'action' => '/matrix-statistics'
+    ]) ?>
+
+    <div class="row">
+        <div class="col-6">
+            <div class="row">
+                <div class="col-4">
+                    <?= $form->field($model, 'year')->dropDownList($years)->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'city_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_CITY]), 'id', 'name'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'Города...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'store_type_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(StoreType::find()->all(), 'id', 'name'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'Тип магазина...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+            </div>
+            <div class="row mt-1">
+                <div class="col-4">
+                    <?= $form->field($model, 'month')->dropDownList(HtmlHelper::getMonthNames())->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'region_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'Регион...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'territory_manager_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'Тер. Управляющий...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+            </div>
+
+            <div class="row mt-2">
+                <div class="col-4">
+                    <?= $form->field($model, 'sale_type')->dropDownList([0 => 'Типы продаж', 1 => 'Оффлайн',
+                        2 => 'Интернет-магазин', 3 => 'Маркетплейсы'])->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'raion_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_DISTRICT]), 'id', 'name'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'Район...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+                <div class="col-4">
+                    <?= $form->field($model, 'kshf_id')->widget(Select2::class, [
+                        'data' => ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name'),
+                        'language' => 'ru',
+                        'options' => ['placeholder' => 'кШФ...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                        ]
+                    ])->label(false) ?>
+                </div>
+            </div>
+        </div>
+        <div class="col-4">
+            <div class="row">
+                <div class="col-1">
+                    <div class="row" style="min-height: 150px; align-items: center;">
+                        <div class="col-12">
+                            <button onclick="updateStores(); return false;">
+                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play-fill" viewBox="0 0 16 16">
+                                    <path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393"/>
+                                </svg>
+                            </button>
+                        </div>
+                    </div>
+                </div>
+                <div class="col-11">
+                    <?= $form->field($model, 'store_id')->dropDownList($stores, [
+                        'multiple' => false,
+                        'size' => 6,
+                        'class' => 'form-control',
+                        'id' => 'selected-store',
+                        'style'=> 'overflow-y: scroll, height: auto; max-height: 200px;  overflow-x: hidden;',
+                    ])->label(false) ?>
+                </div>
+            </div>
+            <div class="row">
+                <div class="col-1"></div>
+                <div class="col-11">
+                    <?= Html::submitButton('Применить', ['class' => 'btn btn-secondary'])?>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    <?php ActiveForm::end() ?>
+
+</div>
diff --git a/erp24/web/js/matrix-statistics/index.js b/erp24/web/js/matrix-statistics/index.js
new file mode 100644 (file)
index 0000000..196a470
--- /dev/null
@@ -0,0 +1,29 @@
+/* jshint esversion: 6 */
+
+const param27 = $('meta[name=csrf-param]').attr('content');
+const token27 = $('meta[name=csrf-token]').attr('content');
+
+function updateStores() {
+    const city_id = $('#dynamicmodel-city_id').val();
+    const region_id = $('#dynamicmodel-region_id').val();
+    const raion_id = $('#dynamicmodel-raion_id').val();
+    const store_type_id = $('#dynamicmodel-store_type_id').val();
+    const territory_manager_id = $('#dynamicmodel-territory_manager_id').val();
+    const kshf_id = $('#dynamicmodel-kshf_id').val();
+    $.ajax({
+        method: "POST",
+        url: '/matrix-statistics/get-stores',
+        data: { city_id, region_id, raion_id, store_type_id, territory_manager_id, kshf_id, [param27] : token27 },
+        dataType: 'json',
+        success: function (data) {
+            $('#selected-store').empty();
+            $.each(data, (key, value) => {
+                const option = document.createElement('OPTION');
+                option.value = key;
+                option.text = value;
+                $('#selected-store').append(option);
+            });
+        }
+    });
+}
+