// 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));
+// }
}
}
}
use yii\web\UploadedFile;
use yii_app\helpers\DataHelper;
use yii_app\records\{BouquetComposition,
+ BouquetCompositionMatrixTypeHistory,
BouquetCompositionPrice,
BouquetCompositionProducts,
BouquetForecast,
// }
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],
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,
]);
}
}
}
- 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]);
+ }
}
}
public const IS_ACTIVE = true;
public const IS_INACTIVE = false;
+ public const MATRIX_TYPE_NONE = '__none';
+
/**
* {@inheritdoc}
*/
<?= 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' => 'Тип матрицы',
],
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;
$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>
<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' => 'Отобразить все'
]) ?>
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;
</div>
-
+ <div class="mt-2">
+ <?= Html::a('Редактировать группы', Url::to('/matrix-type'), ['class' => '', 'target' => '_blank']) ?>
+ </div>
</div>
<!-- 2-я колонка: даты актуальности -->