QM: Wiedervorlage und Lesebestätigung, Platzhalter für Profilbilder (0.21.0)
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8701b6d1b8
commit
4d855c8a74
213 changed files with 1729 additions and 515 deletions
118
plugins-core/qm/src/Acknowledgements.php
Normal file
118
plugins-core/qm/src/Acknowledgements.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Qm;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inhaus\Plugins\Qm\Models\QmEntry;
|
||||
|
||||
/**
|
||||
* Lesebestätigungen: Wer ein Dokument mit „Lesebestätigung“ sehen darf, bestätigt
|
||||
* die aktuelle Fassung. Eine neue Fassung braucht eine neue Bestätigung.
|
||||
*/
|
||||
class Acknowledgements
|
||||
{
|
||||
public function __construct(private readonly QmTree $tree, private readonly QmAccess $access) {}
|
||||
|
||||
/**
|
||||
* Bestätigungen der Person zu den Einträgen: Eintrag => bestätigt am (nur für die aktuelle Fassung).
|
||||
*
|
||||
* @param iterable<QmEntry> $entries
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function stateFor(iterable $entries, User $user): array
|
||||
{
|
||||
$entries = collect($entries)->filter(fn (QmEntry $e) => $e->requires_acknowledgement);
|
||||
|
||||
if ($entries->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = DB::table('qm_acknowledgements')->where('user_id', $user->id)->whereIn('entry_id', $entries->pluck('id'))->get()->keyBy('entry_id');
|
||||
$state = [];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$row = $rows[$entry->id] ?? null;
|
||||
|
||||
if ($row && (int) $row->file_id === (int) $entry->currentFileId()) {
|
||||
$state[$entry->id] = (string) $row->acknowledged_at;
|
||||
}
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
public function acknowledge(QmEntry $entry, User $user): void
|
||||
{
|
||||
DB::table('qm_acknowledgements')->updateOrInsert(
|
||||
['entry_id' => $entry->id, 'user_id' => $user->id],
|
||||
['file_id' => $entry->currentFileId(), 'acknowledged_at' => now()],
|
||||
);
|
||||
|
||||
Audit::log('qm.acknowledged', ['entry' => $entry->id, 'title' => $entry->title]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Noch zu bestätigende Dokumente der Person.
|
||||
*
|
||||
* @return Collection<int, QmEntry>
|
||||
*/
|
||||
public function outstanding(User $user): Collection
|
||||
{
|
||||
if (! $this->access->allows($user)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$entries = QmEntry::query()
|
||||
->where('requires_acknowledgement', true)
|
||||
->whereIn('folder_id', $this->tree->visibleIds($user) ?: [0])
|
||||
->with(['readingFile', 'editableFile'])
|
||||
->orderBy('title')
|
||||
->get();
|
||||
|
||||
$done = $this->stateFor($entries, $user);
|
||||
|
||||
return $entries->reject(fn (QmEntry $entry) => isset($done[$entry->id]) || ! $entry->currentFileId())->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Auswertung für das QM-Team: wer hat die aktuelle Fassung bestätigt, wer nicht.
|
||||
*
|
||||
* @return array{confirmed: list<array<string, mixed>>, missing: list<array<string, mixed>>}
|
||||
*/
|
||||
public function report(QmEntry $entry): array
|
||||
{
|
||||
$fileId = $entry->currentFileId();
|
||||
$category = $this->tree->categoryId($entry->folder_id);
|
||||
|
||||
// Alle aktiven Personen, die den Ordner sehen dürfen (Zielgruppe der Kategorie, Rollen-Ausschluss des Moduls)
|
||||
$excluded = $this->access->excludedRoles();
|
||||
$rules = $category !== null ? Audiences::get('qm_category', $category) : [];
|
||||
$include = array_filter(array_intersect_key($rules, array_flip(['role', 'department', 'location'])));
|
||||
$people = User::query()->where('is_active', true)
|
||||
->when($include !== [], fn (Builder $q) => $q->where(fn (Builder $q) => $q
|
||||
->whereHas('roles', fn (Builder $r) => $r->whereIn('roles.id', $include['role'] ?? [0]))
|
||||
->orWhereIn('department', $include['department'] ?? [])
|
||||
->orWhereIn('location', $include['location'] ?? [])))
|
||||
->when(filled($rules['exclude_role'] ?? []), fn (Builder $q) => $q->whereDoesntHave('roles', fn (Builder $r) => $r->whereIn('roles.id', $rules['exclude_role'])))
|
||||
// Rollen-Ausschluss des Moduls gilt nicht für das QM-Team
|
||||
->when($excluded !== [], fn (Builder $q) => $q->where(fn (Builder $q) => $q->whereDoesntHave('roles', fn (Builder $r) => $r->whereIn('roles.id', $excluded))
|
||||
->orWhereHas('roles.grants', fn (Builder $g) => $g->whereIn('ability', ['qm.manage', '*']))))
|
||||
->orderBy('last_name')->orderBy('first_name')
|
||||
->get(['id', 'name', 'first_name', 'last_name', 'department', 'job_title', 'avatar_path']);
|
||||
|
||||
$acks = DB::table('qm_acknowledgements')->where('entry_id', $entry->id)->where('file_id', $fileId)->pluck('acknowledged_at', 'user_id');
|
||||
$row = fn (User $u) => ['id' => $u->id, 'name' => $u->name, 'department' => $u->department, 'job_title' => $u->job_title, 'initials' => $u->initials, 'avatar_url' => $u->avatarUrl(96)];
|
||||
|
||||
[$confirmed, $missing] = $people->partition(fn (User $u) => isset($acks[$u->id]));
|
||||
|
||||
return [
|
||||
'confirmed' => $confirmed->map(fn (User $u) => [...$row($u), 'acknowledged_at' => (string) $acks[$u->id]])->sortByDesc('acknowledged_at')->values()->all(),
|
||||
'missing' => $missing->map($row)->values()->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Support\Audit;
|
||||
use App\Support\RichText;
|
||||
use App\Support\Settings;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -14,6 +15,7 @@ use Illuminate\Support\Facades\Storage;
|
|||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Qm\Acknowledgements;
|
||||
use Inhaus\Plugins\Qm\Library;
|
||||
use Inhaus\Plugins\Qm\Models\QmEntry;
|
||||
use Inhaus\Plugins\Qm\Models\QmFile;
|
||||
|
|
@ -21,6 +23,7 @@ use Inhaus\Plugins\Qm\Models\QmFolder;
|
|||
use Inhaus\Plugins\Qm\Presenter;
|
||||
use Inhaus\Plugins\Qm\QmAccess;
|
||||
use Inhaus\Plugins\Qm\QmTree;
|
||||
use Inhaus\Plugins\Qm\Reviews;
|
||||
use Inhaus\Plugins\Qm\Search;
|
||||
use Symfony\Component\HttpFoundation\Response as HttpResponse;
|
||||
|
||||
|
|
@ -49,16 +52,85 @@ class QmController extends Controller
|
|||
])->values(),
|
||||
'canManage' => $this->access->canManage($request->user()),
|
||||
'adminUrl' => $this->access->canManage($request->user()) ? url('/admin/qm-ordner') : null,
|
||||
'toAcknowledge' => app(Acknowledgements::class)->outstanding($request->user())->map(fn (QmEntry $entry) => $this->presenter->entry($entry, withFolder: true))->values(),
|
||||
'reviews' => app(Reviews::class)->canSee($request->user()) ? ['open' => app(Reviews::class)->openCount($request->user()), 'url' => route('qm.reviews')] : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wiedervorlagen: alle Termine (QM-Team) bzw. die eigenen (Verantwortliche).
|
||||
*/
|
||||
public function reviews(Request $request, Reviews $reviews): Response
|
||||
{
|
||||
abort_unless($reviews->canSee($request->user()), 403);
|
||||
|
||||
return Inertia::render('qm::Reviews', [
|
||||
'entries' => $reviews->list($request->user())->map(fn (QmEntry $entry) => [
|
||||
...$this->presenter->entry($entry, withFolder: true),
|
||||
'reviewer' => $entry->reviewer?->name,
|
||||
'can_complete' => $reviews->canComplete($entry, $request->user()),
|
||||
])->values(),
|
||||
'intervals' => Reviews::INTERVALS,
|
||||
'leadDays' => Reviews::LEAD_DAYS,
|
||||
]);
|
||||
}
|
||||
|
||||
public function completeReview(Request $request, QmEntry $entry, Reviews $reviews): RedirectResponse
|
||||
{
|
||||
abort_unless($reviews->canComplete($entry, $request->user()), 403);
|
||||
$reviews->complete($entry, $request->user());
|
||||
|
||||
return back()->with('status', $entry->review_due_at
|
||||
? 'Als geprüft vermerkt – nächste Prüfung am '.$entry->review_due_at->format('d.m.Y').'.'
|
||||
: 'Als geprüft vermerkt.');
|
||||
}
|
||||
|
||||
public function acknowledge(Request $request, QmEntry $entry, Acknowledgements $acknowledgements): RedirectResponse
|
||||
{
|
||||
abort_unless($entry->requires_acknowledgement && $this->tree->isVisible($entry->folder_id, $request->user()), 404);
|
||||
$acknowledgements->acknowledge($entry, $request->user());
|
||||
|
||||
return back()->with('status', 'Danke – Ihre Lesebestätigung ist gespeichert.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Auswertung der Lesebestätigungen (QM-Team), als JSON oder CSV.
|
||||
*/
|
||||
public function acknowledgements(Request $request, QmEntry $entry, Acknowledgements $acknowledgements): JsonResponse|HttpResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$report = $acknowledgements->report($entry);
|
||||
|
||||
if ($request->query('format') === 'csv') {
|
||||
$rows = [['Name', 'Abteilung', 'Funktion', 'Status', 'Bestätigt am']];
|
||||
|
||||
foreach ($report['confirmed'] as $p) {
|
||||
$rows[] = [$p['name'], $p['department'], $p['job_title'], 'bestätigt', Carbon::parse($p['acknowledged_at'])->format('d.m.Y H:i')];
|
||||
}
|
||||
|
||||
foreach ($report['missing'] as $p) {
|
||||
$rows[] = [$p['name'], $p['department'], $p['job_title'], 'offen', ''];
|
||||
}
|
||||
|
||||
$csv = "\u{FEFF}".collect($rows)->map(fn (array $row) => implode(';', array_map(fn ($v) => '"'.str_replace('"', '""', (string) $v).'"', $row)))->implode("\r\n");
|
||||
|
||||
return response($csv, 200, [
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
'Content-Disposition' => 'attachment; filename="lesebestaetigungen-'.$entry->id.'.csv"',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json($report);
|
||||
}
|
||||
|
||||
public function folder(Request $request, QmFolder $folder): Response
|
||||
{
|
||||
abort_unless($this->tree->isVisible($folder->id, $request->user()), 404);
|
||||
|
||||
$counts = $this->entryCounts();
|
||||
$canManage = $this->access->canManage($request->user());
|
||||
$entries = $folder->entries()->with(['readingFile', 'editableFile'])->orderBy('sort')->orderBy('title')->get();
|
||||
$entries = $folder->entries()->with(['readingFile', 'editableFile', 'responsible'])->orderBy('sort')->orderBy('title')->get();
|
||||
$acks = app(Acknowledgements::class)->stateFor($entries, $request->user());
|
||||
$node = $this->tree->folder($folder->id);
|
||||
|
||||
return Inertia::render('qm::Folder', [
|
||||
|
|
@ -72,7 +144,7 @@ class QmController extends Controller
|
|||
],
|
||||
'breadcrumbs' => array_map(fn (array $f) => ['id' => $f['id'], 'name' => $f['name'], 'color' => $f['color']], array_slice($this->tree->path($folder->id), 0, -1)),
|
||||
'children' => array_map(fn (int $id) => $this->presenter->tile($id, $counts), $this->tree->childIds($folder->id)),
|
||||
'entries' => $entries->map(fn (QmEntry $entry) => $this->presenter->entry($entry)),
|
||||
'entries' => $entries->map(fn (QmEntry $entry) => [...$this->presenter->entry($entry), 'acknowledged_at' => $acks[$entry->id] ?? null]),
|
||||
'canManage' => $canManage,
|
||||
'forms' => $canManage ? $this->formOptions() : [],
|
||||
'maxUploadMb' => (int) floor(min(Library::MAX_KB / 1024, self::phpUploadLimitMb())),
|
||||
|
|
@ -110,7 +182,7 @@ class QmController extends Controller
|
|||
}
|
||||
|
||||
return Inertia::render('qm::Viewer', [
|
||||
'entry' => $this->presenter->entry($entry, withFolder: true),
|
||||
'entry' => [...$this->presenter->entry($entry, withFolder: true), 'acknowledged_at' => app(Acknowledgements::class)->stateFor([$entry], $request->user())[$entry->id] ?? null],
|
||||
'file' => ['url' => $file->url(inline: true), 'kind' => $file->mime === 'application/pdf' ? 'pdf' : 'image', 'name' => $file->name],
|
||||
'query' => (string) $request->query('suche', ''),
|
||||
]);
|
||||
|
|
@ -206,9 +278,14 @@ class QmController extends Controller
|
|||
'form_id' => [Rule::requiredIf($type === QmEntry::FORM), 'nullable', 'integer', Rule::exists('forms', 'id')],
|
||||
'reading' => [...$fileRule, Rule::requiredIf($type === QmEntry::FILE && ! $entry && ! $request->hasFile('editable'))],
|
||||
'editable' => $fileRule,
|
||||
'review_due_at' => ['nullable', 'date'],
|
||||
'review_interval_months' => ['nullable', 'integer', Rule::in(array_keys(Reviews::INTERVALS))],
|
||||
'responsible_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'requires_acknowledgement' => ['nullable', 'boolean'],
|
||||
], ['url.regex' => 'Bitte eine Adresse angeben, die mit https:// oder / beginnt.', 'reading.required' => 'Bitte eine Datei auswählen.'], [
|
||||
'title' => 'Titel', 'version' => 'Version', 'valid_from' => 'Stand', 'url' => 'Adresse', 'form_id' => 'Formular',
|
||||
'reading' => 'Datei', 'editable' => 'Bearbeitbare Vorlage',
|
||||
'reading' => 'Datei', 'editable' => 'Bearbeitbare Vorlage', 'review_due_at' => 'Nächste Prüfung',
|
||||
'review_interval_months' => 'Prüfintervall', 'responsible_id' => 'Verantwortlich',
|
||||
]) + ['type' => $type];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,14 @@ class Library
|
|||
public function update(QmEntry $entry, array $data, ?UploadedFile $reading, ?UploadedFile $editable, bool $removeEditable, User $user): QmEntry
|
||||
{
|
||||
return DB::transaction(function () use ($entry, $data, $reading, $editable, $removeEditable, $user) {
|
||||
$entry->update([...$this->attributes([...$data, 'type' => $entry->type]), 'updated_by' => $user->id]);
|
||||
$entry->fill([...$this->attributes([...$data, 'type' => $entry->type]), 'updated_by' => $user->id]);
|
||||
|
||||
// Neuer Prüftermin oder andere Verantwortliche → erneut erinnern
|
||||
if ($entry->isDirty(['review_due_at', 'responsible_id'])) {
|
||||
$entry->review_notified_at = null;
|
||||
}
|
||||
|
||||
$entry->save();
|
||||
|
||||
if ($entry->type !== QmEntry::FILE) {
|
||||
return $entry;
|
||||
|
|
@ -89,6 +96,10 @@ class Library
|
|||
'valid_from' => filled($data['valid_from'] ?? null) ? Carbon::parse($data['valid_from'])->toDateString() : now()->toDateString(),
|
||||
'url' => $type === QmEntry::LINK ? trim((string) $data['url']) : null,
|
||||
'form_id' => $type === QmEntry::FORM ? (int) $data['form_id'] : null,
|
||||
'review_due_at' => filled($data['review_due_at'] ?? null) ? Carbon::parse($data['review_due_at'])->toDateString() : null,
|
||||
'review_interval_months' => filled($data['review_interval_months'] ?? null) ? (int) $data['review_interval_months'] : null,
|
||||
'responsible_id' => filled($data['responsible_id'] ?? null) ? (int) $data['responsible_id'] : null,
|
||||
'requires_acknowledgement' => (bool) ($data['requires_acknowledgement'] ?? false),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Inhaus\Plugins\Qm\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
|
@ -12,7 +13,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
|
|||
* Ein Eintrag in einem QM-Ordner: Datei (mit Lesefassung und optional bearbeitbarer
|
||||
* Vorlage), Link oder Online-Formular. „Stand“ = valid_from.
|
||||
*/
|
||||
#[Fillable(['folder_id', 'type', 'title', 'description', 'version', 'valid_from', 'url', 'form_id', 'sort', 'created_by', 'updated_by'])]
|
||||
#[Fillable(['folder_id', 'type', 'title', 'description', 'version', 'valid_from', 'url', 'form_id', 'sort', 'created_by', 'updated_by',
|
||||
'review_due_at', 'review_interval_months', 'responsible_id', 'requires_acknowledgement', 'reviewed_at', 'reviewed_by', 'review_notified_at'])]
|
||||
class QmEntry extends Model
|
||||
{
|
||||
public const FILE = 'file';
|
||||
|
|
@ -29,7 +31,7 @@ class QmEntry extends Model
|
|||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['valid_from' => 'date', 'review_due_at' => 'date', 'requires_acknowledgement' => 'boolean'];
|
||||
return ['valid_from' => 'date', 'review_due_at' => 'date', 'requires_acknowledgement' => 'boolean', 'reviewed_at' => 'datetime', 'review_notified_at' => 'datetime', 'review_interval_months' => 'integer'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +42,33 @@ class QmEntry extends Model
|
|||
return $this->belongsTo(QmFolder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function responsible(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'responsible_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function reviewer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'reviewed_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktuelle Fassung, auf die sich eine Lesebestätigung bezieht (Lesefassung, sonst Vorlage).
|
||||
*/
|
||||
public function currentFileId(): ?int
|
||||
{
|
||||
$file = $this->relationLoaded('readingFile') ? $this->readingFile : $this->readingFile()->first();
|
||||
$file ??= $this->relationLoaded('editableFile') ? $this->editableFile : $this->editableFile()->first();
|
||||
|
||||
return $file?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<QmFile, $this>
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -83,6 +83,14 @@ class Presenter
|
|||
'url' => $entry->url,
|
||||
'form_id' => $entry->form_id,
|
||||
'folder' => $withFolder ? $this->folderLabel($entry->folder_id) : null,
|
||||
'requires_acknowledgement' => (bool) $entry->requires_acknowledgement,
|
||||
'review' => [
|
||||
'due_at' => $entry->review_due_at?->toDateString(),
|
||||
'state' => Reviews::state($entry),
|
||||
'interval_months' => $entry->review_interval_months,
|
||||
'responsible' => $entry->responsible_id ? ['id' => $entry->responsible_id, 'name' => $entry->responsible?->name] : null,
|
||||
'reviewed_at' => $entry->reviewed_at?->toIso8601String(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,19 @@ class QmAccess
|
|||
return true;
|
||||
}
|
||||
|
||||
$excluded = array_map('intval', (array) $this->settings->get(self::EXCLUDED_ROLES, []));
|
||||
$excluded = $this->excludedRoles();
|
||||
|
||||
return $excluded === [] || ! $user->roles()->whereIn('roles.id', $excluded)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function excludedRoles(): array
|
||||
{
|
||||
return array_values(array_map('intval', (array) $this->settings->get(self::EXCLUDED_ROLES, [])));
|
||||
}
|
||||
|
||||
public function canManage(?User $user): bool
|
||||
{
|
||||
return (bool) $user?->can('qm.manage');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Inhaus\Plugins\Qm;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Models\User;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Search\GlobalSearch;
|
||||
|
|
@ -18,13 +19,23 @@ class QmPlugin extends Plugin
|
|||
{
|
||||
$this->app->make(GlobalSearch::class)->add('qm', 'Qualitätsmanagement', 'shield-check', fn (...$args) => app(QmSearch::class)(...$args), sort: 50);
|
||||
|
||||
foreach ([QmTree::class, QmAccess::class, Presenter::class, Search::class, Library::class, Indexer::class, TextExtractor::class, Ocr::class] as $class) {
|
||||
foreach ([QmTree::class, QmAccess::class, Presenter::class, Search::class, Library::class, Reviews::class, Acknowledgements::class, Indexer::class, TextExtractor::class, Ocr::class] as $class) {
|
||||
$this->app->singleton($class);
|
||||
}
|
||||
|
||||
$this->app->make(Navigation::class)->add('qm', 'Qualitätsmanagement', '/qm', active: 'qm.*', sort: 55,
|
||||
visible: fn (User $user) => $this->app->make(QmAccess::class)->allows($user));
|
||||
|
||||
// Startseite: noch zu bestätigende QM-Dokumente (nur wenn es welche gibt)
|
||||
$this->app->make(Widgets::class)->add('qm.acknowledgements', 'qm::Acknowledgements', 'aside', sort: 15, label: 'QM: Lesebestätigungen',
|
||||
props: function (User $user) {
|
||||
$open = $this->app->make(Acknowledgements::class)->outstanding($user);
|
||||
|
||||
return $open->isEmpty() ? null : ['entries' => $open->take(5)->map(fn ($entry) => [
|
||||
'id' => $entry->id, 'title' => $entry->title, 'url' => route('qm.view', $entry),
|
||||
])->values(), 'total' => $open->count(), 'url' => route('qm.index').'#bestaetigen'];
|
||||
});
|
||||
|
||||
$abilities = $this->app->make(Abilities::class);
|
||||
$abilities->define('qm.manage', 'Qualitätsmanagement pflegen (Ordner, Dokumente, Einstellungen)', 'Qualitätsmanagement');
|
||||
$abilities->resourceType('qm_category', 'QM-Kategorie', fn () => QmCategory::query()->orderBy('sort')->pluck('name', 'id')->all());
|
||||
|
|
@ -35,5 +46,9 @@ class QmPlugin extends Plugin
|
|||
// Eingescannte PDFs per Texterkennung durchsuchbar machen (nur wenn eingerichtet).
|
||||
Schedule::call(fn () => $this->app->make(Indexer::class)->processOcr())
|
||||
->everyTenMinutes()->name('qm-ocr')->withoutOverlapping(30);
|
||||
|
||||
// Wiedervorlage: fällige Prüfungen melden
|
||||
Schedule::call(fn () => $this->app->make(Reviews::class)->notifyDue())
|
||||
->dailyAt('07:00')->name('qm-reviews')->withoutOverlapping(30);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
119
plugins-core/qm/src/Reviews.php
Normal file
119
plugins-core/qm/src/Reviews.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Qm;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Inhaus\Plugins\Qm\Models\QmEntry;
|
||||
|
||||
/**
|
||||
* Wiedervorlage: Dokumente, die zu einem Termin geprüft werden müssen.
|
||||
* Die verantwortliche Person (sonst wer den Eintrag angelegt hat) wird
|
||||
* LEAD_DAYS Tage vorher im Portal benachrichtigt.
|
||||
*/
|
||||
class Reviews
|
||||
{
|
||||
public const LEAD_DAYS = 14;
|
||||
|
||||
public const INTERVALS = [6 => 'Alle 6 Monate', 12 => 'Jährlich', 24 => 'Alle 2 Jahre', 36 => 'Alle 3 Jahre'];
|
||||
|
||||
public function __construct(private readonly QmAccess $access) {}
|
||||
|
||||
/** Status eines Termins: overdue | due (innerhalb der Vorlaufzeit) | planned | null */
|
||||
public static function state(QmEntry $entry): ?string
|
||||
{
|
||||
if (! $entry->review_due_at) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$entry->review_due_at->isBefore(today()) => 'overdue',
|
||||
$entry->review_due_at->isBefore(today()->addDays(self::LEAD_DAYS + 1)) => 'due',
|
||||
default => 'planned',
|
||||
};
|
||||
}
|
||||
|
||||
public function canSee(?User $user): bool
|
||||
{
|
||||
return $user && ($this->access->canManage($user) || QmEntry::query()->where('responsible_id', $user->id)->whereNotNull('review_due_at')->exists());
|
||||
}
|
||||
|
||||
public function canComplete(QmEntry $entry, ?User $user): bool
|
||||
{
|
||||
return $user && ($this->access->canManage($user) || $entry->responsible_id === $user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Termine (QM-Team) bzw. die eigenen (Verantwortliche), fällige zuerst.
|
||||
*
|
||||
* @return Collection<int, QmEntry>
|
||||
*/
|
||||
public function list(User $user): Collection
|
||||
{
|
||||
return QmEntry::query()
|
||||
->whereNotNull('review_due_at')
|
||||
->when(! $this->access->canManage($user), fn (Builder $q) => $q->where('responsible_id', $user->id))
|
||||
->with(['responsible', 'reviewer', 'readingFile', 'editableFile'])
|
||||
->orderBy('review_due_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
/** Anzahl überfälliger und bald fälliger Termine für die Person */
|
||||
public function openCount(User $user): int
|
||||
{
|
||||
return QmEntry::query()
|
||||
->whereNotNull('review_due_at')
|
||||
->where('review_due_at', '<=', today()->addDays(self::LEAD_DAYS))
|
||||
->when(! $this->access->canManage($user), fn (Builder $q) => $q->where('responsible_id', $user->id))
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüfung erledigt: nächster Termin nach Intervall (ohne Intervall: keiner).
|
||||
*/
|
||||
public function complete(QmEntry $entry, User $user): void
|
||||
{
|
||||
$entry->forceFill([
|
||||
'reviewed_at' => now(),
|
||||
'reviewed_by' => $user->id,
|
||||
'review_due_at' => $entry->review_interval_months ? today()->addMonthsNoOverflow($entry->review_interval_months) : null,
|
||||
'review_notified_at' => null,
|
||||
])->save();
|
||||
|
||||
Audit::log('qm.entry_reviewed', ['entry' => $entry->id, 'title' => $entry->title, 'next' => $entry->review_due_at?->toDateString()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Täglich: fällige Termine melden (einmal je Termin).
|
||||
*/
|
||||
public function notifyDue(): int
|
||||
{
|
||||
$entries = QmEntry::query()
|
||||
->whereNotNull('review_due_at')
|
||||
->whereNull('review_notified_at')
|
||||
->where('review_due_at', '<=', today()->addDays(self::LEAD_DAYS))
|
||||
->with(['responsible', 'folder'])
|
||||
->get();
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$recipient = $entry->responsible ?? User::query()->find($entry->created_by);
|
||||
|
||||
if ($recipient?->is_active) {
|
||||
$overdue = $entry->review_due_at->isBefore(today());
|
||||
$recipient->notify(new PortalNotification(
|
||||
$overdue ? 'QM-Prüfung überfällig' : 'QM-Prüfung steht an',
|
||||
'„'.$entry->title.'“ – fällig am '.$entry->review_due_at->format('d.m.Y').'.',
|
||||
route('qm.reviews'),
|
||||
'calendar-clock',
|
||||
));
|
||||
}
|
||||
|
||||
$entry->forceFill(['review_notified_at' => now()])->save();
|
||||
}
|
||||
|
||||
return $entries->count();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue