From: Vladimir Fomichev Date: Thu, 11 Sep 2025 10:53:50 +0000 (+0300) Subject: Правки по привязке букетов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f9d79b35ad7a5b668b8eb1c23dc97722393bea84;p=erp24_rep%2Fyii-erp24%2F.git Правки по привязке букетов --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 1798d9e0..055469fa 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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)); +// } } } } diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index e4442e82..29d280d6 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -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, ]); } diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 05a82dee..cb9c01ec 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -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]); + } } } diff --git a/erp24/records/BouquetCompositionMatrixTypeHistory.php b/erp24/records/BouquetCompositionMatrixTypeHistory.php index 50d3c481..f2c52009 100644 --- a/erp24/records/BouquetCompositionMatrixTypeHistory.php +++ b/erp24/records/BouquetCompositionMatrixTypeHistory.php @@ -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} */ diff --git a/erp24/views/bouquet/_form.php b/erp24/views/bouquet/_form.php index 7bd07ccb..c75e0461 100644 --- a/erp24/views/bouquet/_form.php +++ b/erp24/views/bouquet/_form.php @@ -82,7 +82,7 @@ $form = ActiveForm::begin([ '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' => 'Тип матрицы', ], diff --git a/erp24/views/bouquet/index.php b/erp24/views/bouquet/index.php index db34e334..530d37f2 100644 --- a/erp24/views/bouquet/index.php +++ b/erp24/views/bouquet/index.php @@ -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; + ?>

title) ?>

@@ -52,7 +62,7 @@ $this->title = 'Содержание матрицы';
'control-label']) ?> request->get('matrix_type_id'), - ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'), [ + $types, [ 'class' => 'form-control', 'prompt' => 'Отобразить все' ]) ?> diff --git a/erp24/views/matrix-bouquet-actuality/index.php b/erp24/views/matrix-bouquet-actuality/index.php index 7e86cc85..3ab30ba2 100644 --- a/erp24/views/matrix-bouquet-actuality/index.php +++ b/erp24/views/matrix-bouquet-actuality/index.php @@ -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) {
- +
+ '', 'target' => '_blank']) ?> +