]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Убираем кнопку удалить если есть факт
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 14 Jan 2025 15:11:19 +0000 (18:11 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 14 Jan 2025 15:11:19 +0000 (18:11 +0300)
erp24/records/TimetablePlan.php
erp24/views/timetable/tabel_edit.php

index 5fa6adba3ccb7bfd7bfab3cd9b3439f1fe120235..b40c9ca1912107224a6384f416b9c98cb99f3909 100755 (executable)
@@ -3,6 +3,8 @@ declare(strict_types=1);
 
 namespace yii_app\records;
 
+use Yii;
+
 /**
  * План работы
  * @property-read TimetableFact $fact
@@ -143,4 +145,16 @@ class TimetablePlan extends Timetable
         }
         return $this->fact->getDateTimeEnd() < $this->getDateTimeEnd();
     }
-}
\ No newline at end of file
+
+    public function softDelete()
+    {
+        $existingFact = TimetableFactModel::findOne(['plan_id' => $this->id]);
+//var_dump($existingFact); die();
+        if ($existingFact) {
+            Yii::$app->session->setFlash('error', 'Невозможно удалить запись плановой смены для которой существует факт смены.');
+            return false;
+        }
+
+        return parent::softDelete();
+    }
+}
index 527395a72eedad9d56e0c01c77631800b76ff3ca..528908dbc4e8e82911fb47c6d91370539028934f 100755 (executable)
@@ -9,9 +9,12 @@
 use yii\grid\ActionColumn;
 use yii\helpers\Html;
 use yii\helpers\ArrayHelper;
+use yii\helpers\Url;
 use yii_app\records\AdminGroup;
 use yii_app\records\Timetable;
+use yii_app\records\TimetableFactModel;
 
+$this->registerJsFile('/js/timetable/timetable-edit.js', ['position' => \yii\web\View::POS_END]);
 ?>
 <?php if ($success) { ?>
 <div class="alert-success">
@@ -89,9 +92,27 @@ $groupId = (int) $session->get('group_id');
 $numDay = Timetable::getCountDaysAllowEditShift($groupId);
 if (Timetable::getAllowEditShift($slot->date, $numDay)) {
     ?>
-    <?= \yii\helpers\Html::submitButton('Сохранить.', ['class' => 'btn btn-primary']); ?>
+    <?php if (Yii::$app->session->hasFlash('error')): ?>
+        <div class="alert alert-danger">
+            <?= Yii::$app->session->getFlash('error') ?>
+        </div>
+    <?php endif; ?>
+    <?= \yii\helpers\Html::submitButton('Сохранить', ['class' => 'btn btn-primary']); ?>
     <?php if ($slot->id) { ?>
-        <?= \yii\helpers\Html::a('Удалить', \yii\helpers\Url::to(['/timetable/edit_plan?delete&id=' . $slot->id], ['data-role'=>'delete', 'class' => 'btn'])); ?>
+        <?php if (empty(TimetableFactModel::find()->andWhere(['plan_id' => $slot->id])->one())) { ?>
+            <?=
+            \yii\helpers\Html::a(
+                'Удалить',
+                Url::to(['/timetable/edit_plan?delete&id=' . $slot->id]),
+                ['data-role'=>'delete','data-confirm' => 'Удалить?', 'class' => 'btn btn-danger']
+            );
+            ?>
+        <?php } else { ?>
+            <div class="alert alert-danger m-4">
+                Невозможно удалить запись плановой смены для которой существует факт смены.
+            </div>
+        <?php } ?>
+
         <?php if (in_array($_SESSION['group_id'], [1, 8]) && !empty($fact)) { /** @TODO Add RBAC */ ?>
             <br>
             <hr>
@@ -188,4 +209,4 @@ if (Timetable::getAllowEditShift($slot->date, $numDay)) {
 ]); ?>
 </div>
 
-<?php endif; ?>
\ No newline at end of file
+<?php endif; ?>