From 2dd0d8c932821c641e85aa50b299b52fab70972f Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 4 Feb 2025 15:55: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 | 28 ++++++++++++++++++------- erp24/views/bouquet/update.php | 13 +++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 95999c8d..c65ec2b9 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -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'); } } diff --git a/erp24/views/bouquet/update.php b/erp24/views/bouquet/update.php index 5de8c340..bdbe9095 100644 --- a/erp24/views/bouquet/update.php +++ b/erp24/views/bouquet/update.php @@ -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 'fw-bold fs-5 text-center']) ?>
- 'form-select', 'prompt' => 'Выберите категорию']) ?> + select('category')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите категорию']) ?>
- 'form-select', 'prompt' => 'Выберите вид']) ?> + select('species')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите вид']) ?>
- 'form-select', 'prompt' => 'Выберите тип']) ?> + select('type_num')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите тип']) ?>
- 'form-select', 'prompt' => 'Выберите размер']) ?> + select('size')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите размер']) ?>
- 'form-select', 'prompt' => 'Выберите цвет']) ?> + select('color')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите цвет']) ?>
'btn btn-primary w-100 mb-3', 'id' => 'apply-button']) ?> -- 2.39.5