Skip to content

A free open source IT asset/license management system

Fixed #19870 and #19869 - small maintenance improvements

snipeaecfdfbcbcc5
diff --git a/_ide_helper_models.php b/_ide_helper_models.php
index 6998d5db2f..99ac2ab799 100644
--- a/_ide_helper_models.php
+++ b/_ide_helper_models.php
@@ -891,6 +891,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder<static>|CheckoutAcceptance onlyTrashed()
* @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance pending()
* @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance query()
+ * @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance visibleToCurrentUser()
* @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance whereAcceptedAt($value)
* @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance whereAlertOnResponseId($value)
* @method static \App\Models\Builders\CheckoutAcceptanceQueryBuilder<static>|CheckoutAcceptance whereAssignedToId($value)
@@ -1326,6 +1327,8 @@ namespace App\Models{
* @property-write mixed $status_id
* @property-write mixed $supplier_id
* @property-write mixed $warranty_months
+ * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $unconstrainedUsers
+ * @property-read int|null $unconstrained_users_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Actionlog> $uploads
* @property-read int|null $uploads_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $users
@@ -2233,6 +2236,11 @@ namespace App\Models{
* @property-read mixed $expires_formatted_date
* @property mixed $asset_id
* @property mixed $completion_date
+ * @property-read int|null $duration_in_days
+ * @property-read mixed|null $effective_completion_date
+ * @property-read bool $is_overdue
+ * @property-read string|null $progress_label
+ * @property-read int $progress_percent
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Actionlog> $history
* @property-read int|null $history_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Actionlog> $log
diff --git a/app/Http/Transformers/CalendarEventsTransformer.php b/app/Http/Transformers/CalendarEventsTransformer.php
index 6d74dc3738..bbc48f7f92 100644
--- a/app/Http/Transformers/CalendarEventsTransformer.php
+++ b/app/Http/Transformers/CalendarEventsTransformer.php
@@ -76,7 +76,7 @@ class CalendarEventsTransformer
'id' => $row->id,
'title' => $this->titleFor($source, $row->event_type),
'start' => $this->formatDate($row->start, $allDay),
- 'end' => $this->formatDate($row->end, $allDay),
+ 'end' => $this->formatDate($row->end, $allDay, isEnd: true),
'allDay' => $allDay,
'url' => $this->urlFor($source),
'color' => $this->colorFor($source),
@@ -93,8 +93,13 @@ class CalendarEventsTransformer
* Display name prefixed with the human-readable event-type label
* so a viewer can tell why a row is on the calendar ("Audit due:
* Laptop #7" vs. just "Laptop #7"). Presenter's name() is the
- * canonical Snipe-IT accessor; falls through to common attribute
+ * canonical Snipe-IT accessor, with a fallback to common attribute
* names for models without a presenter wired up yet.
+ *
+ * Source models can expose a `calendarTitlePrefix()` method to
+ * stamp a state marker at the front of the title (completed
+ * maintenances use "✓ ", for example). Returning null or an
+ * empty string leaves the title untouched.
*/
private function titleFor(Model $source, string $eventType): string
{
@@ -108,8 +113,11 @@ class CalendarEventsTransformer
$name ??= (string) ($source->display_name ?? $source->name ?? (class_basename($source).'#'.$source->getKey()));
$label = $this->eventTypeLabel($eventType);
+ $title = $label ? sprintf('%s: %s', $label, $name) : $name;
+
+ $prefix = method_exists($source, 'calendarTitlePrefix') ? (string) $source->calendarTitlePrefix() : '';
- return $label ? sprintf('%s: %s', $label, $name) : $name;
+ return $prefix.$title;
}
private function eventTypeLabel(string $eventType): string
@@ -152,8 +160,15 @@ class CalendarEventsTransformer
* not on DateTimeInterface). All-day events serialize as
* `YYYY-MM-DD` (no time component) so FullCalendar doesn't
* reinterpret them as UTC midnight in the browser's local zone.
+ *
+ * FullCalendar treats all-day `end` as EXCLUSIVE: an event with
+ * end=2026-10-15 renders only through 2026-10-14. Range events
+ * (maintenance, request reservations) therefore need end+1 so a
+ * same-day completion still paints on that day. Only applied
+ * when $isEnd is true so starts stay anchored on the day they
+ * actually begin.
*/
- private function formatDate(mixed $date, bool $allDay): ?string
+ private function formatDate(mixed $date, bool $allDay, bool $isEnd = false): ?string
{
if ($date === null || $date === '') {
return null;
@@ -163,6 +178,10 @@ class CalendarEventsTransformer
? $date
: ($date instanceof DateTimeInterface ? Carbon::instance($date) : Carbon::parse($date));
+ if ($allDay && $isEnd) {
+ $date = $date->copy()->addDay();
+ }
+
return $allDay ? $date->format('Y-m-d') : $date->toIso8601String();
}
diff --git a/app/Presenters/MaintenancesPresenter.php b/app/Presenters/MaintenancesPresenter.php
index bc6e48fd95..d14f37ed5c 100644
--- a/app/Presenters/MaintenancesPresenter.php
+++ b/app/Presenters/MaintenancesPresenter.php
@@ -10,11 +10,13 @@ namespace App\Presenters;
class MaintenancesPresenter extends Presenter
{
/**
- * Json Column Layout for bootstrap table
+ * Json Column Layout for bootstrap table. Pass fields to drop
+ * from the layout in $hide_fields.
*
+ * @param array<int, string> $hide_fields
* @return string
*/
- public static function dataTableLayout()
+ public static function dataTableLayout(array $hide_fields = [])
{
$layout = [
[
@@ -259,6 +261,13 @@ class MaintenancesPresenter extends Presenter
],
];
+ if ($hide_fields !== []) {
+ $layout = array_values(array_filter(
+ $layout,
+ fn(array $col) => !in_array($col['field'] ?? null, $hide_fields, true),
+ ));
+ }
+
return json_encode($layout);
}
diff --git a/database/migrations/2026_10_20_104519_backfill_calendar_events_for_completed_maintenances.php b/database/migrations/2026_10_20_104519_backfill_calendar_events_for_completed_maintenances.php
new file mode 100644
index 0000000000..8cd0829536
--- /dev/null
+++ b/database/migrations/2026_10_20_104519_backfill_calendar_events_for_completed_maintenances.php
@@ -0,0 +1,28 @@
+<?php
+
+use App\Models\Maintenance;
+use Illuminate\Database\Migrations\Migration;
+
+/**
+ * One-time backfill for #19870. This re-syncs every
+ * maintenance that has completed_at set so its
+ * calendar_events row picks up the actual completion end.
+ */
+return new class extends Migration
+{
+ public function up(): void
+ {
+ Maintenance::query()
+ ->whereNotNull('completed_at')
+ ->chunkById(500, function ($rows) {
+ foreach ($rows as $row) {
+ $row->forceSyncCalendarEvents();
+ }
+ });
+ }
+
+ public function down(): void
+ {
+ // no-op
+ }
+};
diff --git a/resources/views/blade/progressbar/index.blade.php b/resources/views/blade/progressbar/index.blade.php
index 27a23fe893..9f07a24230 100644
--- a/resources/views/blade/progressbar/index.blade.php
+++ b/resources/views/blade/progressbar/index.blade.php
@@ -5,10 +5,19 @@
'size' => 'sm',
'positive' => false,
'use_well' => 'true',
+ 'color' => null,
+ 'warning_icon' => false,
+ 'warning_label' => null,
])
<?php
-if ($percent < 25) {
+// Explicit color wins over the percentage-driven class so when
+// representing a terminal state (completed maintenance, cancelled
+// request) we can pin a success / muted color without faking the
+// percentage.
+if ($color !== null) {
+ $color_class = $color;
+} elseif ($percent < 25) {
$color_class = (!$positive ? 'info' : 'danger');
} elseif ($percent < 75) {
$color_class = (!$positive ? 'warning' : 'info');
@@ -24,7 +33,17 @@ if ($percent < 25) {
<div class="col-md-{{ $columns }}">
{!! ($use_well=='true') ? '<div class="well well-sm">' : '' !!}
<div class="progress-group">
- <span class="progress-text">{{ $text }}</span>
+ <span class="progress-text">
+ @if ($warning_icon)
+ {{-- Icon is aria-hidden via <x-icon>, so the sibling sr-only
+ span carries the semantic for screen readers. Caller
+ supplies warning_label with the context-specific string
+ (e.g. "Overdue") so the component stays generic. --}}
+ <x-icon type="warning" class="text-yellow" data-tooltip="true" title="{{ $warning_label }}"/>
+ <span class="sr-only">{{ $warning_label }}</span>
+ @endif
+ {{ $text }}
+ </span>
<span class="progress-number">
{{ $slot }}
<span class="text-muted">{{ round($percent) }}%</span>
diff --git a/resources/views/blade/table/maintenances.blade.php b/resources/views/blade/table/maintenances.blade.php
index baa247012b..d801bf16b0 100644
--- a/resources/views/blade/table/maintenances.blade.php
+++ b/resources/views/blade/table/maintenances.blade.php
@@ -5,6 +5,7 @@
'fixed_number' => null,
'table_header' => trans('general.maintenances'),
'export_filename' => 'export-maintenances-'.date('Y-m-d'),
+ 'hide_fields' => [],
])
@aware(['name'])
@@ -20,7 +21,7 @@
:fixed_number="$fixed_number"
buttons="maintenanceButtons"
api_url="{{ $route ?? route('api.maintenances.index') }}"
- :presenter="\App\Presenters\MaintenancesPresenter::dataTableLayout()"
+ :presenter="\App\Presenters\MaintenancesPresenter::dataTableLayout($hide_fields)"
:export_filename="$export_filename"
/>
diff --git a/resources/views/maintenances/index.blade.php b/resources/views/maintenances/index.blade.php
index 0fa273f36a..6053713ce2 100644
--- a/resources/views/maintenances/index.blade.php
+++ b/resources/views/maintenances/index.blade.php
@@ -22,6 +22,7 @@
<x-table.maintenances
name="maintenance"
:route="route('api.maintenances.index').'?completed='.request()->input('completed', 'false').'&upcoming_status='.request()->input('upcoming_status', '')"
+ :hide_fields="request('completed') === 'true' ? [] : ['completed_at', 'completed_by']"
/>
</x-box>
diff --git a/resources/views/maintenances/view.blade.php b/resources/views/maintenances/view.blade.php
index 14794e2cfe..ea0f884be1 100644
--- a/resources/views/maintenances/view.blade.php
+++ b/resources/views/maintenances/view.blade.php
@@ -94,8 +94,8 @@
</x-data-row>
<x-data-row :label="trans('admin/maintenances/form.asset_maintenance_time')" copy_what="time">
- @if ($maintenance->asset_maintenance_time)
- {{ $maintenance->asset_maintenance_time }} {{ trans('general.days') }}
+ @if ($maintenance->duration_in_days !== null)
+ {{ $maintenance->duration_in_days }} {{ trans('general.days') }}
@endif
</x-data-row>
@@ -151,34 +151,15 @@
<x-page-column class="col-md-4 col-sm-12">
<x-well class="well-sm" style="padding-left: 15px;">
- @php
-
- $startCarbon = $maintenance->start_date ? Carbon::parse($maintenance->start_date) : null;
- $endCarbon = $maintenance->expected_completion_date
- ? Carbon::parse($maintenance->expected_completion_date)
- : null;
-
- $maintenancePercent = 0;
- if ($startCarbon) {
- $progressLabel = App\Helpers\Helper::getFormattedDateObject($maintenance->start_date, 'date', false);
- if ($endCarbon) {
- $progressLabel .= ' - '.App\Helpers\Helper::getFormattedDateObject($maintenance->expected_completion_date, 'date', false);;
- // Completed: show how far through the total duration we are as of today
- $totalDays = max(1, $startCarbon->diffInDays($endCarbon));
- $elapsedDays = min($totalDays, $startCarbon->diffInDays(Carbon::now()));
- $maintenancePercent = min(100, max(0, ($elapsedDays / $totalDays) * 100));
- } else {
- // In progress: base on days elapsed since start_date relative to 30-day window
- $elapsedDays = $startCarbon->diffInDays(Carbon::now());
- $maintenancePercent = min(100, max(0, ($elapsedDays / 30) * 100));
- }
- }
- @endphp
-
-
- <x-progressbar use_well="false" columns="12" :text="$progressLabel" :percent="$maintenancePercent">
- </x-progressbar>
-
+ <x-progressbar
+ use_well="false"
+ columns="12"
+ :text="$maintenance->progress_label"
+ :percent="$maintenance->progress_percent"
+ :color="$maintenance->completed_at ? 'success' : null"
+ :warning_icon="$maintenance->is_overdue"
+ :warning_label="trans('admin/maintenances/general.overdue')"
+ />
</x-well>
</x-page-column>
<div class="clearfix"></div>