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\Auth;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
|
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]
|
|
|
|
* @return View
|
|
|
|
*/
|
2021-06-11 14:43:47 -07:00
|
|
|
public function index()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Show the page
|
|
|
|
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();
|
2022-12-20 16:39:17 -08: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 {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|