From ca402df52521933c729a74621ae5b73d2ab81718 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 9 Aug 2018 09:33:51 +1000 Subject: [PATCH] Updates to login home --- app/Http/Controllers/AdminHomeController.php | 2 +- .../ResellerServicesController.php | 9 ++- app/Http/Controllers/UserHomeController.php | 12 +-- app/Models/Account.php | 19 +++++ app/User.php | 33 ++++++-- .../theme/backend/adminlte/a/setup.blade.php | 2 +- .../backend/adminlte/r/accounts.blade.php | 21 +++--- .../backend/adminlte/r/clients.blade.php | 75 +++++++++++++++++++ .../home.blade.php} | 5 +- .../{userhome.blade.php => u/home.blade.php} | 0 .../adminlte/{ => u}/invoice.blade.php | 26 +++---- routes/api.php | 1 + 12 files changed, 166 insertions(+), 39 deletions(-) create mode 100644 resources/theme/backend/adminlte/r/clients.blade.php rename resources/theme/backend/adminlte/{resellerhome.blade.php => r/home.blade.php} (86%) rename resources/theme/backend/adminlte/{userhome.blade.php => u/home.blade.php} (100%) rename resources/theme/backend/adminlte/{ => u}/invoice.blade.php (91%) diff --git a/app/Http/Controllers/AdminHomeController.php b/app/Http/Controllers/AdminHomeController.php index 08bda0a..0f521b8 100644 --- a/app/Http/Controllers/AdminHomeController.php +++ b/app/Http/Controllers/AdminHomeController.php @@ -44,7 +44,7 @@ class AdminHomeController extends Controller try { if ($key == 'site_logo' AND $value instanceof UploadedFile) { - $path = $value->storePubliclyAs('site/'.config('SITE_SETUP')->id,$value->getClientOriginalName()); + $path = $value->storeAs('site/'.config('SITE_SETUP')->id,$value->getClientOriginalName(),'public'); SiteDetails::updateOrCreate([ 'site_id'=>config('SITE_SETUP')->id, diff --git a/app/Http/Controllers/ResellerServicesController.php b/app/Http/Controllers/ResellerServicesController.php index 3a44b5e..006eba2 100644 --- a/app/Http/Controllers/ResellerServicesController.php +++ b/app/Http/Controllers/ResellerServicesController.php @@ -6,13 +6,18 @@ use Auth; class ResellerServicesController extends Controller { + public function accounts() + { + return ['data'=>Auth::user()->all_accounts()->values()]; + } + public function agents() { return ['data'=>Auth::user()->all_agents()->values()]; } - public function accounts() + public function clients() { - return ['data'=>Auth::user()->all_accounts()->values()]; + return ['data'=>Auth::user()->all_clients()->values()]; } } \ No newline at end of file diff --git a/app/Http/Controllers/UserHomeController.php b/app/Http/Controllers/UserHomeController.php index 3f0143c..0367d79 100644 --- a/app/Http/Controllers/UserHomeController.php +++ b/app/Http/Controllers/UserHomeController.php @@ -16,25 +16,25 @@ class UserHomeController extends Controller public function invoice(Invoice $o) { - return View('invoice',['o'=>$o]); + return View('u.invoice',['o'=>$o]); } public function invoice_pdf(Invoice $o) { - return PDF::loadView('invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id)); + return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id)); } public function home() { switch (Auth::user()->role()) { case 'customer': - return View('userhome',['o'=>Auth::user()]); + return View('u.home',['o'=>Auth::user()]); case 'reseller': - return View('resellerhome',['o'=>Auth::user()]); + return View('r.home',['o'=>Auth::user()]); case 'wholesaler': - return View('resellerhome',['o'=>Auth::user()]); + return View('r.home',['o'=>Auth::user()]); default: abort(500,'Unknown role: '.Auth::user()->role()); @@ -58,6 +58,6 @@ class UserHomeController extends Controller public function User(User $o) { // @todo Check authorised to see this account. - return View('userhome',['o'=>$o]); + return View('u.home',['o'=>$o]); } } \ No newline at end of file diff --git a/app/Models/Account.php b/app/Models/Account.php index 89f2ee1..4df4ac9 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -11,11 +11,15 @@ class Account extends Model protected $appends = [ 'active_display', + 'services_count_html', + 'switch_url', ]; protected $visible = [ 'id', 'company', 'active_display', + 'services_count_html', + 'switch_url', ]; /** @@ -31,6 +35,11 @@ class Account extends Model return $this->belongsTo(Language::class); } + public function services() + { + return $this->hasMany(Service::class); + } + public function user() { return $this->belongsTo(\App\User::class); @@ -56,6 +65,16 @@ class Account extends Model return sprintf('%s',$this->id,$this->account_id); } + public function getServicesCountHtmlAttribute() + { + return sprintf('%s /%s',$this->services->where('active',TRUE)->count(),$this->services->count()); + } + + public function getSwitchUrlAttribute() + { + return sprintf('',$this->user_id); + } + private function _address() { $return = []; diff --git a/app/User.php b/app/User.php index ee25011..44397df 100644 --- a/app/User.php +++ b/app/User.php @@ -15,7 +15,7 @@ class User extends Authenticatable use HasApiTokens,Notifiable,UserSwitch; protected $dates = ['created_at','updated_at','last_access']; - protected $with = ['accounts']; + protected $with = ['accounts.services']; /** * The attributes that are mass assignable. @@ -36,13 +36,20 @@ class User extends Authenticatable ]; protected $appends = [ + 'active_display', + 'services_count_html', 'surfirstname', + 'switch_url', 'user_id_url', ]; + protected $visible = [ + 'active_display', 'id', - 'surfirstname', 'level', + 'services_count_html', + 'switch_url', + 'surfirstname', 'user_id_url', ]; @@ -88,6 +95,11 @@ class User extends Authenticatable return $this->hasMany(static::class,'parent_id','id'); } + public function getActiveDisplayAttribute($value) + { + return sprintf('%s',$this->active ? 'primary' : 'danger',$this->active ? 'Active' : 'Inactive'); + } + /** * Logged in users full name * @@ -130,7 +142,6 @@ class User extends Authenticatable { if (is_null($this->language_id)) return config('SITE_SETUP')->language; - dd(__METHOD__,$value,config('SITE_SETUP')->language); } public function getPaymentHistoryAttribute() @@ -155,6 +166,16 @@ class User extends Authenticatable return $this->full_name; } + public function getServicesCountHtmlAttribute() + { + return sprintf('%s /%s',$this->services->where('active',TRUE)->count(),$this->services->count()); + } + + public function getSwitchUrlAttribute() + { + return sprintf('',$this->id); + } + public function getUserIdAttribute() { return sprintf('%02s-%04s',$this->site_id,$this->id); @@ -235,15 +256,15 @@ class User extends Authenticatable public function role() { // If I have agents and no parent, I am the wholesaler - if (is_null($this->parent_id) AND $this->all_agents()->count()) + if (is_null($this->parent_id) AND ($this->all_agents()->count() OR $this->all_clients()->count())) return 'wholesaler'; // If I have agents and a parent, I am a reseller - elseif ($this->parent_id AND $this->all_agents()->count()) + elseif ($this->parent_id AND ($this->all_agents()->count() OR $this->all_clients()->count())) return 'reseller'; // If I have no agents and a parent, I am a customer - elseif (! $this->all_agents()->count()) + elseif (! $this->all_agents()->count() AND ! $this->all_clients()->count()) return 'customer'; } } \ No newline at end of file diff --git a/resources/theme/backend/adminlte/a/setup.blade.php b/resources/theme/backend/adminlte/a/setup.blade.php index db136ed..64c4a58 100644 --- a/resources/theme/backend/adminlte/a/setup.blade.php +++ b/resources/theme/backend/adminlte/a/setup.blade.php @@ -75,7 +75,7 @@ @section('page-scripts') @js('/js/jqBootstrapValidation.js','jq-validation','jquery') +@append diff --git a/resources/theme/backend/adminlte/resellerhome.blade.php b/resources/theme/backend/adminlte/r/home.blade.php similarity index 86% rename from resources/theme/backend/adminlte/resellerhome.blade.php rename to resources/theme/backend/adminlte/r/home.blade.php index 0481941..df7c882 100644 --- a/resources/theme/backend/adminlte/resellerhome.blade.php +++ b/resources/theme/backend/adminlte/r/home.blade.php @@ -12,10 +12,13 @@ @endsection @section('main-content') +
+ @include('r.accounts') +
@include('r.agents')
- @include('r.accounts') + @include('r.clients')
@endsection \ No newline at end of file diff --git a/resources/theme/backend/adminlte/userhome.blade.php b/resources/theme/backend/adminlte/u/home.blade.php similarity index 100% rename from resources/theme/backend/adminlte/userhome.blade.php rename to resources/theme/backend/adminlte/u/home.blade.php diff --git a/resources/theme/backend/adminlte/invoice.blade.php b/resources/theme/backend/adminlte/u/invoice.blade.php similarity index 91% rename from resources/theme/backend/adminlte/invoice.blade.php rename to resources/theme/backend/adminlte/u/invoice.blade.php index 9e1ef8c..1592c7d 100644 --- a/resources/theme/backend/adminlte/invoice.blade.php +++ b/resources/theme/backend/adminlte/u/invoice.blade.php @@ -223,21 +223,21 @@ } @append \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 381c83c..0b914b5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,6 +22,7 @@ Route::middleware('auth:api')->get('/user', function (Request $request) { Route::group(['middleware'=>['auth:api','role:reseller']], function() { Route::get('/r/agents','ResellerServicesController@agents'); Route::get('/r/accounts','ResellerServicesController@accounts'); + Route::get('/r/clients','ResellerServicesController@clients'); }); Route::group(['middleware'=>'auth:api'], function() {