2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-06-11 14:43:47 -07:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2024-07-04 14:37:58 -07:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use \Illuminate\Contracts\View\View;
|
2024-09-09 14:54:19 -07:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2021-06-11 14:43:47 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to the Admin Dashboard
|
|
|
|
* for the Snipe-IT Asset Management application.
|
|
|
|
*
|
2021-06-11 14:43:47 -07:00
|
|
|
* @author A. Gianotto <snipe@snipe.net>
|
|
|
|
* @version v1.0
|
2016-04-07 13:21:09 -07:00
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class DashboardController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2021-06-10 13:15:52 -07:00
|
|
|
* Check authorization and display admin dashboard, otherwise display
|
|
|
|
* the user's checked-out assets.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
*/
|
2024-07-04 14:37:58 -07:00
|
|
|
public function index() : View | RedirectResponse
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Show the page
|
2024-07-04 12:49:22 -07:00
|
|
|
if (auth()->user()->hasAccess('admin')) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$asset_stats = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-05-31 02:02:55 -07:00
|
|
|
$counts['asset'] = \App\Models\Asset::count();
|
|
|
|
$counts['accessory'] = \App\Models\Accessory::count();
|
|
|
|
$counts['license'] = \App\Models\License::assetcount();
|
|
|
|
$counts['consumable'] = \App\Models\Consumable::count();
|
2021-06-19 16:16:18 -07:00
|
|
|
$counts['component'] = \App\Models\Component::count();
|
2024-07-04 12:49:22 -07:00
|
|
|
$counts['user'] = \App\Models\Company::scopeCompanyables(auth()->user())->count();
|
2021-06-10 13:15:52 -07:00
|
|
|
$counts['grand_total'] = $counts['asset'] + $counts['accessory'] + $counts['license'] + $counts['consumable'];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
if ((! file_exists(storage_path().'/oauth-private.key')) || (! file_exists(storage_path().'/oauth-public.key'))) {
|
2021-06-11 14:43:47 -07:00
|
|
|
Artisan::call('migrate', ['--force' => true]);
|
2017-10-11 12:42:31 -07:00
|
|
|
\Artisan::call('passport:install');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('dashboard')->with('asset_stats', $asset_stats)->with('counts', $counts);
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2024-09-09 14:54:19 -07:00
|
|
|
Session::reflash();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
// Redirect to the profile page
|
2016-10-29 07:32:48 -07:00
|
|
|
return redirect()->intended('account/view-assets');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|