From c8a19190e7b6a92c124dd35021f7dd5835ed2276 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Thu, 13 Feb 2025 14:08:41 +0300 Subject: [PATCH] =?utf8?q?[ERP-310]=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81?= =?utf8?q?=D1=82=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D0=BC=D0=B0=D1=82?= =?utf8?q?=D1=80=D0=B8=D1=86=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../MatrixStatisticsController.php | 108 +++++++++++++ erp24/views/matrix-statistics/index.php | 148 ++++++++++++++++++ erp24/web/js/matrix-statistics/index.js | 29 ++++ 3 files changed, 285 insertions(+) create mode 100644 erp24/controllers/MatrixStatisticsController.php create mode 100644 erp24/views/matrix-statistics/index.php create mode 100644 erp24/web/js/matrix-statistics/index.js diff --git a/erp24/controllers/MatrixStatisticsController.php b/erp24/controllers/MatrixStatisticsController.php new file mode 100644 index 00000000..969c5fac --- /dev/null +++ b/erp24/controllers/MatrixStatisticsController.php @@ -0,0 +1,108 @@ + 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 index 00000000..64ab08cd --- /dev/null +++ b/erp24/views/matrix-statistics/index.php @@ -0,0 +1,148 @@ +registerJsFile('/js/matrix-statistics/index.js', ['position' => \yii\web\View::POS_END]); + +?> + +
+ +

Статистика по продажам матрицы

+ + 'filter-form', + 'method' => 'GET', + 'action' => '/matrix-statistics' + ]) ?> + +
+
+
+
+ field($model, 'year')->dropDownList($years)->label(false) ?> +
+
+ 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) ?> +
+
+ 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) ?> +
+
+
+
+ field($model, 'month')->dropDownList(HtmlHelper::getMonthNames())->label(false) ?> +
+
+ 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) ?> +
+
+ 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) ?> +
+
+ +
+
+ field($model, 'sale_type')->dropDownList([0 => 'Типы продаж', 1 => 'Оффлайн', + 2 => 'Интернет-магазин', 3 => 'Маркетплейсы'])->label(false) ?> +
+
+ 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) ?> +
+
+ 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) ?> +
+
+
+
+
+
+
+
+ +
+
+
+
+ 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) ?> +
+
+
+
+
+ 'btn btn-secondary'])?> +
+
+
+
+ + + +
diff --git a/erp24/web/js/matrix-statistics/index.js b/erp24/web/js/matrix-statistics/index.js new file mode 100644 index 00000000..196a4707 --- /dev/null +++ b/erp24/web/js/matrix-statistics/index.js @@ -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); + }); + } + }); +} + -- 2.39.5