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 {
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,

View File

@ -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()];
}
}

View File

@ -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]);
}
}

View File

@ -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('<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()
{
$return = [];

View File

@ -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('<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
*
@ -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 <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()
{
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';
}
}

View File

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

View File

@ -11,23 +11,24 @@
<div class="box-body">
@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>
<tr>
<th>ID</th>
<th>Profile</th>
<th>Name</th>
<th>Active</th>
<th>Services</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Count {{ $user->all_accounts()->count() }}</th>
<th colspan="2">&nbsp;</th>
<th colspan="3">&nbsp;</th>
</tr>
</tfoot>
</table>
@else
<p>No Clients Active</p>
<p>No Accounts Active</p>
@endif
</div>
</div>
@ -45,23 +46,25 @@
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#clients').DataTable( {
$('#accounts').DataTable( {
responsive: true,
ajax: {
url: "/api/r/accounts"
},
columns: [
{ data: "id" },
{ data: "switch_url" },
{ data: "company" },
{ data: "active_display" }
{ data: "active_display" },
{ data: "services_count_html" }
],
language: {
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');
});
});

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
@section('main-content')
<div class="col-xs-6">
@include('r.accounts')
</div>
<div class="col-xs-6">
@include('r.agents')
</div>
<div class="col-xs-6">
@include('r.accounts')
@include('r.clients')
</div>
@endsection

View File

@ -223,21 +223,21 @@
}
</style>
<script>
$(document).ready(function() {
$("table#restripe").removeClass("table-striped");
$(document).ready(function() {
$("table#restripe").removeClass("table-striped");
$("table#restripe tr:not(.visible-print)").each(function (index) {
$(this).toggleClass("stripe-odd", (index & 1));
$(this).toggleClass("stripe-even", !!(index & 1));
});
$("table#restripe tr:not(.visible-print)").each(function (index) {
$(this).toggleClass("stripe-odd", (index & 1));
$(this).toggleClass("stripe-even", !!(index & 1));
});
$('tr[id="invoice-services"]').click(function() {
$(".invoice-services").toggleClass("visible-print");
});
$('tr[id="invoice-services"]').click(function() {
$(".invoice-services").toggleClass("visible-print");
});
$('tr[id="invoice-service-items"]').click(function() {
$(".invoice-service-items").toggleClass("visible-print");
});
})
$('tr[id="invoice-service-items"]').click(function() {
$(".invoice-service-items").toggleClass("visible-print");
});
})
</script>
@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::get('/r/agents','ResellerServicesController@agents');
Route::get('/r/accounts','ResellerServicesController@accounts');
Route::get('/r/clients','ResellerServicesController@clients');
});
Route::group(['middleware'=>'auth:api'], function() {