Added Reseller view
This commit is contained in:
18
app/Http/Controllers/ResellerServicesController.php
Normal file
18
app/Http/Controllers/ResellerServicesController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
|
||||
class ResellerServicesController extends Controller
|
||||
{
|
||||
public function agents()
|
||||
{
|
||||
return ['data'=>Auth::user()->all_agents()->values()];
|
||||
}
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return ['data'=>Auth::user()->all_accounts()->values()];
|
||||
}
|
||||
}
|
@@ -15,13 +15,13 @@ class UserHomeController extends Controller
|
||||
{
|
||||
switch (Auth::user()->role()) {
|
||||
case 'Customer':
|
||||
return View('home');
|
||||
return View('userhome',['o'=>Auth::user()]);
|
||||
|
||||
case 'Reseller':
|
||||
break;
|
||||
return View('resellerhome',['o'=>Auth::user()]);
|
||||
|
||||
case 'Wholesaler':
|
||||
break;
|
||||
return View('resellerhome',['o'=>Auth::user()]);
|
||||
|
||||
default:
|
||||
abort(500,'Unknown role: ',Auth::user()->role());
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\SetSite;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
@@ -62,6 +61,7 @@ class Kernel extends HttpKernel
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'demoMode' => \Spatie\DemoMode\DemoMode::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'reseller' => \App\Http\Middleware\Reseller::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'theme' => \Igaster\LaravelTheme\Middleware\setTheme::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
|
19
app/Http/Middleware/Reseller.php
Normal file
19
app/Http/Middleware/Reseller.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Closure;
|
||||
|
||||
class Reseller
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (! in_array(Auth::user()->role(),['Wholesaler','Reseller']))
|
||||
{
|
||||
abort(303,'Not Reseller');
|
||||
|
||||
} else
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@@ -9,6 +9,15 @@ class Account extends Model
|
||||
protected $table = 'ab_account';
|
||||
public $timestamps = FALSE;
|
||||
|
||||
protected $appends = [
|
||||
'active_display',
|
||||
];
|
||||
protected $visible = [
|
||||
'id',
|
||||
'company',
|
||||
'active_display',
|
||||
];
|
||||
|
||||
/**
|
||||
* Return the country the user belongs to
|
||||
*/
|
||||
@@ -26,4 +35,14 @@ class Account extends Model
|
||||
{
|
||||
return $this->belongsTo(\App\User::class);
|
||||
}
|
||||
|
||||
public function getCompanyAttribute($value)
|
||||
{
|
||||
return $value ? $value : $this->user->SurFirstName;
|
||||
}
|
||||
|
||||
public function getActiveDisplayAttribute($value)
|
||||
{
|
||||
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'primary' : 'danger',$this->active ? 'Active' : 'Inactive');
|
||||
}
|
||||
}
|
88
app/User.php
88
app/User.php
@@ -14,6 +14,7 @@ class User extends Authenticatable
|
||||
use HasApiTokens,Notifiable,UserSwitch;
|
||||
|
||||
protected $dates = ['created_at','updated_at','last_access'];
|
||||
protected $with = ['accounts'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -33,17 +34,28 @@ class User extends Authenticatable
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
public function accounts()
|
||||
protected $appends = [
|
||||
'surfirstname',
|
||||
'user_id_url',
|
||||
];
|
||||
protected $visible = [
|
||||
'id',
|
||||
'surfirstname',
|
||||
'level',
|
||||
'user_id_url',
|
||||
];
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany(Models\Account::class);
|
||||
}
|
||||
|
||||
protected function agents() {
|
||||
return $this->hasMany(static::class,'parent_id','id');
|
||||
public function agents() {
|
||||
return $this->hasMany(static::class,'parent_id','id')->with('agents');
|
||||
}
|
||||
|
||||
protected function clients() {
|
||||
return $this->hasMany(\App\User::class);
|
||||
public function clients() {
|
||||
return $this->hasMany(static::class,'parent_id','id')->with('clients');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
@@ -80,6 +92,11 @@ class User extends Authenticatable
|
||||
return sprintf('%s %s',$this->firstname,$this->lastname);
|
||||
}
|
||||
|
||||
public function getSurFirstNameAttribute()
|
||||
{
|
||||
return sprintf('%s, %s',$this->lastname,$this->firstname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Carbon Date if it has a value.
|
||||
*
|
||||
@@ -92,6 +109,7 @@ class User extends Authenticatable
|
||||
if (! is_null($value))
|
||||
return new Carbon($value);
|
||||
}
|
||||
|
||||
public function getInvoicesDueAttribute()
|
||||
{
|
||||
return $this->invoices
|
||||
@@ -124,33 +142,73 @@ class User extends Authenticatable
|
||||
return $this->full_name;
|
||||
}
|
||||
|
||||
public function getUserIdAttribute()
|
||||
{
|
||||
return sprintf('%02s-%04s',$this->site_id,$this->id);
|
||||
}
|
||||
|
||||
public function getUserIdUrlAttribute()
|
||||
{
|
||||
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->user_id);
|
||||
}
|
||||
|
||||
public function scopeActive()
|
||||
{
|
||||
return $this->where('active',TRUE);
|
||||
}
|
||||
|
||||
// List all the agents, including agents of agents
|
||||
public function all_agents()
|
||||
public function all_agents($level=0)
|
||||
{
|
||||
$result = collect();
|
||||
|
||||
foreach ($this->agents()->orderBy('id')->get() as $o)
|
||||
foreach ($this->agents as $o)
|
||||
{
|
||||
if (! $o->active)
|
||||
if (! $o->active OR ! $o->agents->count())
|
||||
continue;
|
||||
|
||||
$result->push($o->all_agents());
|
||||
$result->push($this);
|
||||
$o->level = $level;
|
||||
|
||||
$result->push($o);
|
||||
|
||||
// Include agents of agents
|
||||
$result->push($o->all_agents($level+1));
|
||||
}
|
||||
|
||||
return $result->flatten();
|
||||
}
|
||||
|
||||
public function all_clients()
|
||||
public function all_accounts()
|
||||
{
|
||||
// List all the clients of my agents
|
||||
$result = collect();
|
||||
|
||||
foreach ($this->all_clients() as $o)
|
||||
{
|
||||
$result->push($o->accounts->where('active',TRUE));
|
||||
}
|
||||
|
||||
return $result->flatten();
|
||||
}
|
||||
|
||||
public function all_suppliers()
|
||||
public function all_clients($level=0)
|
||||
{
|
||||
// For each supplier, so if that supplier has a parent
|
||||
}
|
||||
$result = collect();
|
||||
|
||||
foreach ($this->clients as $o)
|
||||
{
|
||||
if (! $o->active)
|
||||
continue;
|
||||
|
||||
$o->level = $level;
|
||||
|
||||
$result->push($o);
|
||||
|
||||
// Include clients of agents
|
||||
$result->push($o->all_clients($level+1));
|
||||
}
|
||||
|
||||
return $result->flatten();
|
||||
}
|
||||
public function role()
|
||||
{
|
||||
// If I have agents and no parent, I am the wholesaler
|
||||
|
Reference in New Issue
Block a user