From 6b93a8d4410a8dde6273b93037b0897bf9c8b23a Mon Sep 17 00:00:00 2001 From: marina Date: Thu, 20 Feb 2025 14:49:42 +0300 Subject: [PATCH] =?utf8?q?ERP-302=20=D0=A0=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?utf8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B1=D1=83?= =?utf8?q?=D0=BA=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/BouquetController.php | 25 +++++++++++++++++ erp24/records/BouquetComposition.php | 7 +++++ erp24/records/BouquetForecast.php | 8 ++++-- erp24/views/bouquet/_form.php | 4 +-- erp24/views/bouquet/index.php | 3 ++- erp24/views/bouquet/view.php | 1 + erp24/web/js/bouquet/bouquet.js | 36 +++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 5 deletions(-) diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 1b325de7..a010f1da 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -8,6 +8,7 @@ use yii\helpers\ArrayHelper; use yii\helpers\Url; use yii\web\Controller; use yii\web\NotFoundHttpException; +use yii\web\Response; use yii\web\UploadedFile; use yii_app\helpers\DataHelper; use yii_app\records\BouquetComposition; @@ -346,4 +347,28 @@ class BouquetController extends Controller return ArrayHelper::map($query->asArray()->all(), 'id', 'name'); } + + public function actionGetSalesData() + { + Yii::$app->response->format = Response::FORMAT_JSON; + + $year = Yii::$app->request->post('year'); + $month = Yii::$app->request->post('month'); + $id = Yii::$app->request->post('id'); + + if (!$year || !$month || !$id) { + return ['success' => false, 'message' => 'Некорректные параметры']; + } + + $storesTypeList = BouquetForecast::getStoresList($id, BouquetForecast::OFFLINE_STORES, StoreType::class, [], $month, $year); + $marketplaceList = BouquetForecast::getStoresList($id, BouquetForecast::MARKETPLACE, CityStore::class, ['visible' => CityStore::IS_VISIBLE], $month, $year); + $onlineStoresList = BouquetForecast::getStoresList($id, BouquetForecast::ONLINE_STORES, CityStore::class, ['visible' => CityStore::IS_VISIBLE], $month, $year); + + return [ + 'success' => true, + 'offline' => $storesTypeList, + 'online' => $onlineStoresList, + 'marketplace' => $marketplaceList, + ]; + } } diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 28efe9de..df611110 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -199,4 +199,11 @@ class BouquetComposition extends ActiveRecord { return $this->hasMany(BouquetForecast::class, ['bouquet_id' => 'id']); } + + public static function getYears() + { + $currentYear = date('Y'); + $years = range($currentYear - 5, $currentYear + 5); + return array_combine($years, $years); + } } diff --git a/erp24/records/BouquetForecast.php b/erp24/records/BouquetForecast.php index 6acef163..bd724655 100644 --- a/erp24/records/BouquetForecast.php +++ b/erp24/records/BouquetForecast.php @@ -87,12 +87,16 @@ class BouquetForecast extends ActiveRecord ]; } - public static function getStoresList($id, $typeSales, $defaultModel, $defaultCondition) + public static function getStoresList($id, $typeSales, $defaultModel, $defaultCondition, $month = null, $year = null) { $joinTable = $defaultModel === CityStore::class ? 'city_store' : 'store_type'; + $list = BouquetForecast::find() - ->andWhere(['bouquet_id' => $id, 'type_sales' => $typeSales]) + ->andWhere(['bouquet_id' => $id]) + ->andWhere(['type_sales' => $typeSales]) + ->andWhere(['month' => $month ?? date('m')]) + ->andWhere([ 'year' => $year ?? date('Y')]) ->leftJoin("$joinTable AS df", "df.id = bouquet_forecast.type_sales_id") ->select(["df.name AS name", 'type_sales_value AS value', 'type_sales_id AS id']) ->orderBy('type_sales_id') diff --git a/erp24/views/bouquet/_form.php b/erp24/views/bouquet/_form.php index 1e3f793f..a798f471 100644 --- a/erp24/views/bouquet/_form.php +++ b/erp24/views/bouquet/_form.php @@ -181,11 +181,11 @@ $form = ActiveForm::begin([
'font-weight-bold pt-3 h6']) ?>
-
forecastMonthAndYear->year ?? null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?>
+
'form-control year-picker']) ?>
'font-weight-bold pt-3 h6']) ?>
-
forecastMonthAndYear->month ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?>
+
'form-control month-picker']) ?>
diff --git a/erp24/views/bouquet/index.php b/erp24/views/bouquet/index.php index d995b97f..c4520913 100644 --- a/erp24/views/bouquet/index.php +++ b/erp24/views/bouquet/index.php @@ -5,6 +5,7 @@ use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\ActiveForm; +use yii_app\records\BouquetComposition; use yii_app\records\Files; use yii_app\records\MatrixType; use yii_app\records\Products1c; @@ -31,7 +32,7 @@ $this->title = 'Содержание матрицы';
- request->get('year'), [2024 => 2024, 2025 => 2025], [ + request->get('year'), BouquetComposition::getYears(), [ 'class' => 'form-control', 'prompt' => 'Год' ]) ?> diff --git a/erp24/views/bouquet/view.php b/erp24/views/bouquet/view.php index b126225c..48851bd6 100644 --- a/erp24/views/bouquet/view.php +++ b/erp24/views/bouquet/view.php @@ -15,6 +15,7 @@ use yii\helpers\Url; $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; +$this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::POS_END]); ?>
diff --git a/erp24/web/js/bouquet/bouquet.js b/erp24/web/js/bouquet/bouquet.js index 14d871ab..e724f7aa 100644 --- a/erp24/web/js/bouquet/bouquet.js +++ b/erp24/web/js/bouquet/bouquet.js @@ -7,3 +7,39 @@ document.addEventListener('DOMContentLoaded', function() { }); }); }); +$(document).ready(function () { + if (window.location.pathname.includes('/bouquet/view')) { + $('.year-picker, .month-picker').on('change', function () { + let year = $('.year-picker').val(); + let month = $('.month-picker').val(); + let urlParams = new URLSearchParams(window.location.search); + let id = urlParams.get('id'); + + if (!id) { + return; + } + + $.ajax({ + url: '/bouquet/get-sales-data', + type: 'POST', + data: { year: year, month: month, id: id }, + dataType: 'json', + success: function(response) { + console.log("Ответ сервера:", response); + if (response) { + ['offline', 'online', 'marketplace'].forEach(type => { + $.each(response[type], function(_, value) { + let inputSelector = `input[name='BouquetForecast[type_sales_value][${type}][${value.id}]']`; + console.log(`Поиск инпута: ${inputSelector}, установка значения: ${value.value}`); + $(inputSelector).val(value.value); + }); + }); + } + }, + error: function(xhr, status, error) { + console.error("Ошибка загрузки данных:", status, error); + } + }); + }); + } +}); -- 2.39.5