where('record_id', $id) ->where('column_name', $columnName) ->orderBy('created_at', 'DESC') ->get(); $weldLogEditInfo = null; $weldLogInfoMessages = []; $showWeldLogTimer = ($table === 'weld_logs' && $columnName === 'welding_date'); if ($showWeldLogTimer) { $latestWeldingDateComment = $comments->first(function ($comment) { return stripos($comment->comment ?? '', 'welding date set') !== false; }); $limitHours = (float) setting('weld_log_edit_time_limit'); $exceptLevelsRaw = setting('weld_log_edit_time_limit_except_levels'); $exceptLevels = $exceptLevelsRaw ? j($exceptLevelsRaw) : []; if (!is_array($exceptLevels)) { $exceptLevels = []; } $currentUserLevel = optional(u())->level; $isExcept = $currentUserLevel && in_array($currentUserLevel, $exceptLevels); if ($isExcept) { $weldLogInfoMessages[] = "Your level is excluded from the weld log edit time limit."; } if ($latestWeldingDateComment && $limitHours > 0) { $commentTime = Carbon::parse($latestWeldingDateComment->created_at); $expiresAt = $commentTime->copy()->addHours($limitHours); $now = Carbon::now(); $totalSeconds = (int) ($limitHours * 3600); $secondsLeft = $now->diffInSeconds($expiresAt, false); $isEditable = $secondsLeft > 0; $secondsLeft = max(0, $secondsLeft); $elapsedSeconds = max(0, $totalSeconds - $secondsLeft); $percent = $totalSeconds > 0 ? round(($elapsedSeconds / $totalSeconds) * 100, 1) : 100; $interval = CarbonInterval::seconds($secondsLeft)->cascade(); $weldLogEditInfo = [ 'isEditable' => $isEditable, 'secondsLeft' => $secondsLeft, 'humanLeft' => $isEditable ? $interval->forHumans(['short' => true, 'parts' => 2]) : '0 minutes', 'limitHours' => $limitHours, 'percent' => min(100, max(0, $percent)), 'expiresAt' => $expiresAt, 'commentTime' => $commentTime, 'exceptLevels' => $exceptLevels, ]; } elseif ($limitHours > 0) { $weldLogInfoMessages[] = "No recent welding date change was found to calculate the countdown."; } } // Convert comments to JSON for DataGrid $commentsJson = json_encode($comments); // Convert users to a lookup object for DataGrid $usersLookup = []; foreach ($users as $user) { $usersLookup[$user->id] = $user->name; } $usersJson = json_encode($usersLookup); if($comments->count() > 0 || true) { ?>
Status:
Remaining Time: (limit: hours)
Expires At: format('d.m.Y H:i'); ?>
Except Levels:
%
Info:
{{e2($table)}} / {{e2($id)}} / {{e2($columnName)}} {{e2("Add Comment")}}
@csrf
{{e2("Comments History")}}
{{e2("No Comments Found")}}