From 6d55d782806c9660e9e65dc5250faacb5d0033ed Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 9 Oct 2023 16:13:41 +0100 Subject: [PATCH] Set resend acceptance to POST Signed-off-by: snipe --- app/Http/Controllers/ReportsController.php | 16 +++++++++++++--- .../views/reports/unaccepted_assets.blade.php | 16 ++++++++++++++-- routes/web.php | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index bacc27f4238a..4873c7f2a5d3 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1043,27 +1043,37 @@ public function getAssetAcceptanceReport($deleted = false) * @throws \Illuminate\Auth\Access\AuthorizationException * @version v1.0 */ - public function sentAssetAcceptanceReminder($acceptanceId = null) + public function sentAssetAcceptanceReminder(Request $request) { $this->authorize('reports.view'); - if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) { + if (!$acceptance = CheckoutAcceptance::pending()->find($request->input('acceptance_id'))) { + \Log::debug('No pending acceptances'); // Redirect to the unaccepted assets report page with error return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } + $assetItem = $acceptance->checkoutable; + \Log::debug(print_r($assetItem, true)); + if (is_null($acceptance->created_at)){ + \Log::debug('No acceptance created_at'); return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } else { $logItem_res = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get(); + + \Log::debug('Acceptance created at: '.$acceptance->created_at); + \Log::debug(print_r($logItem_res, true)); + if ($logItem_res->isEmpty()){ + \Log::debug('Acceptance date mismatch'); return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } $logItem = $logItem_res[0]; } - if(!$assetItem->assignedTo->locale){ + if (!$assetItem->assignedTo->locale){ Notification::locale(Setting::getSettings()->locale)->send( $assetItem->assignedTo, new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) diff --git a/resources/views/reports/unaccepted_assets.blade.php b/resources/views/reports/unaccepted_assets.blade.php index 37ae66ce30d8..80d151fd422f 100644 --- a/resources/views/reports/unaccepted_assets.blade.php +++ b/resources/views/reports/unaccepted_assets.blade.php @@ -77,11 +77,23 @@ class="table table-striped snipe-table" {!! $item['assetItem']->present()->nameUrl() !!} {{ $item['assetItem']->asset_tag }} assignedTo === null || $item['acceptance']->assignedTo->trashed()) style="text-decoration: line-through" @endif>{!! ($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->nameUrl() : trans('admin/reports/general.deleted_user') !!} - + + @if(!$item['acceptance']->trashed()) - @if ($item['acceptance']->assignedTo){{ trans('admin/reports/general.send_reminder') }}@endif +
+ @if ($item['acceptance']->assignedTo) + @csrf + + + + @endif +
@endif + +
@endif diff --git a/routes/web.php b/routes/web.php index 4bc8b3bb58c5..0aacf85135d1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -368,8 +368,8 @@ 'reports/unaccepted_assets/{deleted?}', [ReportsController::class, 'getAssetAcceptanceReport'] )->name('reports/unaccepted_assets'); - Route::get( - 'reports/unaccepted_assets/{acceptanceId}/sent_reminder', + Route::post( + 'reports/unaccepted_assets/sent_reminder', [ReportsController::class, 'sentAssetAcceptanceReminder'] )->name('reports/unaccepted_assets_sent_reminder'); Route::delete(