Fix dashboard shows all companies

Fix dashboard page shows statistics of all companies
even when the user is assigned to a company
and full multiple companies support is enabled
This commit is contained in:
Abdullah Alansari
2015-11-18 06:14:08 +03:00
parent 999910f31f
commit 6478425be6
3 changed files with 15 additions and 11 deletions
+11 -7
View File
@@ -4,6 +4,7 @@ use AdminController;
use View;
use Asset;
use Actionlog;
use Company;
class DashboardController extends AdminController
{
@@ -16,12 +17,15 @@ class DashboardController extends AdminController
{
// Show the page
$recent_activity = Actionlog::orderBy('created_at','DESC')->with('accessorylog','consumablelog','licenselog','assetlog','adminlog','userlog')->take(7)->get();
$recent_activity = Company::scopeActionLogs(Actionlog::orderBy('created_at','DESC'))
->with('accessorylog','consumablelog','licenselog','assetlog','adminlog','userlog')
->take(7)
->get();
$asset_stats['total'] = Asset::Hardware()->count();
$asset_stats['total'] = Company::scopeCompanayables(Asset::Hardware())->count();
$asset_stats['rtd']['total'] = Asset::Hardware()->RTD()->count();
$asset_stats['rtd']['total'] = Company::scopeCompanayables(Asset::Hardware()->RTD())->count();
if ($asset_stats['rtd']['total'] > 0) {
$asset_stats['rtd']['percent'] = round(($asset_stats['rtd']['total']/$asset_stats['total']) * 100);
@@ -30,7 +34,7 @@ class DashboardController extends AdminController
}
$asset_stats['pending']['total'] = Asset::Hardware()->Pending()->count();
$asset_stats['pending']['total'] = Company::scopeCompanayables(Asset::Hardware()->Pending())->count();
if ($asset_stats['pending']['total'] > 0) {
$asset_stats['pending']['percent'] = round(($asset_stats['pending']['total']/$asset_stats['total']) * 100);
@@ -39,7 +43,7 @@ class DashboardController extends AdminController
}
$asset_stats['deployed']['total'] = Asset::Hardware()->Deployed()->count();
$asset_stats['deployed']['total'] = Company::scopeCompanayables(Asset::Hardware()->Deployed())->count();
if ($asset_stats['deployed']['total'] > 0) {
$asset_stats['deployed']['percent'] = round(($asset_stats['deployed']['total']/$asset_stats['total']) * 100);
@@ -48,7 +52,7 @@ class DashboardController extends AdminController
}
$asset_stats['undeployable']['total'] = Asset::Hardware()->Undeployable()->count();
$asset_stats['undeployable']['total'] = Company::scopeCompanayables(Asset::Hardware()->Undeployable())->count();
if ($asset_stats['undeployable']['total'] > 0) {
$asset_stats['undeployable']['percent'] = round(($asset_stats['undeployable']['total']/$asset_stats['total']) * 100);
@@ -56,7 +60,7 @@ class DashboardController extends AdminController
$asset_stats['undeployable']['percent'] = 0;
}
$asset_stats['archived']['total'] = Asset::Hardware()->Archived()->count();
$asset_stats['archived']['total'] = Company::scopeCompanayables(Asset::Hardware()->Archived())->count();
if ($asset_stats['archived']['total'] > 0) {
$asset_stats['archived']['percent'] = round(($asset_stats['archived']['total']/$asset_stats['total']) * 100);
+2 -2
View File
@@ -258,7 +258,7 @@ return false;
public static function assetcount()
{
return DB::table( 'assets' )
return Company::scopeCompanayables( DB::table( 'assets' ) )
->where( 'physical', '=', '1' )
->whereNull( 'deleted_at', 'and' )
->count();
@@ -270,7 +270,7 @@ return false;
public static function availassetcount()
{
return Asset::RTD()
return Company::scopeCompanayables( Asset::RTD() )
->whereNull( 'deleted_at' )
->count();
+2 -2
View File
@@ -69,7 +69,7 @@ class License extends Depreciable
*/
public static function assetcount()
{
return DB::table('license_seats')
return Company::scopeCompanayableChildren('license', LicenseSeat::with('license'))
->whereNull('deleted_at')
->count();
}
@@ -92,7 +92,7 @@ class License extends Depreciable
*/
public static function availassetcount()
{
return DB::table('license_seats')
return Company::scopeCompanayableChildren('license', LicenseSeat::with('license'))
->whereNull('assigned_to')
->whereNull('asset_id')
->whereNull('deleted_at')