From: fomichev Date: Tue, 14 Jan 2025 15:11:19 +0000 (+0300) Subject: Убираем кнопку удалить если есть факт X-Git-Tag: 1.7~83^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c5ed58d73f01c38f769b9780f9a42e3795a5a952;p=erp24_rep%2Fyii-erp24%2F.git Убираем кнопку удалить если есть факт --- diff --git a/erp24/records/TimetablePlan.php b/erp24/records/TimetablePlan.php index 5fa6adba..b40c9ca1 100755 --- a/erp24/records/TimetablePlan.php +++ b/erp24/records/TimetablePlan.php @@ -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(); + } +} diff --git a/erp24/views/timetable/tabel_edit.php b/erp24/views/timetable/tabel_edit.php index 527395a7..528908db 100755 --- a/erp24/views/timetable/tabel_edit.php +++ b/erp24/views/timetable/tabel_edit.php @@ -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]); ?>
@@ -89,9 +92,27 @@ $groupId = (int) $session->get('group_id'); $numDay = Timetable::getCountDaysAllowEditShift($groupId); if (Timetable::getAllowEditShift($slot->date, $numDay)) { ?> - 'btn btn-primary']); ?> + session->hasFlash('error')): ?> +
+ session->getFlash('error') ?> +
+ + 'btn btn-primary']); ?> id) { ?> - id], ['data-role'=>'delete', 'class' => 'btn'])); ?> + andWhere(['plan_id' => $slot->id])->one())) { ?> + id]), + ['data-role'=>'delete','data-confirm' => 'Удалить?', 'class' => 'btn btn-danger'] + ); + ?> + +
+ Невозможно удалить запись плановой смены для которой существует факт смены. +
+ +

@@ -188,4 +209,4 @@ if (Timetable::getAllowEditShift($slot->date, $numDay)) { ]); ?>
- \ No newline at end of file +