Updates to login home

This commit is contained in:
Deon George 2018-08-09 09:33:51 +10:00
parent b9cf666581
commit ca402df525
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
12 changed files with 166 additions and 39 deletions

View File

@ -44,7 +44,7 @@ class AdminHomeController extends Controller
try { try {
if ($key == 'site_logo' AND $value instanceof UploadedFile) 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([ SiteDetails::updateOrCreate([
'site_id'=>config('SITE_SETUP')->id, 'site_id'=>config('SITE_SETUP')->id,

View File

@ -6,13 +6,18 @@ use Auth;
class ResellerServicesController extends Controller class ResellerServicesController extends Controller
{ {
public function accounts()
{
return ['data'=>Auth::user()->all_accounts()->values()];
}
public function agents() public function agents()
{ {
return ['data'=>Auth::user()->all_agents()->values()]; 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()];
} }
} }

View File

@ -16,25 +16,25 @@ class UserHomeController extends Controller
public function invoice(Invoice $o) public function invoice(Invoice $o)
{ {
return View('invoice',['o'=>$o]); return View('u.invoice',['o'=>$o]);
} }
public function invoice_pdf(Invoice $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() public function home()
{ {
switch (Auth::user()->role()) { switch (Auth::user()->role()) {
case 'customer': case 'customer':
return View('userhome',['o'=>Auth::user()]); return View('u.home',['o'=>Auth::user()]);
case 'reseller': case 'reseller':
return View('resellerhome',['o'=>Auth::user()]); return View('r.home',['o'=>Auth::user()]);
case 'wholesaler': case 'wholesaler':
return View('resellerhome',['o'=>Auth::user()]); return View('r.home',['o'=>Auth::user()]);
default: default:
abort(500,'Unknown role: '.Auth::user()->role()); abort(500,'Unknown role: '.Auth::user()->role());
@ -58,6 +58,6 @@ class UserHomeController extends Controller
public function User(User $o) public function User(User $o)
{ {
// @todo Check authorised to see this account. // @todo Check authorised to see this account.
return View('userhome',['o'=>$o]); return View('u.home',['o'=>$o]);
} }
} }

View File

@ -11,11 +11,15 @@ class Account extends Model
protected $appends = [ protected $appends = [
'active_display', 'active_display',
'services_count_html',
'switch_url',
]; ];
protected $visible = [ protected $visible = [
'id', 'id',
'company', 'company',
'active_display', 'active_display',
'services_count_html',
'switch_url',
]; ];
/** /**
@ -31,6 +35,11 @@ class Account extends Model
return $this->belongsTo(Language::class); return $this->belongsTo(Language::class);
} }
public function services()
{
return $this->hasMany(Service::class);
}
public function user() public function user()
{ {
return $this->belongsTo(\App\User::class); return $this->belongsTo(\App\User::class);
@ -56,6 +65,16 @@ class Account extends Model
return sprintf('<a href="/r/account/view/%s">%s</a>',$this->id,$this->account_id); return sprintf('<a href="/r/account/view/%s">%s</a>',$this->id,$this->account_id);
} }
public function getServicesCountHtmlAttribute()
{
return sprintf('%s <small>/%s</small>',$this->services->where('active',TRUE)->count(),$this->services->count());
}
public function getSwitchUrlAttribute()
{
return sprintf('<a href="/a/switch/start/%s"><i class="fa fa-external-link"></i></a>',$this->user_id);
}
private function _address() private function _address()
{ {
$return = []; $return = [];

View File

@ -15,7 +15,7 @@ class User extends Authenticatable
use HasApiTokens,Notifiable,UserSwitch; use HasApiTokens,Notifiable,UserSwitch;
protected $dates = ['created_at','updated_at','last_access']; protected $dates = ['created_at','updated_at','last_access'];
protected $with = ['accounts']; protected $with = ['accounts.services'];
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
@ -36,13 +36,20 @@ class User extends Authenticatable
]; ];
protected $appends = [ protected $appends = [
'active_display',
'services_count_html',
'surfirstname', 'surfirstname',
'switch_url',
'user_id_url', 'user_id_url',
]; ];
protected $visible = [ protected $visible = [
'active_display',
'id', 'id',
'surfirstname',
'level', 'level',
'services_count_html',
'switch_url',
'surfirstname',
'user_id_url', 'user_id_url',
]; ];
@ -88,6 +95,11 @@ class User extends Authenticatable
return $this->hasMany(static::class,'parent_id','id'); return $this->hasMany(static::class,'parent_id','id');
} }
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');
}
/** /**
* Logged in users full name * Logged in users full name
* *
@ -130,7 +142,6 @@ class User extends Authenticatable
{ {
if (is_null($this->language_id)) if (is_null($this->language_id))
return config('SITE_SETUP')->language; return config('SITE_SETUP')->language;
dd(__METHOD__,$value,config('SITE_SETUP')->language);
} }
public function getPaymentHistoryAttribute() public function getPaymentHistoryAttribute()
@ -155,6 +166,16 @@ class User extends Authenticatable
return $this->full_name; return $this->full_name;
} }
public function getServicesCountHtmlAttribute()
{
return sprintf('%s <small>/%s</small>',$this->services->where('active',TRUE)->count(),$this->services->count());
}
public function getSwitchUrlAttribute()
{
return sprintf('<a href="/a/switch/start/%s"><i class="fa fa-external-link"></i></a>',$this->id);
}
public function getUserIdAttribute() public function getUserIdAttribute()
{ {
return sprintf('%02s-%04s',$this->site_id,$this->id); return sprintf('%02s-%04s',$this->site_id,$this->id);
@ -235,15 +256,15 @@ class User extends Authenticatable
public function role() public function role()
{ {
// If I have agents and no parent, I am the wholesaler // 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'; return 'wholesaler';
// If I have agents and a parent, I am a reseller // 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'; return 'reseller';
// If I have no agents and a parent, I am a customer // 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'; return 'customer';
} }
} }

View File

@ -75,7 +75,7 @@
@section('page-scripts') @section('page-scripts')
@js('/js/jqBootstrapValidation.js','jq-validation','jquery') @js('/js/jqBootstrapValidation.js','jq-validation','jquery')
<script> <script>
$(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } ); $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );
</script> </script>
<style> <style>
span.help-block > ul { span.help-block > ul {

View File

@ -11,23 +11,24 @@
<div class="box-body"> <div class="box-body">
@if ($user->all_accounts()->count()) @if ($user->all_accounts()->count())
<table class="table table-bordered table-striped table-hover" id="clients" style="width: 100%;"> <table class="table table-bordered table-striped table-hover" id="accounts" style="width: 100%;">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th>Profile</th>
<th>Name</th> <th>Name</th>
<th>Active</th> <th>Active</th>
<th>Services</th>
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<th>Count {{ $user->all_accounts()->count() }}</th> <th>Count {{ $user->all_accounts()->count() }}</th>
<th colspan="2">&nbsp;</th> <th colspan="3">&nbsp;</th>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@else @else
<p>No Clients Active</p> <p>No Accounts Active</p>
@endif @endif
</div> </div>
</div> </div>
@ -45,23 +46,25 @@
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#clients').DataTable( { $('#accounts').DataTable( {
responsive: true, responsive: true,
ajax: { ajax: {
url: "/api/r/accounts" url: "/api/r/accounts"
}, },
columns: [ columns: [
{ data: "id" }, { data: "switch_url" },
{ data: "company" }, { data: "company" },
{ data: "active_display" } { data: "active_display" },
{ data: "services_count_html" }
], ],
language: { language: {
emptyTable: "No Active Clients" emptyTable: "No Active Clients"
}, },
order: [1, 'asc'] order: [1, 'asc'],
pageLength: 25
}); });
$('#clients tbody').on('click','tr', function () { $('#accounts tbody').on('click','tr', function () {
$(this).toggleClass('selected'); $(this).toggleClass('selected');
}); });
}); });

View File

@ -0,0 +1,75 @@
<div class="box box-warning small">
<div class="box-header">
<h3 class="box-title">Clients</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
@if ($user->all_clients()->count())
<table class="table table-bordered table-striped table-hover" id="clients" style="width: 100%;">
<thead>
<tr>
<th>Profile</th>
<th>ID</th>
<th>Name</th>
<th>Active</th>
<th>Services</th>
<th>Level</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Count {{ $user->all_clients()->count() }}</th>
<th colspan="5">&nbsp;</th>
</tr>
</tfoot>
</table>
@else
<p>No Clients Active</p>
@endif
</div>
</div>
@section('page-scripts')
@css('https://cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css')
@css('https://cdn.datatables.net/rowgroup/1.0.2/css/rowGroup.dataTables.min.css')
@js('https://cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js')
@js('https://cdn.datatables.net/rowgroup/1.0.2/js/dataTables.rowGroup.min.js')
<style>
table.dataTable td {
outline: none;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#clients').DataTable( {
responsive: true,
ajax: {
url: "/api/r/clients"
},
columns: [
{ data: "switch_url" },
{ data: "user_id_url" },
{ data: "surfirstname" },
{ data: "active_display" },
{ data: "services_count_html" },
{ data: "level" }
],
language: {
emptyTable: "No Active Clients"
},
order: [2, 'asc']
});
$('#clients tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
});
</script>
@append

View File

@ -12,10 +12,13 @@
@endsection @endsection
@section('main-content') @section('main-content')
<div class="col-xs-6">
@include('r.accounts')
</div>
<div class="col-xs-6"> <div class="col-xs-6">
@include('r.agents') @include('r.agents')
</div> </div>
<div class="col-xs-6"> <div class="col-xs-6">
@include('r.accounts') @include('r.clients')
</div> </div>
@endsection @endsection

View File

@ -223,21 +223,21 @@
} }
</style> </style>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$("table#restripe").removeClass("table-striped"); $("table#restripe").removeClass("table-striped");
$("table#restripe tr:not(.visible-print)").each(function (index) { $("table#restripe tr:not(.visible-print)").each(function (index) {
$(this).toggleClass("stripe-odd", (index & 1)); $(this).toggleClass("stripe-odd", (index & 1));
$(this).toggleClass("stripe-even", !!(index & 1)); $(this).toggleClass("stripe-even", !!(index & 1));
}); });
$('tr[id="invoice-services"]').click(function() { $('tr[id="invoice-services"]').click(function() {
$(".invoice-services").toggleClass("visible-print"); $(".invoice-services").toggleClass("visible-print");
}); });
$('tr[id="invoice-service-items"]').click(function() { $('tr[id="invoice-service-items"]').click(function() {
$(".invoice-service-items").toggleClass("visible-print"); $(".invoice-service-items").toggleClass("visible-print");
}); });
}) })
</script> </script>
@append @append

View File

@ -22,6 +22,7 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
Route::group(['middleware'=>['auth:api','role:reseller']], function() { Route::group(['middleware'=>['auth:api','role:reseller']], function() {
Route::get('/r/agents','ResellerServicesController@agents'); Route::get('/r/agents','ResellerServicesController@agents');
Route::get('/r/accounts','ResellerServicesController@accounts'); Route::get('/r/accounts','ResellerServicesController@accounts');
Route::get('/r/clients','ResellerServicesController@clients');
}); });
Route::group(['middleware'=>'auth:api'], function() { Route::group(['middleware'=>'auth:api'], function() {