]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета
authormarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 11:49:42 +0000 (14:49 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 11:49:42 +0000 (14:49 +0300)
erp24/controllers/BouquetController.php
erp24/records/BouquetComposition.php
erp24/records/BouquetForecast.php
erp24/views/bouquet/_form.php
erp24/views/bouquet/index.php
erp24/views/bouquet/view.php
erp24/web/js/bouquet/bouquet.js

index 1b325de7df44ff155186eb5862b677dfb29b5bc7..a010f1da22900d73d14d01de9033353eb4d4c74e 100644 (file)
@@ -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,
+        ];
+    }
 }
index 28efe9de836a4b47bd3fda6b893383a2243e40a6..df6111100ba2b9d5a1213f5dd2ac62bfffc7b3c8 100644 (file)
@@ -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);
+    }
 }
index 6acef163d876732575242cc6f125b3299ab1ba74..bd7246557e64e5a462dc4c142c4dd82e23f03bac 100644 (file)
@@ -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')
index 1e3f793f9444f0a8d819574b07c44e02bad6d410..a798f4718d9d3ea19bc7b4e598c58648246c8bc5 100644 (file)
@@ -181,11 +181,11 @@ $form = ActiveForm::begin([
             <div class="row">
                 <div class="col-md-5">
                     <div class="col-md-3"><?= Html::label("Год", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
-                    <div class="col-md-9"> <?= Html::dropDownList("year", $model?->forecastMonthAndYear->year ?? null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?></div>
+                    <div class="col-md-9"> <?= Html::dropDownList("year", date('Y') ?? null, BouquetComposition::getYears(), ['class' => 'form-control year-picker']) ?></div>
                 </div>
                 <div class="col-md-7">
                     <div class="col-md-3"><?= Html::label("Месяц", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
-                    <div class="col-md-9"><?= Html::dropDownList("month", $model?->forecastMonthAndYear->month ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?></div>
+                    <div class="col-md-9"><?= Html::dropDownList("month", date('m') ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control month-picker']) ?></div>
                 </div>
             </div>
             <div class="row">
index d995b97f51d2d58f7f276a98e7e46c96aab5489c..c4520913118ec820cd76b45dcb8c5c31c0189567 100644 (file)
@@ -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 = 'Содержание матрицы';
 
         <div class="col-md-2">
             <div class="form-group mb-0">
-                <?= Html::dropDownList("year", Yii::$app->request->get('year'), [2024 => 2024, 2025 => 2025], [
+                <?= Html::dropDownList("year", Yii::$app->request->get('year'), BouquetComposition::getYears(), [
                     'class' => 'form-control',
                     'prompt' => 'Год'
                 ]) ?>
index b126225c807fd4615f5b157fb328dc9b08c82f60..48851bd6eaf00a5615944e3f97a4839e052bb4dc 100644 (file)
@@ -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]);
 ?>
 
 <div class="bouquet-view border-bottom-4 p-7">
index 14d871ab81eb6650698d01b4242aac5b8d6844ff..e724f7aab098c355f833e7117b500cf6b43a25ac 100644 (file)
@@ -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);
+                }
+            });
+        });
+    }
+});