$timetableWorkbot->save();
- return (bool)$timetable->softDelete();
+ return (bool)$timetable->softDelete($removed_by);
}
return false;
}
public function getCheckInCount() {
return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count();
}
-}
\ No newline at end of file
+
+ public function softDelete($deleted_by = null)
+ {
+ $existingFact = TimetableFactModel::findOne(['plan_id' => $this->id]);
+
+ if ($existingFact) {
+ return false;
+ }
+
+ return parent::softDelete($deleted_by);
+ }
+
+}
return $this->fact->getDateTimeEnd() < $this->getDateTimeEnd();
}
- public function softDelete()
+ public function softDelete($deleted_by = null)
{
$existingFact = TimetableFactModel::findOne(['plan_id' => $this->id]);
-//var_dump($existingFact); die();
+
if ($existingFact) {
Yii::$app->session->setFlash('error', 'Невозможно удалить запись плановой смены для которой существует факт смены.');
return false;
}
- return parent::softDelete();
+ return parent::softDelete($deleted_by);
}
}
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
+use yii_app\traits\SoftDeleteTrait;
/**
* Табель сотрудников
*/
class TimetableV3 extends ActiveRecord
{
+ use SoftDeleteTrait;
const STATUS_PENDING = 0;
const STATUS_VERIFIED = 1;
{
return $this->hasOne(Shift::class, ['id' => 'shift_id']);
}
-}
\ No newline at end of file
+
+ public static function hasSoftDelete(): bool
+ {
+ return true;
+ }
+
+ public static function find()
+ {
+ $query = parent::find();
+ if (static::hasSoftDelete()) {
+ $query->andWhere(['timetable.active' => 1]);
+ }
+ return $query;
+ }
+}
/**
* Удаление записи (soft delete).
*/
- public function softDelete()
+ public function softDelete($deleted_by = null)
{
$admin = Yii::$app->user->identity;
+ $adminId = $deleted_by ?? $admin->id;
$this->active = 0;
- $this->deleted_by = $admin->id;
+ $this->deleted_by = $adminId;
$this->deleted_at = date('Y-m-d H:i:s');
return $this->save(false, ['active', 'deleted_by', 'deleted_at']);
}