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

index 95999c8d547bcfbb36aa075dbf57dacdbe3f6df0..c65ec2b9a690093714a72d3e590912bd1747e755 100644 (file)
@@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException;
 use yii_app\records\BouquetComposition;
 use yii_app\records\BouquetCompositionProducts;
 use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
 
 /**
  * Контроллер для управления букетами и их составами.
@@ -98,14 +99,27 @@ class BouquetController extends Controller
     {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
 
-        
+        $request = Yii::$app->request;
 
-        $products = Products1c::find()
-            ->where(['tip' => Products1c::TYPE_PRODUCTS, 'view' => Products1c::IS_VISIBLE])
-            ->andWhere(['ilike', 'name', 'роза'])
-            ->asArray()
-            ->all();
+        $conditions = array_filter([
+            'tip' => $request->post('tip'),
+            'color' => $request->post('color'),
+            'species' => $request->post('species'),
+            'category' => $request->post('category'),
+            'size' => $request->post('size'),
+        ]);
+
+        $filters = array_map(fn($field, $value) => Products1cNomenclature::find()->select('id')->where([$field => $value]), array_keys($conditions), $conditions);
+
+        $query = Products1c::find()->where([
+            'tip' => Products1c::TYPE_PRODUCTS,
+            'view' => Products1c::IS_VISIBLE,
+        ]);
+
+        if (!empty($filters)) {
+            $query->andWhere(['in', 'id', array_values($filters)]);
+        }
 
-        return ArrayHelper::map($products, 'id', 'name');
+        return ArrayHelper::map($query->asArray()->all(), 'id', 'name');
     }
 }
index 5de8c3403270a9d8dbae228047a9587f37b26ef0..bdbe9095b996a97a28f2915de61512e6520fc101 100644 (file)
@@ -5,9 +5,12 @@ use yii\helpers\ArrayHelper;
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
 
 /** @var yii\web\View $this */
 /** @var yii_app\records\BouquetComposition $model */
+/** @var array|null $availableItems */
+/** @var array|null $selectedItems */
 
 $this->title = 'Три гладиолуса';
 $this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']];
@@ -26,19 +29,19 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
                 <?= Html::tag('div', Html::label('Фильтры'), ['class' => 'fw-bold fs-5 text-center']) ?>
             </div>
             <div class="row mb-2">
-                <?= Html::dropDownList('category', null, [], ['class' => 'form-select', 'prompt' => 'Выберите категорию']) ?>
+                <?= Html::dropDownList('category', null, Products1cNomenclature::find()->select('category')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите категорию']) ?>
             </div>
             <div class="row mb-2">
-                <?= Html::dropDownList('species', null, [], ['class' => 'form-select', 'prompt' => 'Выберите вид']) ?>
+                <?= Html::dropDownList('species', null, Products1cNomenclature::find()->select('species')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите вид']) ?>
             </div>
             <div class="row mb-2">
-                <?= Html::dropDownList('type', null, [], ['class' => 'form-select', 'prompt' => 'Выберите тип']) ?>
+                <?= Html::dropDownList('type', null, Products1cNomenclature::find()->select('type_num')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите тип']) ?>
             </div>
             <div class="row mb-2">
-                <?= Html::dropDownList('size', null, [], ['class' => 'form-select', 'prompt' => 'Выберите размер']) ?>
+                <?= Html::dropDownList('size', null, Products1cNomenclature::find()->select('size')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите размер']) ?>
             </div>
             <div class="row mb-3">
-                <?= Html::dropDownList('color', null, [], ['class' => 'form-select', 'prompt' => 'Выберите цвет']) ?>
+                <?= Html::dropDownList('color', null, Products1cNomenclature::find()->select('color')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите цвет']) ?>
             </div>
 
             <?= Html::button('Применить', ['class' => 'btn btn-primary w-100 mb-3', 'id' => 'apply-button']) ?>