]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки по привязке букетов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 11 Sep 2025 10:53:50 +0000 (13:53 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 11 Sep 2025 10:53:50 +0000 (13:53 +0300)
erp24/api2/controllers/DataController.php
erp24/controllers/BouquetController.php
erp24/records/BouquetComposition.php
erp24/records/BouquetCompositionMatrixTypeHistory.php
erp24/views/bouquet/_form.php
erp24/views/bouquet/index.php
erp24/views/matrix-bouquet-actuality/index.php

index 1798d9e0f2a9c066ec64289ca5ce26f17da59366..055469fae273680152fd5cdd24f6842c11e941c8 100644 (file)
@@ -1244,15 +1244,15 @@ class DataController extends BaseController
 //                                if(empty($costModels)) {
 //                                    LogService::apiErrorLog(json_encode(["error_id" => 8.3, "error" => "Стоимость и цена не подсчитаны"], JSON_UNESCAPED_UNICODE));
 //                                }
-                                $bouquetTypeHistory = new BouquetCompositionMatrixTypeHistory();
-                                $bouquetTypeHistory->bouquet_id = $newBouquetComp->id;
-                                $bouquetTypeHistory->matrix_type_id = 1;
-                                $bouquetTypeHistory->created_by = Admin::getAdminAgentId() ?: null;
-                                $bouquetTypeHistory->is_active = 1;
-                                $bouquetTypeHistory->date_from = date('Y-m-d H:i:s');
-                                if(!$bouquetTypeHistory->save()) {
-                                    LogService::apiErrorLog(json_encode(["error_id" => 8.4, "error" => $bouquetTypeHistory->getErrors()], JSON_UNESCAPED_UNICODE));
-                                }
+//                                $bouquetTypeHistory = new BouquetCompositionMatrixTypeHistory();
+//                                $bouquetTypeHistory->bouquet_id = $newBouquetComp->id;
+//                                $bouquetTypeHistory->matrix_type_id = 1;
+//                                $bouquetTypeHistory->created_by = Admin::getAdminAgentId() ?: null;
+//                                $bouquetTypeHistory->is_active = 1;
+//                                $bouquetTypeHistory->date_from = date('Y-m-d H:i:s');
+//                                if(!$bouquetTypeHistory->save()) {
+//                                    LogService::apiErrorLog(json_encode(["error_id" => 8.4, "error" => $bouquetTypeHistory->getErrors()], JSON_UNESCAPED_UNICODE));
+//                                }
                             }
                         }
                     }
index e4442e8224939cd3210bcfd26da4dac02f680bca..29d280d64c6c1765b99fd3d7b56f885482bdd8c3 100644 (file)
@@ -18,6 +18,7 @@ use yii\web\Response;
 use yii\web\UploadedFile;
 use yii_app\helpers\DataHelper;
 use yii_app\records\{BouquetComposition,
+    BouquetCompositionMatrixTypeHistory,
     BouquetCompositionPrice,
     BouquetCompositionProducts,
     BouquetForecast,
@@ -53,7 +54,17 @@ class BouquetController extends Controller
 //        }
 
         BouquetComposition::applyFilters($query, $request);
-
+        $matrixTypeId = $request->get('matrix_type_id');
+        $matrixTypeLabel = null;
+
+        if ($matrixTypeId === BouquetCompositionMatrixTypeHistory::MATRIX_TYPE_NONE) {
+            $matrixTypeLabel = 'Без типов';
+        } elseif ($matrixTypeId !== null && $matrixTypeId !== '' && ctype_digit((string)$matrixTypeId)) {
+            $matrixTypeLabel = MatrixType::find()
+                ->select('name')
+                ->where(['id' => (int)$matrixTypeId])
+                ->scalar();
+        }
         $dataProvider = new \yii\data\ActiveDataProvider([
             'query' => $query,
             'pagination' => ['pageSize' => 20],
@@ -61,9 +72,7 @@ class BouquetController extends Controller
 
         return $this->render('index', [
             'dataProvider' => $dataProvider,
-            'matrix_type' => $request->get('matrix_type_id')
-                ? MatrixType::findOne($request->get('matrix_type_id'))?->name
-                : null,
+            'matrix_type' => $matrixTypeLabel,
         ]);
     }
 
index 05a82deefd0bb6efd34f4fc0ec34cc18fa6f12b3..cb9c01ec9e5ed0a9db9daf080cb8586e7a82cf50 100644 (file)
@@ -170,14 +170,24 @@ class BouquetComposition extends ActiveRecord
             }
         }
 
-        if ($matrixTypeId = $request->get('matrix_type_id')) {
-            $query->leftJoin(
-                'erp24.bouquet_composition_matrix_type_history mth', // Добавили схему
-                'mth.bouquet_id = bouquet_composition.id'
-            )->andWhere([
-                'mth.matrix_type_id' => $matrixTypeId,
-                'mth.is_active' => true // Используем true без константы
-            ]);
+        $matrixTypeId = $request->get('matrix_type_id');
+
+        if ($matrixTypeId !== null && $matrixTypeId !== '') {
+            if ($matrixTypeId === BouquetCompositionMatrixTypeHistory::MATRIX_TYPE_NONE) {
+                $query->andWhere("
+                NOT EXISTS (
+                    SELECT 1
+                    FROM erp24.bouquet_composition_matrix_type_history m
+                    WHERE m.bouquet_id = bouquet_composition.id
+                )
+            ");
+            } else {
+                $query->leftJoin(
+                    'erp24.bouquet_composition_matrix_type_history mth',
+                    'mth.bouquet_id = bouquet_composition.id AND mth.is_active = TRUE'
+                );
+                $query->andWhere(['mth.matrix_type_id' => (int)$matrixTypeId]);
+            }
         }
     }
 
index 50d3c48157e8b6000eae11ee93f635e49ae01b61..f2c52009a5e28444dd8b62fc803e55c6a08d5501 100644 (file)
@@ -28,6 +28,8 @@ class BouquetCompositionMatrixTypeHistory extends ActiveRecord
     public const IS_ACTIVE = true;
     public const IS_INACTIVE = false;
 
+    public const MATRIX_TYPE_NONE = '__none';
+
     /**
      * {@inheritdoc}
      */
index 7bd07ccb4c761a6e2b17f090844e8e955eec4381..c75e0461d6a4a3d3b5e31cbda5e094d8f9fa297c 100644 (file)
@@ -82,7 +82,7 @@ $form = ActiveForm::begin([
                     <?= Select2::widget([
                         'name' => 'matrix_type_id',
                         'value' => isset($model->matrixType) ? $model->matrixType->matrix_type_id : null,
-                        'data' => ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'),
+                        'data' => ArrayHelper::map(MatrixType::find()->where(['is not', 'parent_id', null])->all(), 'id', 'name'),
                         'options' => [
                             'placeholder' => 'Тип матрицы',
                         ],
index db34e3343e01747e1d43a1c0d579ea85c27c31fa..530d37f2978594c9adb133f1f6fb9d341a9fa585 100644 (file)
@@ -6,6 +6,7 @@ use yii\helpers\Html;
 use yii\helpers\Url;
 use yii\widgets\ActiveForm;
 use yii_app\records\BouquetComposition;
+use yii_app\records\BouquetCompositionMatrixTypeHistory;
 use yii_app\records\Files;
 use yii_app\records\MatrixType;
 use yii_app\records\Products1c;
@@ -19,6 +20,15 @@ $this->registerCssFile('@web/css/fancybox.css');
 $this->registerJsFile('@web/js/fancybox.umd.js', ['position' => View::POS_END]);
 $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => View::POS_END]);
 $this->title = 'Содержание матрицы';
+
+
+$types = ArrayHelper::map(
+    MatrixType::find()->where(['is not', 'parent_id', null])->orderBy('name')->all(),
+    'id',
+    'name'
+);
+$types = [BouquetCompositionMatrixTypeHistory::MATRIX_TYPE_NONE => '— Без типов —'] + $types;
+
 ?>
 <div class="bouquet-index p-4">
     <h1><?= Html::encode($this->title) ?></h1>
@@ -52,7 +62,7 @@ $this->title = 'Содержание матрицы';
             <div class="form-group mb-0">
                 <?= Html::label('Тип матрицы', 'matrix_type_id', ['class' => 'control-label']) ?>
                 <?= Html::dropDownList('matrix_type_id', Yii::$app->request->get('matrix_type_id'),
-                    ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'), [
+                    $types, [
                         'class' => 'form-control',
                         'prompt' => 'Отобразить все'
                     ]) ?>
index 7e86cc85e4daf1ead2e19a3657e376a0ba0c62b5..3ab30ba2fa415171ecea3847333274ec69e43f68 100644 (file)
@@ -3,6 +3,7 @@
 use kartik\form\ActiveForm;
 use kartik\grid\GridView;
 use yii\helpers\Html;
+use yii\helpers\Url;
 use yii\web\View;
 use yii_app\records\Products1cNomenclatureActuality;
 
@@ -102,7 +103,9 @@ foreach ($subgroups as $sg) {
 
 
             </div>
-
+            <div class="mt-2">
+                <?= Html::a('Редактировать группы', Url::to('/matrix-type'), ['class' => '', 'target' => '_blank']) ?>
+            </div>
         </div>
 
         <!-- 2-я колонка: даты актуальности -->