From ed99532c30eedb8fec21fd09e8a7900e55a0f01f Mon Sep 17 00:00:00 2001 From: Dampfklon Date: Mon, 3 May 2021 21:06:12 +0200 Subject: [PATCH] Unaccepted Assets Report Actions (send reminder, delete) added Unaccepted Assets Export fixed --- app/Http/Controllers/ReportsController.php | 97 ++++++++++++++++++- resources/lang/en/admin/reports/general.php | 11 +++ resources/lang/en/general.php | 1 + .../views/reports/unaccepted_assets.blade.php | 21 ++-- routes/web.php | 8 ++ 5 files changed, 127 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index fac4699bba..5e3856be36 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -12,8 +12,10 @@ use App\Models\CustomField; use App\Models\Depreciation; use App\Models\License; use App\Models\Setting; +use App\Notifications\CheckoutAssetNotification; use Carbon\Carbon; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\View; use Input; @@ -904,6 +906,7 @@ class ReportsController extends Controller * getAssetAcceptanceReport * * @return mixed + * @throws \Illuminate\Auth\Access\AuthorizationException * @author Vincent Sposato * @version v1.0 */ @@ -914,19 +917,87 @@ class ReportsController extends Controller /** * Get all assets with pending checkout acceptances */ +<<<<<<< HEAD $acceptances = CheckoutAcceptance::pending()->get(); +======= + $acceptances = CheckoutAcceptance::pending()->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get(); +>>>>>>> Unaccepted Assets Report Actions (send reminder, delete) added $assetsForReport = $acceptances ->filter(function ($acceptance) { return $acceptance->checkoutable_type == \App\Models\Asset::class; }) +<<<<<<< HEAD ->map(function ($acceptance) { return $acceptance->checkoutable; +======= + ->map(function($acceptance) { + return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; +>>>>>>> Unaccepted Assets Report Actions (send reminder, delete) added }); return view('reports/unaccepted_assets', compact('assetsForReport')); } + /** + * sentAssetAcceptanceReminder + * + * @param integer|null $acceptanceId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + * @version v1.0 + */ + public function sentAssetAcceptanceReminder($acceptanceId = null) + { + $this->authorize('reports.view'); + + if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) { + // Redirect to the unaccepted assets report page with error + return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); + } + $assetItem = $acceptance->checkoutable; + + $logItem = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get()[0]; + + if(!$assetItem->assignedTo->locale){ + Notification::locale(Setting::getSettings()->locale)->send( + $assetItem->assignedTo, + new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) + ); + } else { + Notification::send( + $assetItem->assignedTo, + new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) + ); + } + + return redirect()->route('reports/unaccepted_assets')->with('success', trans('admin/reports/general.reminder_sent')); + } + + /** + * sentAssetAcceptanceReminder + * + * @param integer|null $acceptanceId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + * @version v1.0 + */ + public function deleteAssetAcceptance($acceptanceId = null) + { + $this->authorize('reports.view'); + + if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) { + // Redirect to the unaccepted assets report page with error + return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); + } + + if($acceptance->delete()) { + return redirect()->route('reports/unaccepted_assets')->with('success', trans('admin/reports/general.acceptance_deleted')); + } else { + return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.deletion_failed')); + } + } + /** * exportAssetAcceptanceReport * @@ -937,9 +1008,19 @@ class ReportsController extends Controller public function exportAssetAcceptanceReport() { $this->authorize('reports.view'); - // Grab all the improvements - $assetsForReport = Actionlog::whereIn('id', $this->getAssetsNotAcceptedYet()) - ->get(); + + /** + * Get all assets with pending checkout acceptances + */ + $acceptances = CheckoutAcceptance::pending()->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model'])->get(); + + $assetsForReport = $acceptances + ->filter(function($acceptance) { + return $acceptance->checkoutable_type == 'App\Models\Asset'; + }) + ->map(function($acceptance) { + return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; + }); $rows = []; @@ -954,6 +1035,7 @@ class ReportsController extends Controller $header = array_map('trim', $header); $rows[] = implode($header, ','); +<<<<<<< HEAD foreach ($assetsForReport as $assetItem) { $row = []; $row[] = str_replace(',', '', e($assetItem->assetlog->model->category->name)); @@ -961,6 +1043,15 @@ class ReportsController extends Controller $row[] = str_replace(',', '', e($assetItem->assetlog->present()->name())); $row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag)); $row[] = str_replace(',', '', e($assetItem->assetlog->assignedTo->present()->name())); +======= + foreach ($assetsForReport as $item) { + $row = [ ]; + $row[] = str_replace(',', '', e($item['assetItem']->model->category->name)); + $row[] = str_replace(',', '', e($item['assetItem']->model->name)); + $row[] = str_replace(',', '', e($item['assetItem']->name)); + $row[] = str_replace(',', '', e($item['assetItem']->asset_tag)); + $row[] = str_replace(',', '', e(($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->name() : trans('admin/reports/general.deleted_user'))); +>>>>>>> Unaccepted Assets Report Actions (send reminder, delete) added $rows[] = implode($row, ','); } diff --git a/resources/lang/en/admin/reports/general.php b/resources/lang/en/admin/reports/general.php index 65e2bb1d73..ad3b0f5df1 100644 --- a/resources/lang/en/admin/reports/general.php +++ b/resources/lang/en/admin/reports/general.php @@ -1,5 +1,16 @@ 'Select the options you want for your asset report.', ]; +======= +return array( + 'info' => 'Select the options you want for your asset report.', + 'deleted_user' => 'Deleted user', + 'send_reminder' => 'Send reminder', + 'reminder_sent' => 'Reminder sent', + 'acceptance_deleted' => 'Acceptance request deleted', + 'acceptance_request' => 'Acceptance request' +); +>>>>>>> Unaccepted Assets Report Actions (send reminder, delete) added diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 5c79f227e6..aeb8dd9565 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -73,6 +73,7 @@ 'delete_confirm' => 'Are you sure you wish to delete :item?', 'deleted' => 'Deleted', 'delete_seats' => 'Deleted Seats', + 'deletion_failed' => 'Deletion failed', 'departments' => 'Departments', 'department' => 'Department', 'deployed' => 'Deployed', diff --git a/resources/views/reports/unaccepted_assets.blade.php b/resources/views/reports/unaccepted_assets.blade.php index 45b6f163a3..8432f25b8f 100644 --- a/resources/views/reports/unaccepted_assets.blade.php +++ b/resources/views/reports/unaccepted_assets.blade.php @@ -41,19 +41,24 @@ {{ trans('admin/hardware/form.name') }} {{ trans('admin/hardware/table.asset_tag') }} {{ trans('admin/hardware/table.checkoutto') }} + {{ trans('table.actions') }} @if ($assetsForReport) - @foreach ($assetsForReport as $assetItem) - @if ($assetItem) + @foreach ($assetsForReport as $item) + @if ($item['assetItem']) - {{ ($assetItem->company) ? $assetItem->company->name : '' }} - {{ $assetItem->model->category->name }} - {{ $assetItem->model->name }} - {!! $assetItem->present()->nameUrl() !!} - {{ $assetItem->asset_tag }} - {!! ($assetItem->assignedTo) ? $assetItem->assignedTo->present()->nameUrl() : 'Deleted user' !!} + {{ ($item['assetItem']->company) ? $assetItem->company->name : '' }} + {!! $item['assetItem']->model->category->present()->nameUrl() !!} + {!! $item['assetItem']->present()->modelUrl() !!} + {!! $item['assetItem']->present()->nameUrl() !!} + {{ $item['assetItem']->asset_tag }} + {!! ($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->nameUrl() : trans('admin/reports/general.deleted_user') !!} + + @if ($item['acceptance']->assignedTo){{ trans('admin/reports/general.send_reminder') }}@endif + + @endif @endforeach diff --git a/routes/web.php b/routes/web.php index 7a6c25bdcb..934bb4de83 100644 --- a/routes/web.php +++ b/routes/web.php @@ -322,6 +322,14 @@ Route::group(['middleware' => ['auth']], function () { 'reports/unaccepted_assets', [ReportsController::class, 'getAssetAcceptanceReport'] )->name('reports/unaccepted_assets'); + Route::get( + 'reports/unaccepted_assets/{acceptanceId}/sent_reminder', + [ 'as' => 'reports/unaccepted_assets_sent_reminder', 'uses' => 'ReportsController@sentAssetAcceptanceReminder' ] + ); + Route::delete( + 'reports/unaccepted_assets/{acceptanceId}/delete', + [ 'as' => 'reports/unaccepted_assets_delete', 'uses' => 'ReportsController@deleteAssetAcceptance' ] + ); Route::get( 'reports/export/unaccepted_assets', [ReportsController::class, 'exportAssetAcceptanceReport']