]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
изменения основной таблицы и таблицы просмотра а так же методов создания и редактирования
authorJoySystem_v <fvv2011@gmail.com>
Fri, 16 Aug 2024 14:07:41 +0000 (17:07 +0300)
committerJoySystem_v <fvv2011@gmail.com>
Fri, 16 Aug 2024 14:07:41 +0000 (17:07 +0300)
erp24/controllers/crud/EmployeePaymentController.php
erp24/forms/EmployeePaymentSearch.php
erp24/views/crud/employee-payment/_form.php
erp24/views/crud/employee-payment/_search.php
erp24/views/crud/employee-payment/create.php
erp24/views/crud/employee-payment/index.php
erp24/views/crud/employee-payment/update.php
erp24/views/crud/employee-payment/view.php
erp24/views/layouts/main.php

index 082aed0af20f4b16443fadb4c978e70c5749aaa2..7e3841456b59b986da0d0d090f87195569da0100 100755 (executable)
@@ -2,6 +2,8 @@
 
 namespace yii_app\controllers\crud;
 
+use yii\data\ActiveDataProvider;
+use yii_app\records\Admin;
 use yii_app\records\EmployeePayment;
 use yii_app\forms\EmployeePaymentSearch;
 use yii\web\Controller;
@@ -41,6 +43,8 @@ class EmployeePaymentController extends Controller
         $searchModel = new EmployeePaymentSearch();
         $dataProvider = $searchModel->search($this->request->queryParams);
 
+        $dataProvider->query->orderBy(['admin_id' => SORT_ASC]);
+
         return $this->render('index', [
             'searchModel' => $searchModel,
             'dataProvider' => $dataProvider,
@@ -55,8 +59,21 @@ class EmployeePaymentController extends Controller
      */
     public function actionView($id)
     {
+
+        $dataProvider = new ActiveDataProvider([
+            'query' => EmployeePayment::find()->where(['admin_id' => $id]),
+        ]);
+
+        // Получение данных сотрудника для заголовка
+        $admin = Admin::findOne($id);
+
+        if (!$admin) {
+            throw new NotFoundHttpException("Сотрудник не найден");
+        }
+
         return $this->render('view', [
-            'model' => $this->findModel($id),
+            'admin' => $admin,
+            'dataProvider' => $dataProvider,
         ]);
     }
 
@@ -65,13 +82,18 @@ class EmployeePaymentController extends Controller
      * If creation is successful, the browser will be redirected to the 'view' page.
      * @return string|\yii\web\Response
      */
-    public function actionCreate()
+    public function actionCreate($admin_id = null)
     {
         $model = new EmployeePayment();
 
+        // Если передан admin_id, устанавливаем его в модели
+        if ($admin_id !== null) {
+            $model->admin_id = $admin_id;
+        }
+
         if ($this->request->isPost) {
             if ($model->load($this->request->post()) && $model->save()) {
-                return $this->redirect(['index']);
+                return $this->redirect(['view', 'id' => $model->admin_id]);
             }
         } else {
             $model->loadDefaultValues();
@@ -95,7 +117,7 @@ class EmployeePaymentController extends Controller
         $model = $this->findModel($id);
 
         if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
-            return $this->redirect(['index']);
+            return $this->redirect(['view', 'id' => $model->admin_id]);
         }
 
         return $this->render('update', [
@@ -112,9 +134,13 @@ class EmployeePaymentController extends Controller
      */
     public function actionDelete($id)
     {
-        $this->findModel($id)->delete();
+        $model = $this->findModel($id);
+        $admin_id = $model->admin_id;
+
+        $model->delete();
 
-        return $this->redirect(['index']);
+        // Редирект на страницу просмотра сотрудника после удаления записи
+        return $this->redirect(['view', 'id' => $admin_id]);
     }
 
     /**
index 36e96c10459d4e313f2bf0060ead7b1c4587382d..3d060873ea7075851ebfad31a13948da0eca4990 100755 (executable)
@@ -41,10 +41,16 @@ class EmployeePaymentSearch extends EmployeePayment
      */
     public function search($params)
     {
-        $query = EmployeePayment::find();
+        $subQuery = EmployeePayment::find()
+            ->select(['MAX(id)'])
+            ->groupBy('admin_id');
+
+        $query = EmployeePayment::find()
+            ->where(['id' => $subQuery]);
 
         // add conditions that should always apply here
 
+
         $dataProvider = new ActiveDataProvider([
             'query' => $query,
         ]);
index a7b816a70215b7dd60b7e5f06517a3265d5e8da2..72b239dc73e50a9625ee97ecc2e00d85f819f12a 100755 (executable)
@@ -22,7 +22,10 @@ use yii\widgets\ActiveForm;
     ?>
     <?= $form->field($model, 'admin_id')->widget(Select2::classname(), [
         'data' => $adminsList,
-        'options' => ['placeholder' => 'Select a state ...'],
+        'options' => [
+            'placeholder' => 'Выберите сотрудника...',
+            'value' => $model->admin_id,  // Устанавливаем значение по умолчанию
+        ],
         'pluginOptions' => [
             'allowClear' => true
         ],
@@ -33,6 +36,7 @@ use yii\widgets\ActiveForm;
 
     <div class="form-group">
         <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+        <?= Html::a('Назад', ['view', 'id' => $model->admin_id], ['class' => 'btn btn-danger']) ?>
     </div>
 
     <?php ActiveForm::end(); ?>
index ac3f00cd3cd8716b0008a54a4dab58f4c1513ca8..f214265b4feb33605d49bfafe48464c7c0afa6d1 100755 (executable)
@@ -19,9 +19,9 @@ use yii\widgets\ActiveForm;
         ],
     ]); ?>
     <div class="row">
-        <div class="col-4">
-            <?= $form->field($model, 'id') ?>
-        </div>
+        <!--<div class="col-4">
+            <?/*= $form->field($model, 'id') */?>
+        </div>-->
         <div class="col-4">
             <?php
             $adminsWithGroup = \yii_app\records\Admin::find()->select(['name', 'id'])->indexBy('id')->orderBy('name' , SORT_DESC)->all();
@@ -46,26 +46,27 @@ use yii\widgets\ActiveForm;
             ]) ?>
         </div>
     </div>
-    <div class="row">
+    <!--<div class="row">
         <div class="col-3">
-            <?= $form->field($model, 'date') ?>
+            <?/*= $form->field($model, 'date') */?>
         </div>
         <div class="col-3">
-            <?= $form->field($model, 'monthly_salary') ?>
+            <?/*= $form->field($model, 'monthly_salary') */?>
         </div>
         <div class="col-3">
-            <?= $form->field($model, 'daily_payment') ?>
+            <?/*= $form->field($model, 'daily_payment') */?>
         </div>
         <div class="col-3">
-            <?= $form->field($model, 'creator_id')->dropDownList(\yii_app\records\AdminGroup::find()->select(['name', 'id'])->indexBy('id')->column(), [
+            <?/*= $form->field($model, 'creator_id')->dropDownList(\yii_app\records\AdminGroup::find()->select(['name', 'id'])->indexBy('id')->column(), [
                 'prompt' => '---',
-            ]) ?>
+            ]) */?>
         </div>
-    </div>
+    </div>-->
 
     <div class="form-group">
         <?= Html::submitButton('Найти', ['class' => 'btn btn-primary']) ?>
-        <?= Html::resetButton('Сбросить фильтры', ['class' => 'btn btn-outline-secondary']) ?>
+       <?/*= Html::resetButton('Сбросить фильтры', ['class' => 'btn btn-outline-secondary']) */?>
+        <?= Html::a('Сбросить фильтры', ['index'], ['class' => 'btn btn-outline-secondary']) ?>
     </div>
 
     <?php ActiveForm::end(); ?>
index 6be5ea1fa297d98e5170c3b519aa900213026885..f8bcc254b78a017f6ded57e631085e58e0d684d0 100755 (executable)
@@ -9,7 +9,7 @@ $this->title = 'Добавить запись оклада';
 $this->params['breadcrumbs'][] = ['label' => 'Оклады', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
 ?>
-<div class="employee-payment-create">
+<div class="employee-payment-create p-4">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
index 2c1d48728a68b4045ffce8cd687d127065636d4f..d6c3a869352773be14f8b92c51caf23605c130df 100755 (executable)
@@ -14,7 +14,7 @@ use yii_app\records\EmployeePayment;
 $this->title = 'Оклад и стоимость рабочего дня';
 $this->params['breadcrumbs'][] = $this->title;
 ?>
-<div class="employee-payment-index">
+<div class="employee-payment-index p-4">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
@@ -32,7 +32,7 @@ $this->params['breadcrumbs'][] = $this->title;
                 'label' => 'ID',
                 'format' => 'raw',
                 'value' => function($model) {
-                    return Html::a($model->id, ['employee-payment/view', 'id' => $model->admin_id]);
+                    return Html::a($model->admin_id, ['employee-payment/view', 'id' => $model->admin_id]);
                 }
             ],
             [
@@ -40,15 +40,15 @@ $this->params['breadcrumbs'][] = $this->title;
                 'label' => 'Сотрудник',
                 'format' => 'raw',
                 'value' => function($model) {
-                    return $model->admin ? Html::a(Html::encode($model->admin->name), ['employee/view', 'id' => $model->admin_id]) : null;
+                    return $model->admin ? Html::a(Html::encode($model->admin->name), ['employee-payment/view', 'id' => $model->admin_id]) : null;
                 }
             ],
 
             'adminGroup.name:text:Должность',
-            'date',
-            'monthly_salary',
-            'daily_payment',
-            'creator.name:text:Создавший правило',
+           // 'date',
+           // 'monthly_salary',
+           // 'daily_payment',
+          //  'creator.name:text:Создавший правило',
             [
                 'class' => ActionColumn::class,
                 'template' => '{view}', // Оставляем только кнопку "view"
@@ -64,6 +64,6 @@ $this->params['breadcrumbs'][] = $this->title;
 
     <?php Pjax::end(); ?>
 
-    <?php print_r($searchModel); ?>
+
 
 </div>
index 9ac2bbfa2258b57730423acb2bedf84594494763..09eed9d43b2ffaf9d5f3a1f5b3b4e6c1f451ba59 100755 (executable)
@@ -10,7 +10,7 @@ $this->params['breadcrumbs'][] = ['label' => 'Employee Payments', 'url' => ['ind
 $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
 $this->params['breadcrumbs'][] = 'Update';
 ?>
-<div class="employee-payment-update">
+<div class="employee-payment-update p-4">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
index 77da5dbeb4f82942a123a6d458f4360c45794fd5..a414b150908645772f213211d647916572e0e7ae 100755 (executable)
@@ -1,46 +1,55 @@
 <?php
 
 use yii\helpers\Html;
+use yii\grid\GridView;
 use yii\widgets\DetailView;
 
 /* @var $this yii\web\View */
-/* @var $model yii_app\records\EmployeePayment */
+/* @var $admin yii_app\records\Admin */
+/* @var $dataProvider yii\data\ActiveDataProvider */
 
-$this->title = $model->id;
+$this->title = $admin->name . ' - ' . $admin->adminGroup->name;
 $this->params['breadcrumbs'][] = ['label' => 'Оклады', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
-\yii\web\YiiAsset::register($this);
+//var_dump($this->params['breadcrumbs']);
 ?>
-<div class="employee-payment-view">
+<div class="employee-payment-view p-4">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
     <p>
-        <?= Html::a('Добавить запись', ['create'], ['class' => 'btn btn-success']) ?>
-    </p>
-
-    <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',
-            ],
-        ]) ?>
+        <?= Html::a('Добавить запись', ['create', 'admin_id' => $admin->id], ['class' => 'btn btn-success']) ?>
+        <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger']) ?>
     </p>
 
     <?= DetailView::widget([
-        'model' => $model,
+        'model' => $admin,
         'attributes' => [
-            'id',
-            'admin.name:text:Сотрудник',
+            'id:text:Admin ID',
+            'name:text:Сотрудник',
             'adminGroup.name:text:Должность',
+        ],
+    ]) ?>
+
+    <h2>Записи выплат</h2>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            'id',
             'date',
             'monthly_salary',
             'daily_payment',
             'creator.name:text:Правило создал',
+            [
+                'class' => 'yii\grid\ActionColumn',
+                'template' => ' {update} {delete}', // Оставляем все действия
+                'urlCreator' => function ($action, $model, $key, $index, $column) use ($admin) {
+                    return [$action, 'id' => $model->id, 'admin_id' => $admin->id];
+                }
+            ],
         ],
     ]) ?>
 
 </div>
+
index 713d64211159d6957129939d24ed30c830a050c3..543798ad84022d4ba905d698b494e60495445591 100755 (executable)
@@ -3,11 +3,17 @@
      * @var string $content rendered content
      * @var \yii\web\View $this
      */
-    global $_CONFIG;
+    global
+
+
+
+$_CONFIG;
 
 app\assets\CommonAsset::register($this);
 app\assets\CachemenutopAsset::register($this);
 app\assets\JQueryPluginsAsset::register($this); /** @TODO удалить после переписывания основного функционала */
+
+use yii\widgets\Breadcrumbs;
 ?>
 <?php $this->beginPage() ?>
 <!DOCTYPE html>
@@ -56,6 +62,9 @@ app\assets\JQueryPluginsAsset::register($this); /** @TODO удалить пос
                 </aside>
                 <div class="app-content main-content">
                     <?= $this->render('header.php'); ?>
+                    <?= Breadcrumbs::widget([
+                        'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
+                    ]) ?>
                     <?= $content ?>
                 </div>
             </div>