]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
задачи
authorvladfo <fvv2011@gmail.com>
Mon, 16 Sep 2024 15:02:03 +0000 (18:02 +0300)
committervladfo <fvv2011@gmail.com>
Mon, 16 Sep 2024 15:02:03 +0000 (18:02 +0300)
erp24/actions/task/FourColumnsAction.php
erp24/controllers/TaskController.php
erp24/controllers/crud/TaskEntityController.php [new file with mode: 0644]
erp24/services/TaskService.php
erp24/views/crud/task-entity/_form.php [new file with mode: 0644]
erp24/views/crud/task-entity/create.php [new file with mode: 0644]
erp24/views/crud/task-entity/index.php [new file with mode: 0644]
erp24/views/crud/task-entity/update.php [new file with mode: 0644]
erp24/views/crud/task-entity/view.php [new file with mode: 0644]
erp24/views/crud/task/_form.php
erp24/views/task/four-columns.php

index dfd54c410416ee5edef3d2a6db050de829a2e5f1..aa529e4213b3e3e0ee4b09c2a0af911d89df1a52 100755 (executable)
@@ -75,6 +75,14 @@ class FourColumnsAction extends Action
             $tasksQuery = $tasksQuery->andWhere(['like', 'created_by', $filterModel->createdBy]);
         }
 
+        if ((int)$filterModel->entity_type > 0) {
+            $tasksQuery = $tasksQuery->andWhere(['entity_type_id' => $filterModel->entity_type]);
+        }
+
+        if ((int)$filterModel->entity_id > 0) {
+            $tasksQuery = $tasksQuery->andWhere(['entity_id' => $filterModel->entity_id]);
+        }
+
         $tasksQuery = $tasksQuery
             ->andWhere(['>=', 'created_at', DateTime::createFromFormat('d.m.Y', $filterModel->created_at_from)->format('Y-m-d 00:00:00')])
             ->andWhere(['<=', 'created_at', DateTime::createFromFormat('d.m.Y', $filterModel->created_at_to)->format('Y-m-d 23:59:59')])
@@ -108,6 +116,8 @@ class FourColumnsAction extends Action
             $tasksQuery = $eit ? $tasksQuery->joinWith('companyFunction')->andWhere(['entity' => 'store'])->andWhere(['function_entity_id' => $eit->export_val])->andWhere(['or', ['updated_by' => 0], ['updated_by' => null]]) : null;
         }
 
+
+
         $tasks = $tasksQuery ? $tasksQuery->andWhere(['or', ['task.parent_id' => 0], ['task.parent_id' => null]])->all() : [];
 
         $taskStatuses = ArrayHelper::map(TaskStatus::find()->all(), 'id', 'name');
index 221a480c941a561c9e0d78e1218942653dc1c63e..04f6bb4399fcd3d26fd6393c260b374de98f80a5 100755 (executable)
@@ -28,4 +28,16 @@ class TaskController extends \yii\web\Controller
             'support' => SupportAction::class,
         ];
     }
+
+    public function actionGetEntities()
+    {
+        if (Yii::$app->request->isAjax) {
+            $entityTypeId = Yii::$app->request->post('entity_type');
+            $entities = Entity::find()->where(['entity_type_id' => $entityTypeId])->all();
+
+            // Вернем JSON ответ с сущностями
+            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+            return ArrayHelper::map($entities, 'id', 'name');
+        }
+    }
 }
\ No newline at end of file
diff --git a/erp24/controllers/crud/TaskEntityController.php b/erp24/controllers/crud/TaskEntityController.php
new file mode 100644 (file)
index 0000000..fb43f43
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+namespace yii_app\controllers\crud;
+
+
+use Yii;
+use yii_app\records\TaskEntity;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+class TaskEntityController extends Controller
+{
+    public function behaviors()
+    {
+        return [
+            'verbs' => [
+                'class' => VerbFilter::className(),
+                'actions' => [
+                    'delete' => ['POST'],
+                ],
+            ],
+        ];
+    }
+
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => TaskEntity::find(),
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+
+    public function actionView($id)
+    {
+        return $this->render('view', [
+            'model' => $this->findModel($id),
+        ]);
+    }
+
+    public function actionCreate()
+    {
+        $model = new TaskEntity();
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('create', [
+            'model' => $model,
+        ]);
+    }
+
+    public function actionUpdate($id)
+    {
+        $model = $this->findModel($id);
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('update', [
+            'model' => $model,
+        ]);
+    }
+
+    public function actionDelete($id)
+    {
+        $this->findModel($id)->delete();
+
+        return $this->redirect(['index']);
+    }
+
+    protected function findModel($id)
+    {
+        if (($model = TaskEntity::findOne($id)) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
\ No newline at end of file
index c0e6f06e86c2e5eee541245ed0095a98cb7a727b..d9ecef013f60417b3fbe8b4f05ac6800bd5cd887 100644 (file)
@@ -6,6 +6,7 @@ use yii\helpers\ArrayHelper;
 use yii_app\records\Admin;
 use yii_app\records\Files;
 use yii_app\records\Lessons;
+use yii_app\records\UniversalCatalogItem;
 use yii_app\records\Products1c;
 use yii_app\records\Task;
 use yii_app\records\TaskStatus;
@@ -18,6 +19,7 @@ class TaskService
         switch ($alias) {
             case 'matrix': return ArrayHelper::map(Products1c::find()->joinWith('productClass pc')->where(['pc.tip' => 'matrix'])->all(), 'id', 'name');
             case "lesson": return ArrayHelper::map(Lessons::find()->all(), 'id', 'name');
+            case "bpmn": return  ArrayHelper::map(UniversalCatalogItem::find()->where(['catalog_alias' => 'bpmn'])->all(), 'id', 'name');
             case 'store': return ArrayHelper::map(Products1c::find()->where(['tip' => 'city_store'])->andWhere(['view' => '1'])->orderBy('name')->all(), 'id', 'name');
             case "lesson_group": break;
         }
@@ -175,26 +177,50 @@ class TaskService
             switch ($task->status) {
                 case 1:
                 case 2:
-                    TelegramService::sendMessage($task->updated_by, $msg, $reply_markup_updated_by); break;
+                try {
+                    TelegramService::sendMessage($task->updated_by, $msg, $reply_markup_updated_by);
+                } catch (\Exception $e) {
+
+                    error_log("Error sending message to updated_by: " . $e->getMessage());
+                }
+                break;
                 case -1:
                 case 3:
                 case 4:
                 case 5:
                 case 6:
-                    TelegramService::sendMessage($task->updated_by, $msg . "(исполнителю)", $reply_markup_info); break;
+                try {
+                    TelegramService::sendMessage($task->updated_by, $msg . "(исполнителю)", $reply_markup_info);
+                } catch (\Exception $e) {
+
+                    error_log("Error sending message to updated_by: " . $e->getMessage());
+                }
+                break;
             }
         }
         if ($task->controller_id && ($task->controller_id != $task->updated_by || $task->status == 5)) {
             switch ($task->status) {
                 case 5:
-                    TelegramService::sendMessage($task->controller_id, $msg, $reply_markup_controller); break;
+                    try {
+                        TelegramService::sendMessage($task->controller_id, $msg, $reply_markup_controller);
+                    } catch (\Exception $e) {
+
+                        error_log("Error sending message to controller_id: " . $e->getMessage());
+                    }
+                    break;
                 case -1:
                 case 1:
                 case 2:
                 case 3:
                 case 4:
                 case 6:
-                    TelegramService::sendMessage($task->controller_id, $msg . "(контроллеру)", $reply_markup_info); break;
+                try {
+                    TelegramService::sendMessage($task->controller_id, $msg . "(контроллеру)", $reply_markup_info);
+                } catch (\Exception $e) {
+
+                    error_log("Error sending message to controller_id: " . $e->getMessage());
+                }
+                break;
             }
         }
         if ($task->created_by && $task->created_by != $task->controller_id && $task->created_by != $task->updated_by) {
@@ -206,7 +232,13 @@ class TaskService
                 case 4:
                 case 5:
                 case 6:
-                    TelegramService::sendMessage($task->created_by, $msg . "(создателю)", $reply_markup_info); break;
+                try {
+                    TelegramService::sendMessage($task->created_by, $msg . "(создателю)", $reply_markup_info);
+                } catch (\Exception $e) {
+
+                    error_log("Error sending message to created_by: " . $e->getMessage());
+                }
+                break;
             }
         }
     }
diff --git a/erp24/views/crud/task-entity/_form.php b/erp24/views/crud/task-entity/_form.php
new file mode 100644 (file)
index 0000000..a0da5da
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+?>
+
+<div class="task-entity-form">
+    <?php $form = ActiveForm::begin(); ?>
+    <?= $form->field($model, 'name')->textInput(['maxlength' => true])->label('Имя') ?>
+    <?= $form->field($model, 'alias')->textInput(['maxlength' => true])->label('Псевдоним') ?>
+    <div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+    </div>
+    <?php ActiveForm::end(); ?>
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger']) ?>
+
+</div>
diff --git a/erp24/views/crud/task-entity/create.php b/erp24/views/crud/task-entity/create.php
new file mode 100644 (file)
index 0000000..4a55706
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+use yii\helpers\Html;
+
+$this->title = 'Создание типа сущности';
+$this->params['breadcrumbs'][] = ['label' => 'Task Entities', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="task-entity-create  p-4">
+    <h1><?= Html::encode($this->title) ?></h1>
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
diff --git a/erp24/views/crud/task-entity/index.php b/erp24/views/crud/task-entity/index.php
new file mode 100644 (file)
index 0000000..fcd7dd3
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+$this->title = 'Тип сущности';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="task-entity-index p-4">
+    <h1><?= Html::encode($this->title) ?></h1>
+    <p>
+        <?= Html::a('Создать', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+            'id',
+            'name',
+            'alias',
+            ['class' => 'yii\grid\ActionColumn'],
+        ],
+    ]); ?>
+</div>
diff --git a/erp24/views/crud/task-entity/update.php b/erp24/views/crud/task-entity/update.php
new file mode 100644 (file)
index 0000000..a96990b
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+use yii\helpers\Html;
+
+$this->title = 'Редактирование типа сущности: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Task Entities', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+<div class="task-entity-update  p-4">
+    <h1><?= Html::encode($this->title) ?></h1>
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
diff --git a/erp24/views/crud/task-entity/view.php b/erp24/views/crud/task-entity/view.php
new file mode 100644 (file)
index 0000000..5087956
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Task Entities', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="task-entity-view  p-4">
+    <h1><?= Html::encode($this->title) ?></h1>
+    <p>
+        <?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы уверены что хотите удалить эту запись?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'name',
+            'alias',
+        ],
+    ]) ?>
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger']) ?>
+</div>
\ No newline at end of file
index e08171dda82212e5c898b34a5a6d05c3d60bc7d6..f511f181c8e072b13b1e6b2fa166f8c5501e7792 100755 (executable)
@@ -52,7 +52,7 @@ $this->registerJsFile('/js/crud/task/update.js', ['position' => \yii\web\View::P
         'pluginEvents' => [
             "change" => "function() {
                 var value= $(this).val();
-                
+                console.log(value);
                 $.ajax({
                     method: 'POST',
                     dataType: 'text',
@@ -60,6 +60,7 @@ $this->registerJsFile('/js/crud/task/update.js', ['position' => \yii\web\View::P
                     data: { value : value },
                     success: function (response) {
                         var r = JSON.parse(response);
+                        console.log(r);
                         var myDropDownList = document.getElementById('task-entity_id');
                         while (myDropDownList.options.length > 0) {
                             myDropDownList.remove(myDropDownList.options.length - 1);
index 5e3c2845db17ac4b80944f38af6ce27be98a54ef..749100e2357f5f47c614164705f8fee0fd5da76f 100755 (executable)
@@ -5,7 +5,7 @@ use yii\helpers\Html;
 
 use \kartik\select2\Select2;
 use dosamigos\datepicker\DatePicker;
-
+use yii\helpers\ArrayHelper;
 use \yii_app\helpers\PrintBlockHelper;
 
 /** @var array $tasks */
@@ -61,7 +61,45 @@ $this->registerJsFile('/js/task/four-columns.js', ['position' => \yii\web\View::
         ])->label(false) ?>
     </div>
 </div>
-
+<div class="row">
+    <div class="col-2">
+        <?= $form->field($filterModel, 'entity_type')->widget(Select2::class, [
+            'data' => ArrayHelper::map($taskEntityTypes, 'id', 'name'), // Типы сущностей
+            'language' => 'ru',
+            'options' => ['placeholder' => 'Тип сущности...'],
+            'pluginOptions' => [
+                'allowClear' => true,
+            ],
+            'pluginEvents' => [
+                "change" => "function() {
+                    var entityType = $(this).val();
+                    $.ajax({
+                        method: 'POST',
+                        url: '/path/to/get-entities', // Указать URL для получения сущностей по типу
+                        data: { entity_type: entityType },
+                        success: function(data) {
+                            var entitiesDropdown = $('#dynamicmodel-entity_id');
+                            entitiesDropdown.empty(); // Очистить предыдущие значения
+                            $.each(data, function(index, value) {
+                                entitiesDropdown.append(new Option(value, index));
+                            });
+                        }
+                    });
+                }"
+            ]
+        ])->label(false) ?>
+    </div>
+    <div class="col-2">
+        <?= $form->field($filterModel, 'entity_id')->widget(Select2::class, [
+            'data' => $entities, // Изначально пустой или предзагруженные сущности
+            'language' => 'ru',
+            'options' => ['placeholder' => 'Сущность...'],
+            'pluginOptions' => [
+                'allowClear' => true,
+            ]
+        ])->label(false) ?>
+    </div>
+</div>
 <div class="row">
     <div class="col-3">
         <div class="row">
@@ -196,8 +234,15 @@ $this->registerJsFile('/js/task/four-columns.js', ['position' => \yii\web\View::
     </div>
 </div>
 
+
 <?php ActiveForm::end() ?>
+<div class="row">
+    <div class="col-4">
+        <?= Html::a('Создать задачу', ['/crud/task/create'], ['class' => 'btn btn-success', 'target' => '_blank', 'data-pjax' => '0']) ?>
 
+    </div>
+
+</div>
 <div class="card mt-2">
     <div class="row g-0">
         <?php if (isset($taskStatuses)): //<div class="col-1 font-weight-bold"></div> ?>