Removed many redundant functions from User::class

This commit is contained in:
Deon George 2022-04-21 16:25:29 +10:00
parent 796c72dd09
commit d53643ef55
25 changed files with 87 additions and 625 deletions

View File

@ -92,7 +92,7 @@ class HomeController extends Controller
public function service(Service $o): View public function service(Service $o): View
{ {
$breadcrumb = collect(); $breadcrumb = collect();
$breadcrumb->put($o->account->user->name,url('u/home',$o->account->user_id)); $breadcrumb->put($o->account->user->full_name,url('u/home',$o->account->user_id));
return View('u.service.home') return View('u.service.home')
->with('breadcrumb',$breadcrumb) ->with('breadcrumb',$breadcrumb)

View File

@ -1,39 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Account;
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 clients()
{
return ['data'=>Auth::user()->all_clients()->values()];
}
public function services(Request $request,Account $o)
{
return $o->services
->filter(function($item) use ($request) {
return $item->active || ($item->id == $request->include);
});
}
public function service_inactive()
{
return ['data'=>Auth::user()->all_client_service_inactive()->values()];
}
}

View File

@ -25,31 +25,31 @@ class SearchController extends Controller
if (! $request->input('term')) if (! $request->input('term'))
return $result; return $result;
$accounts = ($x=Auth::user()->all_accounts())->pluck('id'); $account_ids = ($x=Auth::user()->accounts)->pluck('id');
$users = $x->transform(function($item) { return $item->user;}); $user_ids = $x->transform(function($item) { return $item->user;})->pluck('id');
# Look for User # Look for User
foreach (User::Search($request->input('term')) foreach (User::Search($request->input('term'))
->whereIN('id',$users->pluck('id')) ->whereIN('id',$user_ids)
->orderBy('lastname') ->orderBy('lastname')
->orderBy('firstname') ->orderBy('firstname')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']); $result->push(['name'=>sprintf('%s %s',$o->sid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
} }
# Look for Account # Look for Account
foreach (Account::Search($request->input('term')) foreach (Account::Search($request->input('term'))
->whereIN('user_id',$users->pluck('id')) ->whereIN('user_id',$user_ids)
->orderBy('company') ->orderBy('company')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']); $result->push(['name'=>sprintf('%s %s',$o->sid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
} }
# Look for a Service # Look for a Service
foreach (Service::Search($request->input('term')) foreach (Service::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->orderBy('id') ->orderBy('id')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
@ -58,7 +58,7 @@ class SearchController extends Controller
# Look for an Invoice # Look for an Invoice
foreach (Invoice::Search($request->input('term')) foreach (Invoice::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->orderBy('id') ->orderBy('id')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
@ -67,7 +67,7 @@ class SearchController extends Controller
# Look for an Broadband Service # Look for an Broadband Service
foreach (Broadband::Search($request->input('term')) foreach (Broadband::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->orderBy('service_number') ->orderBy('service_number')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
@ -76,7 +76,7 @@ class SearchController extends Controller
# Look for an Phone Service # Look for an Phone Service
foreach (Phone::Search($request->input('term')) foreach (Phone::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->orderBy('service_number') ->orderBy('service_number')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
@ -85,7 +85,7 @@ class SearchController extends Controller
# Look for Domain Name # Look for Domain Name
foreach (Service\Domain::Search($request->input('term')) foreach (Service\Domain::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->orderBy('domain_name') ->orderBy('domain_name')
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
@ -95,7 +95,7 @@ class SearchController extends Controller
if (Gate::any(['wholesaler'],new Payment)) { if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments # Look for Payments
foreach (Payment::Search($request->input('term')) foreach (Payment::Search($request->input('term'))
->whereIN('account_id',$accounts) ->whereIN('account_id',$account_ids)
->limit(10)->get() as $o) ->limit(10)->get() as $o)
{ {
$result->push(['name'=>sprintf('%s ($%s)',$o->id,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']); $result->push(['name'=>sprintf('%s ($%s)',$o->id,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']);

View File

@ -131,24 +131,6 @@ class Account extends Model implements IDs
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'success' : 'danger',$this->active ? 'Active' : 'Inactive'); return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'success' : 'danger',$this->active ? 'Active' : 'Inactive');
} }
/**
* @deprecated use getAIDAttribute()
*/
public function getAccountIdAttribute()
{
abort(500,'deprecated');
return $this->getAIDAttribute();
}
/**
* @deprecated use getUrlAdminAttribute()
*/
public function getAccountIdUrlAttribute()
{
abort(500,'deprecated');
return $this->getUrlAdminAttribute();
}
/** /**
* Get the address for the account * Get the address for the account
* *
@ -163,17 +145,6 @@ class Account extends Model implements IDs
]; ];
} }
/**
* Return the Account Unique Identifier
* @return string
* @deprecated use getSIDAttribute()
*/
public function getAIDAttribute()
{
abort(500,'deprecated');
return $this->getSIDAttribute();
}
/** /**
* Return the account name * Return the account name
* *
@ -181,19 +152,7 @@ class Account extends Model implements IDs
*/ */
public function getNameAttribute(): string public function getNameAttribute(): string
{ {
return $this->company ?: ($this->user_id ? $this->user->SurFirstName : 'AID:'.$this->id); return $this->company ?: ($this->user_id ? $this->user->getSurFirstNameAttribute() : 'LID:'.$this->id);
}
public function getServicesCountHtmlAttribute()
{
abort(500,'deprecated');
return sprintf('%s <small>/%s</small>',$this->services()->noEagerLoads()->where('active',TRUE)->count(),$this->services()->noEagerLoads()->count());
}
public function getSwitchUrlAttribute()
{
abort(500,'deprecated');
return sprintf('<a href="/r/switch/start/%s"><i class="fas fa-external-link-alt"></i></a>',$this->user_id);
} }
public function getTypeAttribute() public function getTypeAttribute()
@ -205,6 +164,7 @@ class Account extends Model implements IDs
* Return the Admin URL to manage the account * Return the Admin URL to manage the account
* *
* @return string * @return string
* @deprecated
*/ */
public function getUrlAdminAttribute(): string public function getUrlAdminAttribute(): string
{ {
@ -216,6 +176,7 @@ class Account extends Model implements IDs
* Return the User URL to manage the account * Return the User URL to manage the account
* *
* @return string * @return string
* @deprecated
*/ */
public function getUrlUserAttribute(): string public function getUrlUserAttribute(): string
{ {

View File

@ -26,7 +26,7 @@ class AccountPolicy
OR $uo->isWholesaler() OR $uo->isWholesaler()
// The user is the reseller // The user is the reseller
OR ($uo->all_accounts()->pluck('id')->search($ao->id) !== FALSE); OR $uo->isReseller();
} }
/** /**

View File

@ -26,7 +26,7 @@ class InvoicePolicy
OR $uo->isWholesaler() OR $uo->isWholesaler()
// The user is the reseller // The user is the reseller
OR ($uo->all_accounts()->pluck('id')->search($io->account_id) !== FALSE); OR $uo->isReseller();
} }
/** /**

View File

@ -26,7 +26,7 @@ class ServicePolicy
OR $uo->isWholesaler() OR $uo->isWholesaler()
// The user is the reseller // The user is the reseller
OR ($uo->all_accounts()->pluck('id')->search($so->account_id) !== FALSE); OR $uo->isReseller();
} }
/** /**

View File

@ -26,7 +26,7 @@ class UserPolicy
OR $uo->isWholesaler() OR $uo->isWholesaler()
// The user is the reseller // The user is the reseller
OR ($uo->all_clients()->pluck('id')->search($o->id) !== FALSE); OR $uo->isReseller();
} }
/** /**

View File

@ -49,17 +49,6 @@ class Service extends Model implements IDs
{ {
use HasFactory,ScopeServiceUserAuthorised; use HasFactory,ScopeServiceUserAuthorised;
protected $appends = [
'account_name',
'admin_service_id_url',
'billing_price',
'name_short',
'next_invoice',
'service_id',
'service_id_url',
'status',
];
protected $casts = [ protected $casts = [
'order_info'=>AsCollection::class, 'order_info'=>AsCollection::class,
]; ];
@ -71,35 +60,12 @@ class Service extends Model implements IDs
'stop_at', 'stop_at',
]; ];
protected $visible = [
'account_name',
'admin_service_id_url',
'active',
'billing_price',
'data_orig',
'id',
'name_short',
'next_invoice',
'product_category',
'product_name',
'service_id',
'service_id_url',
'status',
];
protected $with = [ protected $with = [
'invoice_items', 'invoice_items',
'product.type.supplied', 'product.type.supplied',
'type', 'type',
]; ];
// @todo Change to self::INACTIVE_STATUS
private $inactive_status = [
'CANCELLED',
'ORDER-REJECTED',
'ORDER-CANCELLED',
];
public const INACTIVE_STATUS = [ public const INACTIVE_STATUS = [
'CANCELLED', 'CANCELLED',
'ORDER-REJECTED', 'ORDER-REJECTED',
@ -406,7 +372,7 @@ class Service extends Model implements IDs
{ {
return $query->where(function () use ($query) { return $query->where(function () use ($query) {
$query->where($this->getTable().'.active',TRUE) $query->where($this->getTable().'.active',TRUE)
->orWhereNotIn('order_status',$this->inactive_status); ->orWhereNotIn('order_status',self::INACTIVE_STATUS);
}); });
} }
@ -420,7 +386,7 @@ class Service extends Model implements IDs
{ {
return $query->where(function () use ($query) { return $query->where(function () use ($query) {
$query->where($this->getTable().'.active',FALSE) $query->where($this->getTable().'.active',FALSE)
->orWhereIn('order_status',$this->inactive_status); ->orWhereIn('order_status',self::INACTIVE_STATUS);
}); });
} }
@ -459,14 +425,6 @@ class Service extends Model implements IDs
return $this->account->name; return $this->account->name;
} }
/**
* @deprecated Use getUrlAdminAttribute()
*/
public function getAdminServiceIdUrlAttribute()
{
return $this->getUrlAdminAttribute();
}
/** /**
* Return the auto billing details * Return the auto billing details
* *
@ -1170,7 +1128,7 @@ class Service extends Model implements IDs
public function getStageParameters(string $stage): Collection public function getStageParameters(string $stage): Collection
{ {
$result = Arr::get(self::ACTION_PROGRESS,$stage); $result = Arr::get(self::ACTION_PROGRESS,$stage);
$myrole = array_search(Auth::user()->role(),User::$role_order); $myrole = array_search(Auth::user()->role(),User::role_order);
// If we have no valid next stage, return an empty collection. // If we have no valid next stage, return an empty collection.
if (($myrole === FALSE) || (! $result)) if (($myrole === FALSE) || (! $result))
@ -1185,7 +1143,7 @@ class Service extends Model implements IDs
$cando = FALSE; $cando = FALSE;
foreach ($roles as $role) { foreach ($roles as $role) {
if ($myrole <= array_search($role,User::$role_order)) { if ($myrole <= array_search($role,User::role_order)) {
$cando = TRUE; $cando = TRUE;
break; break;
@ -1234,14 +1192,14 @@ class Service extends Model implements IDs
} }
/** /**
* Determine if a service is active. It is active, if active=1, or the order_status is not in inactive_status[] * Determine if a service is active. It is active, if active=1, or the order_status is not in self::INACTIVE_STATUS[]
* *
* @return bool * @return bool
* @todo Remove active and have order_status reflect whether active or not * @todo Remove active and have order_status reflect whether active or not
*/ */
public function isActive(): bool public function isActive(): bool
{ {
return $this->active OR ($this->order_status AND ! in_array($this->order_status,$this->inactive_status)); return $this->active OR ($this->order_status AND ! in_array($this->order_status,self::INACTIVE_STATUS));
} }
/** /**
@ -1323,7 +1281,7 @@ class Service extends Model implements IDs
{ {
return ! $this->active return ! $this->active
AND ! is_null($this->order_status) AND ! is_null($this->order_status)
AND ! in_array($this->order_status,array_merge($this->inactive_status,['INACTIVE'])); AND ! in_array($this->order_status,array_merge(self::INACTIVE_STATUS,['INACTIVE']));
} }
/** /**
@ -1464,6 +1422,6 @@ class Service extends Model implements IDs
*/ */
public function wasCancelled(): bool public function wasCancelled(): bool
{ {
return in_array($this->order_status,$this->inactive_status); return in_array($this->order_status,self::INACTIVE_STATUS);
} }
} }

View File

@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Laravel\Passport\HasApiTokens; use Laravel\Passport\HasApiTokens;
use Leenooks\Carbon; use Leenooks\Traits\ScopeActive;
use Leenooks\Traits\UserSwitch; use Leenooks\Traits\UserSwitch;
use App\Notifications\ResetPassword as ResetPasswordNotification; use App\Notifications\ResetPassword as ResetPasswordNotification;
@ -25,7 +25,7 @@ use App\Traits\{QueryCacheableConfig,SiteID};
*/ */
class User extends Authenticatable class User extends Authenticatable
{ {
use HasFactory,HasApiTokens,Notifiable,UserSwitch,QueryCacheableConfig,SiteID; use HasFactory,HasApiTokens,Notifiable,UserSwitch,QueryCacheableConfig,SiteID,ScopeActive;
private const CACHE_TIME = 3600; private const CACHE_TIME = 3600;
@ -41,7 +41,9 @@ class User extends Authenticatable
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'password', 'name',
'email',
'password',
]; ];
/** /**
@ -56,14 +58,27 @@ class User extends Authenticatable
/** /**
* Role hierarchy order * Role hierarchy order
*
* @var array * @var array
*/ */
public static $role_order = [ public const role_order = [
'wholesaler', 'wholesaler',
'reseller', 'reseller',
'customer', 'customer',
]; ];
/* OVERRIDES */
/**
* Users password reset email notification
*
* @param string $token
*/
public function sendPasswordResetNotification($token)
{
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
}
/* RELATIONS */ /* RELATIONS */
/** /**
@ -81,23 +96,14 @@ class User extends Authenticatable
} }
/** /**
* The agents that this users manages * This users invoices
* *
* @return \Illuminate\Database\Eloquent\Relations\HasMany * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/ */
public function agents() { public function invoices()
return $this->hasMany(static::class,'parent_id','id')->with('agents'); {
} return $this->hasManyThrough(Invoice::class,Account::class)
->active();
/**
* The clients that this user has
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function clients() {
return $this
->hasMany(static::class,'parent_id','id')
->with('clients');
} }
/** /**
@ -110,17 +116,6 @@ class User extends Authenticatable
return $this->belongsTo(Language::class); return $this->belongsTo(Language::class);
} }
/**
* This users invoices
*
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public function invoices()
{
return $this->hasManyThrough(Invoice::class,Account::class)
->active();
}
/** /**
* The payments this user has made * The payments this user has made
* *
@ -153,41 +148,16 @@ class User extends Authenticatable
->active(); ->active();
} }
/**
* The site this user is configured to access
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function site()
{
return $this->belongsTo(Site::class);
}
/**
* This users supplier/reseller
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
protected function supplier()
{
return $this->belongsTo(static::class,'parent_id','id');
}
/**
* Who this user supplies to
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
protected function suppliers() {
return $this->hasMany(static::class,'parent_id','id');
}
/* ATTRIBUTES */ /* ATTRIBUTES */
public function getActiveDisplayAttribute($value) /**
* This is an alias method, as it is used by the framework
*
* @return string
*/
public function getNameAttribute(): string
{ {
abort(500,'deprecated:'.__METHOD__); return $this->getFullNameAttribute();
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'primary' : 'danger',$this->active ? 'Active' : 'Inactive');
} }
/** /**
@ -200,35 +170,6 @@ class User extends Authenticatable
return sprintf('%s %s',$this->firstname,$this->lastname); return sprintf('%s %s',$this->firstname,$this->lastname);
} }
/**
* A list of all invoices currently unpaid
*
* @return mixed
*/
public function getInvoicesDueAttribute()
{
return $this->invoices
->where('active',TRUE)
->sortBy('id')
->transform(function ($item) { if ($item->due > 0) return $item; })
->reverse()
->filter();
}
/**
* Return a Carbon Date if it has a value.
*
* @param $value
* @return Carbon
* @throws \Exception
* @todo This attribute is not in the schema
*/
public function getLastAccessAttribute($value)
{
if (! is_null($value))
return new Carbon($value);
}
/** /**
* Return my accounts * Return my accounts
* *
@ -239,28 +180,6 @@ class User extends Authenticatable
return $this->accounts->where('user_id',$this->id); return $this->accounts->where('user_id',$this->id);
} }
/**
* @deprecated Use static::getFullNameAttribute()
* @return mixed
*/
public function getNameAttribute()
{
return $this->full_name;
}
/**
* Return a list of the payments that the user has made
*
* @return mixed
* @todo Merge this with payments()
*/
public function getPaymentHistoryAttribute()
{
return $this->payments
->sortBy('payment_date')
->reverse();
}
/** /**
* Return a friendly string of this persons role * Return a friendly string of this persons role
* @return string * @return string
@ -270,61 +189,18 @@ class User extends Authenticatable
return ucfirst($this->role()); return ucfirst($this->role());
} }
public function getServicesCountHtmlAttribute()
{
abort(500,'deprecated:'.__METHOD__);
return sprintf('%s <small>/%s</small>',$this->services->where('active',TRUE)->count(),$this->services->count());
}
public function getSurFirstNameAttribute() public function getSurFirstNameAttribute()
{ {
return sprintf('%s, %s',$this->lastname,$this->firstname); return sprintf('%s, %s',$this->lastname,$this->firstname);
} }
public function getSwitchUrlAttribute()
{
abort(500,'deprecated:'.__METHOD__);
return sprintf('<a href="/a/switch/start/%s"><i class="fas fa-external-link-alt"></i></a>',$this->id);
}
public function getUserIdAttribute()
{
abort(500,'deprecated:'.__METHOD__);
return sprintf('%02s-%04s',$this->site_id,$this->id);
}
public function getUserIdUrlAttribute()
{
abort(500,'deprecated:'.__METHOD__);
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->user_id);
}
/* METHODS */
/**
* Users password reset email notification
*
* @param string $token
*/
public function sendPasswordResetNotification($token)
{
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
}
/* SCOPES */ /* SCOPES */
// @todo use trait
public function scopeActive()
{
return $this->where('active',TRUE);
}
/** /**
* Search for a record * Search for a record
* *
* @param $query * @param $query
* @param string $term * @param string $term
* @return
*/ */
public function scopeSearch($query,string $term) public function scopeSearch($query,string $term)
{ {
@ -358,120 +234,6 @@ class User extends Authenticatable
/* METHODS */ /* METHODS */
/**
* Determine if the user is an admin of the user with $id
*
* @param $id
* @return bool
*/
public function isAdmin($id): bool
{
return $id AND $this->isReseller() AND $this->accounts->pluck('user_id')->contains($id);
}
/**
* Get a list of accounts for the clients of this user
*
* @return DatabaseCollection
* @deprecated Use rtm_accounts()
*/
public function all_accounts(): DatabaseCollection
{
throw new \Exception('deprecated');
abort(500,'deprecated:'.__METHOD__);
$result = new DatabaseCollection();
$clients = $this->all_clients();
foreach ($clients->pluck('accounts') as $accounts) {
foreach ($accounts as $o) {
if (! $o->active)
continue;
$result->push($o);
}
}
// Include my accounts
foreach ($this->accounts as $o) {
if (! $o->active)
continue;
$result->push($o);
}
$result->load('user.accounts');
return $result;
}
/**
* Get a list of clients that this user is responsible for.
*
* @param int $level
* @param DatabaseCollection|null $clients
* @return DatabaseCollection
* @deprecated Use rtm_accounts() to determine this
*/
public function all_clients($level=0,DatabaseCollection $clients=NULL): DatabaseCollection
{
$result = is_null($clients) ? $this->clients : $clients;
$result
->filter(function($item) { return $item->active; })
->transform(function($item) use ($level) { $item->level = $level; return $item; });
foreach ($result->pluck('clients') as $clients) {
foreach ($this->all_clients($level+1,$clients) as $o) {
if (! $o->active)
continue;
$result->push($o);
}
}
return $result;
}
/**
* @return mixed
* @deprecated Use rtm_accounts() to determine this list
*/
public function all_client_service_inactive()
{
$s = Service::InActive();
$aa = $this->all_accounts()->pluck('id')->unique()->toArray();
return $s->get()->filter(function($item) use ($aa) {
return in_array($item->account_id,$aa);
});
}
/**
* List of all this users agents, recursively
*
* @param int $level
* @return Collection
* @deprecated Use rtm_accounts()
*/
public function all_agents($level=0)
{
$result = collect();
foreach ($this->agents as $o) {
if (! $o->active OR ! $o->agents->count())
continue;
$o->level = $level;
$result->push($o);
// Include agents of agents
$result->push($o->all_agents($level+1));
}
return $result->flatten();
}
/** /**
* Show this user's clients with service movements * Show this user's clients with service movements
* *
@ -488,6 +250,17 @@ class User extends Authenticatable
->get(); ->get();
} }
/**
* Determine if the user is an admin of the user with $id
*
* @param $id
* @return bool
*/
public function isAdmin($id): bool
{
return $id AND $this->isReseller() AND $this->accounts->pluck('user_id')->contains($id);
}
/** /**
* Determine if the logged in user is a reseller or wholesaler * Determine if the logged in user is a reseller or wholesaler
* *
@ -649,33 +422,6 @@ class User extends Authenticatable
->from($summary,'summary'); ->from($summary,'summary');
} }
public function query_payment_summary()
{
$payment = (new Payment)
->select([
DB::raw('payment_id AS id'),
DB::raw('SUM(allocate) AS allocate'),
])
->from($this->query_payment_items(),'PI')
//->where('payments.active',TRUE) // @todo To implement
->groupBy(['payment_id']);
return (new Payment)
->select([
DB::raw('payments.id AS id'),
'date_orig',
'payment_date',
'total_amt',
//'fees_amt',
DB::raw('total_amt-allocate AS balance'),
])
->rightJoin('payments',['payments.id'=>'summary.id'])
//->where('payments.active',TRUE) // @todo To implement
->whereIN('account_id',$this->all_accounts()->pluck('id')->unique()->toArray())
->from($payment,'summary');
}
/** /**
* Determine what the logged in user's role is * Determine what the logged in user's role is
* + Wholesaler - aka Super User * + Wholesaler - aka Super User

View File

@ -5,8 +5,8 @@ Please order the following...
| Service | Details | | Service | Details |
| :---------- | :---------------- | | :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} | | Logged User | {{ Auth::user()->id }} |
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) | | Account | {{ $service->account_name }} |
| Service ID | {!! $service->service_id_url !!} | | Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} | | Product | {{ $service->product_name }} |
@switch($service->product_category) @switch($service->product_category)
@case('BROADBAND') @case('BROADBAND')

View File

@ -6,8 +6,8 @@
@component('mail::table') @component('mail::table')
| Service | Details | | Service | Details |
| :---------- | :---------------- | | :---------- | :---------------- |
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) | | Account | {{ $service->account_name }} |
| Service ID | {!! $service->service_id_url !!} | | Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} | | Product | {{ $service->product_name }} |
@switch($service->category) @switch($service->category)
@case('BROADBAND') @case('BROADBAND')

View File

@ -5,8 +5,8 @@ Please cancel the following...
| Service | Details | | Service | Details |
| :---------- | :---------------- | | :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} | | Logged User | {{ Auth::user()->id }} |
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) | | Account | {{ $service->account_name }} |
| Service ID | {!! $service->service_id_url !!} | | Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} | | Product | {{ $service->product_name }} |
@switch($service->product_category) @switch($service->product_category)
@case('BROADBAND') @case('BROADBAND')

View File

@ -5,8 +5,8 @@ Please change the following...
| Service | Details | | Service | Details |
| :---------- | :---------------- | | :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} | Logged User | {{ Auth::user()->id }}
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) | | Account | {{ $service->account_name }} |
| Service ID | {!! $service->service_id_url !!} | | Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} | | Product | {{ $service->product_name }} |
@switch($service->product_category) @switch($service->product_category)
@case('BROADBAND') @case('BROADBAND')

View File

@ -1,5 +1,5 @@
@component('mail::message',['site'=>$site,'heading'=>'Traffic Mismatch: '.$date]) @component('mail::message',['site'=>$site,'heading'=>'Traffic Mismatch: '.$date])
Hi {{ isset($user) ? $user->name.',' : '' }} Hi {{ isset($user) ? $user->full_name.',' : '' }}
The traffic import today, had mismatching records. A request to have those login removed has been generated. The traffic import today, had mismatching records. A request to have those login removed has been generated.

View File

@ -1,5 +1,5 @@
@component('mail::message',['site'=>$site,'heading'=>'Link Your Account']) @component('mail::message',['site'=>$site,'heading'=>'Link Your Account'])
Hi {{ isset($user) ? $user->name.',' : '' }} Hi {{ isset($user) ? $user->full_name.',' : '' }}
A request was made to link your account to a social login. A request was made to link your account to a social login.
If you didnt make this request, you can ignore this, and the request will be ignored. If you didnt make this request, you can ignore this, and the request will be ignored.

View File

@ -1,5 +1,5 @@
@component('mail::message',['site'=>$site,'heading'=>'System Test Email']) @component('mail::message',['site'=>$site,'heading'=>'System Test Email'])
Hi {{ isset($user) ? $user->name.',' : '' }} Hi {{ isset($user) ? $user->full_name.',' : '' }}
This is just a test email to validate that you can receive emails from us. This is just a test email to validate that you can receive emails from us.

View File

@ -1,5 +1,5 @@
@component('mail::message',['site'=>$site,'heading'=>'Invoice: '.$invoice->id]) @component('mail::message',['site'=>$site,'heading'=>'Invoice: '.$invoice->id])
Hi {{ isset($user) ? $user->name.',' : '' }} Hi {{ isset($user) ? $user->full_name.',' : '' }}
A new invoice has been generated on your account. A summary of that invoice is below. A new invoice has been generated on your account. A summary of that invoice is below.

View File

@ -1,5 +1,5 @@
@component('mail::message',['site'=>$site,'heading'=>'Password Reset']) @component('mail::message',['site'=>$site,'heading'=>'Password Reset'])
Hi {{ isset($user) ? $user->name.',' : '' }} Hi {{ isset($user) ? $user->full_name.',' : '' }}
You are receiving this email because we received a password reset request for your account. You are receiving this email because we received a password reset request for your account.

View File

@ -1,67 +0,0 @@
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title">Agents</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_agents()->count())
<table class="table table-bordered table-striped table-hover" id="agents" style="width: 100%;">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Level</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Count {{ $user->all_agents()->count() }}</th>
<th colspan="2">&nbsp;</th>
</tr>
</tfoot>
</table>
@else
<p>No Agents Active</p>
@endif
</div>
</div>
@section('page-scripts')
@css(datatables,bootstrap4|rowgroup)
@js(datatables,bootstrap4|rowgroup)
<style>
table.dataTable td {
outline: none;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#agents').DataTable( {
responsive: true,
ajax: {
url: "/api/r/agents"
},
columns: [
{ data: "user_id_url" },
{ data: "surfirstname" },
{ data: "level" }
],
language: {
emptyTable: "No Active Agents"
},
order: [1, 'asc']
});
$('#agents tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
});
</script>
@append

View File

@ -1,73 +0,0 @@
<div class="box box-warning">
<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(datatables,bootstrap4|rowgroup)
@js(datatables,bootstrap4|rowgroup)
<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

@ -7,12 +7,4 @@
@include('r.invoice.widgets.due') @include('r.invoice.widgets.due')
</div> </div>
{{--
<div class="col-xs-6">
@include('r.agents')
</div>
<div class="col-xs-6">
@include('r.clients')
</div>
--}}
</div> </div>

View File

@ -16,7 +16,7 @@
<table class="table table-sm"> <table class="table table-sm">
<tr> <tr>
<th>Account</th> <th>Account</th>
<td><a href="{{url('u/home/',$o->account->user_id)}}">{{ $o->account->aid }}</a></td> <td><a href="{{url('u/home/',$o->account->user_id)}}">{{ $o->account->sid }}</a></td>
</tr> </tr>
<tr> <tr>
<th>Status</th> <th>Status</th>

View File

@ -51,7 +51,7 @@
<label for="account_id">Client Account</label> <label for="account_id">Client Account</label>
<select class="form-control" id="account_id" name="account_id"> <select class="form-control" id="account_id" name="account_id">
<option value="">&nbsp;</option> <option value="">&nbsp;</option>
@foreach ($user->all_accounts()->sortBy('name') as $o) @foreach ($user->accounts->sortBy('name') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option> <option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option>
@endforeach @endforeach
</select> </select>

View File

@ -1,9 +1,6 @@
<?php <?php
use App\Http\Controllers\{AdminController, use App\Http\Controllers\{CheckoutController,ProductController};
CheckoutController,
ProductController,
ResellerServicesController};
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -21,19 +18,6 @@ Route::group(['middleware'=>['auth:api','role:wholesaler']], function() {
Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']); Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']);
}); });
// Reseller API calls
Route::group(['middleware'=>['auth:api','role:reseller']], function() {
// Route::get('/r/agents','ResellerServicesController@agents');
Route::get('/r/accounts',[ResellerServicesController::class,'accounts']);
Route::get('/r/services/{o}',[ResellerServicesController::class,'services'])
->where('o','[0-9]+');
// Route::get('/r/clients','ResellerServicesController@clients');
// Route::get('/r/service_inactive','ResellerServicesController@service_inactive');
Route::post('r/invoices/{o}',[AdminController::class,'pay_invoices'])
->where('o','[0-9]+')
->middleware(['theme:adminlte-be','role:wholesaler']);
});
Route::group(['middleware'=>'auth:api'], function() { Route::group(['middleware'=>'auth:api'], function() {
Route::post('/u/checkout/fee/{o}',[CheckoutController::class,'fee']) Route::post('/u/checkout/fee/{o}',[CheckoutController::class,'fee'])
->where('o','[0-9]+'); ->where('o','[0-9]+');