namespace yii_app\records;
+use Yii;
+
/**
* План работы
* @property-read TimetableFact $fact
}
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();
+ }
+}
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">
$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>
]); ?>
</div>
-<?php endif; ?>
\ No newline at end of file
+<?php endif; ?>