]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета
authormarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 12:45:40 +0000 (15:45 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 12:45:40 +0000 (15:45 +0300)
erp24/controllers/BouquetController.php
erp24/records/BouquetForecast.php
erp24/views/bouquet/_product_edit.php
erp24/views/bouquet/update.php

index a010f1da22900d73d14d01de9033353eb4d4c74e..33694ed8d36d30b5ee1552d18b5f46e29b8e7c6a 100644 (file)
@@ -36,7 +36,6 @@ class BouquetController extends Controller
         $month = $request->get('month');
         $matrixTypeId = $request->get('matrix_type_id');
 
-        // Убираем дублирование joinWith
         if ($year || $month) {
             $query->joinWith('bouquetForecast as bf');
         }
@@ -52,7 +51,6 @@ class BouquetController extends Controller
             $query->andWhere(['mth.matrix_type_id' => $matrixTypeId, 'mth.is_active' => BouquetCompositionMatrixTypeHistory::IS_ACTIVE]);
         }
 
-        // Предотвращаем дубликаты записей из-за join
         $query->groupBy('bouquet_composition.id');
 
         $dataProvider = new \yii\data\ActiveDataProvider([
@@ -76,9 +74,7 @@ class BouquetController extends Controller
             if ($data['matrix_type_id']) {
                 BouquetCompositionMatrixTypeHistory::setData($data['matrix_type_id'], $model->id);
             }
-            if ($model->save()) {
-                return $this->redirect(['index']);
-            }
+
             $month = $data['month'];
             $year = $data['year'];
 
@@ -119,6 +115,21 @@ class BouquetController extends Controller
                 }
             }
 
+            if ($data['products_quantity']) {
+                $bouquetProducts = Yii::$app->request->post('products_quantity');
+                foreach ($bouquetProducts as $key => $value) {
+                    $product = new BouquetCompositionProducts([
+                        'bouquet_id' => $model->id,
+                        'product_guid' => $key,
+                        'count' => $value
+                    ]);
+                    $product->save();
+                }
+            }
+
+            if ($model->save()) {
+                return $this->redirect(['view', 'id' => $model->id]);
+            }
         }
 
 
index bd7246557e64e5a462dc4c142c4dd82e23f03bac..b6d6111bd6c226b6b4ab7e645aa17d46b79bb2f1 100644 (file)
@@ -111,6 +111,7 @@ class BouquetForecast extends ActiveRecord
                     'name',
                     new Expression('NULL as value')
                 ])
+                ->orderBy("$joinTable.id")
                 ->asArray()
                 ->all();
         }
index a8351654dbb71156ea134f6b7b67143329032e17..13fb28eac2c661d2afc1f5f4456cbaa7be38c7c3 100644 (file)
@@ -1,8 +1,6 @@
 <?php use app\widgets\DualList;
 use yii\helpers\Html;
-use yii\widgets\ActiveForm;
-
-//$form = ActiveForm::begin(['id' => 'dual-list-form']); ?>
+?>
 <?= DualList::widget([
     'name' => 'products',
     'availableLabel' => 'Выбор',
@@ -33,4 +31,3 @@ use yii\widgets\ActiveForm;
     <?php } ?>
 
 </div>
-<?php //ActiveForm::end(); ?>
\ No newline at end of file
index bacbf3700f83e17eb00c985971ec9bd00ba720a5..a4921f543f1ca5606c2e2f8d90f8a4e8b48c388b 100644 (file)
@@ -45,6 +45,7 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
             <?= Html::button('Применить', ['class' => 'btn btn-primary w-100 mb-3', 'id' => 'apply-button']) ?>
         </div>
         <div class="col-md-8">
+            <?php $form = ActiveForm::begin(['id' => 'dual-list-form']); ?>
             <div class="row mb-5"></div>
             <?= $this->render('_product_edit', [
                 'availableItems' => $availableItems,
@@ -52,4 +53,5 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
                 'isCreate' => false,
                 'listContainerSize' => [],
             ]); ?>
-        </div>
+            <?php ActiveForm::end(); ?>
+        </div>
\ No newline at end of file