Next/Future invoices for users
This commit is contained in:
parent
b61e00d80f
commit
eb316f65fc
@ -27,7 +27,7 @@ class SearchController extends Controller
|
|||||||
$accounts = ($x=Auth::user()->all_accounts())->pluck('id');
|
$accounts = ($x=Auth::user()->all_accounts())->pluck('id');
|
||||||
$users = $x->transform(function($item) { return $item->user;});
|
$users = $x->transform(function($item) { return $item->user;});
|
||||||
|
|
||||||
# Look for Account
|
# Look for User
|
||||||
foreach (User::Search($request->input('term'))
|
foreach (User::Search($request->input('term'))
|
||||||
->whereIN('id',$users->pluck('id'))
|
->whereIN('id',$users->pluck('id'))
|
||||||
->orderBy('lastname')
|
->orderBy('lastname')
|
||||||
@ -37,6 +37,15 @@ class SearchController extends Controller
|
|||||||
$result->push(['label'=>sprintf('US:%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id]);
|
$result->push(['label'=>sprintf('US:%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Look for Account
|
||||||
|
foreach (Account::Search($request->input('term'))
|
||||||
|
->whereIN('user_id',$users->pluck('id'))
|
||||||
|
->orderBy('company')
|
||||||
|
->limit(10)->get() as $o)
|
||||||
|
{
|
||||||
|
$result->push(['label'=>sprintf('AC:%s %s',$o->aid,$o->company),'value'=>'/u/home/'.$o->user_id]);
|
||||||
|
}
|
||||||
|
|
||||||
# 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',$accounts)
|
||||||
|
@ -24,8 +24,11 @@ class UserHomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function home(User $o=NULL): View
|
public function home(User $o=NULL): View
|
||||||
{
|
{
|
||||||
if (is_null($o))
|
if ($o)
|
||||||
$o = Auth::user();
|
return View('u.home',['o'=>$o]);
|
||||||
|
|
||||||
|
// If User was null, then test and see what type of logged on user we have
|
||||||
|
$o = Auth::user();
|
||||||
|
|
||||||
switch (Auth::user()->role()) {
|
switch (Auth::user()->role()) {
|
||||||
case 'customer':
|
case 'customer':
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\User;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
use App\Traits\NextKey;
|
use App\Traits\NextKey;
|
||||||
@ -10,9 +9,7 @@ use App\Traits\NextKey;
|
|||||||
class Account extends Model
|
class Account extends Model
|
||||||
{
|
{
|
||||||
use NextKey;
|
use NextKey;
|
||||||
|
|
||||||
const RECORD_ID = 'account';
|
const RECORD_ID = 'account';
|
||||||
|
|
||||||
public $incrementing = FALSE;
|
public $incrementing = FALSE;
|
||||||
|
|
||||||
protected $table = 'ab_account';
|
protected $table = 'ab_account';
|
||||||
|
@ -8,7 +8,7 @@ class Invoice extends Model
|
|||||||
{
|
{
|
||||||
protected $table = 'ab_invoice';
|
protected $table = 'ab_invoice';
|
||||||
protected $dates = ['date_orig','due_date'];
|
protected $dates = ['date_orig','due_date'];
|
||||||
protected $with = ['account.country.currency','items','paymentitems'];
|
protected $with = ['account.country.currency','items.taxes','paymentitems'];
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'date_due',
|
'date_due',
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
use Leenooks\Carbon;
|
use Leenooks\Carbon;
|
||||||
|
|
||||||
class InvoiceItem extends Model
|
class InvoiceItem extends Model
|
||||||
@ -11,7 +13,6 @@ class InvoiceItem extends Model
|
|||||||
protected $dates = ['date_start','date_stop'];
|
protected $dates = ['date_start','date_stop'];
|
||||||
public $dateFormat = 'U';
|
public $dateFormat = 'U';
|
||||||
protected $table = 'ab_invoice_item';
|
protected $table = 'ab_invoice_item';
|
||||||
protected $with = ['taxes'];
|
|
||||||
|
|
||||||
private $_tax = 0;
|
private $_tax = 0;
|
||||||
|
|
||||||
@ -20,6 +21,11 @@ class InvoiceItem extends Model
|
|||||||
return $this->belongsTo(Invoice::class);
|
return $this->belongsTo(Invoice::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product for this item
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
public function product()
|
public function product()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Product::class);
|
return $this->belongsTo(Product::class);
|
||||||
@ -131,13 +137,13 @@ class InvoiceItem extends Model
|
|||||||
/**
|
/**
|
||||||
* Add taxes to this record
|
* Add taxes to this record
|
||||||
*/
|
*/
|
||||||
public function addTaxes()
|
public function addTaxes(Collection $taxes)
|
||||||
{
|
{
|
||||||
// Refuse to change an existing record
|
// Refuse to change an existing record
|
||||||
if ($this->exists)
|
if ($this->exists)
|
||||||
throw new \Exception('Refusing to add Taxes to existing record');
|
throw new \Exception('Refusing to add Taxes to existing record');
|
||||||
|
|
||||||
foreach($this->service->account->country->taxes as $to)
|
foreach($taxes as $to)
|
||||||
{
|
{
|
||||||
$iit = new InvoiceItemTax;
|
$iit = new InvoiceItemTax;
|
||||||
$iit->tax_id = $to->id;
|
$iit->tax_id = $to->id;
|
||||||
|
@ -191,9 +191,6 @@ class Service extends Model
|
|||||||
*/
|
*/
|
||||||
public function type()
|
public function type()
|
||||||
{
|
{
|
||||||
if (! $this->model)
|
|
||||||
abort(500,'Missing Model in',['service'=>$this]);
|
|
||||||
|
|
||||||
return $this->morphTo(null,'model','id','service_id');
|
return $this->morphTo(null,'model','id','service_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,7 +769,7 @@ class Service extends Model
|
|||||||
$o->date_stop = $this->invoice_next_end;
|
$o->date_stop = $this->invoice_next_end;
|
||||||
$o->quantity = $this->invoice_next_quantity;
|
$o->quantity = $this->invoice_next_quantity;
|
||||||
|
|
||||||
$o->addTaxes();
|
$o->addTaxes($this->account->country->taxes);
|
||||||
$result->push($o);
|
$result->push($o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,7 +786,7 @@ class Service extends Model
|
|||||||
$o->date_stop = $this->invoice_next;
|
$o->date_stop = $this->invoice_next;
|
||||||
$o->quantity = 1;
|
$o->quantity = 1;
|
||||||
|
|
||||||
$o->addTaxes();
|
$o->addTaxes($this->account->country->taxes);
|
||||||
$result->push($o);
|
$result->push($o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,7 +804,7 @@ class Service extends Model
|
|||||||
$o->module_id = 30; // @todo This shouldnt be hard coded
|
$o->module_id = 30; // @todo This shouldnt be hard coded
|
||||||
$o->module_ref = $oo->id;
|
$o->module_ref = $oo->id;
|
||||||
|
|
||||||
$o->addTaxes();
|
$o->addTaxes($this->account->country->taxes);
|
||||||
$result->push($o);
|
$result->push($o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class Adsl extends ServiceType implements ServiceItem
|
|||||||
*/
|
*/
|
||||||
public function getServiceDescriptionAttribute(): string
|
public function getServiceDescriptionAttribute(): string
|
||||||
{
|
{
|
||||||
return $this->service_address ?: 'NO Service Address';
|
return strtoupper($this->service_address) ?: 'NO Service Address';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,24 +2,33 @@
|
|||||||
|
|
||||||
namespace App\Models\Service;
|
namespace App\Models\Service;
|
||||||
|
|
||||||
|
use App\Interfaces\ServiceItem;
|
||||||
|
use App\Models\Base\ServiceType;
|
||||||
use App\Traits\NextKey;
|
use App\Traits\NextKey;
|
||||||
|
|
||||||
class Voip extends \App\Models\Base\ServiceType
|
class Voip extends ServiceType implements ServiceItem
|
||||||
{
|
{
|
||||||
use NextKey;
|
use NextKey;
|
||||||
|
|
||||||
const RECORD_ID = 'service__adsl';
|
const RECORD_ID = 'service__adsl';
|
||||||
|
|
||||||
protected $table = 'ab_service__voip';
|
protected $table = 'ab_service__voip';
|
||||||
|
|
||||||
public function getFullNameAttribute()
|
/**
|
||||||
|
* Return the service address
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getServiceDescriptionAttribute(): string
|
||||||
{
|
{
|
||||||
return ($this->service_number AND $this->service_address)
|
return $this->service_address ?: 'VOIP';
|
||||||
? sprintf('%s: %s',$this->service_number, $this->service_address)
|
|
||||||
: $this->name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNameAttribute()
|
/**
|
||||||
|
* Return the service number
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getServiceNameAttribute(): string
|
||||||
{
|
{
|
||||||
return $this->service_number;
|
return $this->service_number;
|
||||||
}
|
}
|
||||||
|
208
app/User.php
208
app/User.php
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use App\Models\Site;
|
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@ -12,32 +11,38 @@ use Laravel\Passport\HasApiTokens;
|
|||||||
use Leenooks\Carbon;
|
use Leenooks\Carbon;
|
||||||
use Leenooks\Traits\UserSwitch;
|
use Leenooks\Traits\UserSwitch;
|
||||||
use App\Notifications\ResetPassword as ResetPasswordNotification;
|
use App\Notifications\ResetPassword as ResetPasswordNotification;
|
||||||
|
use App\Models\Site;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
use Spinen\QuickBooks\HasQuickBooksToken;
|
use Spinen\QuickBooks\HasQuickBooksToken;
|
||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasApiTokens,Notifiable,UserSwitch,HasQuickBooksToken;
|
use HasApiTokens,Notifiable,UserSwitch,HasQuickBooksToken;
|
||||||
|
|
||||||
protected $dates = ['created_at','updated_at','last_access'];
|
protected $dates = [
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'last_access'
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'email', 'password',
|
'name', 'email', 'password',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be hidden for arrays.
|
* The attributes that should be hidden for arrays.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password', 'remember_token',
|
'password',
|
||||||
];
|
'remember_token',
|
||||||
|
];
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'active_display',
|
'active_display',
|
||||||
@ -57,49 +62,92 @@ class User extends Authenticatable
|
|||||||
'user_id_url',
|
'user_id_url',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The accounts that this user manages
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
public function accounts()
|
public function accounts()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Models\Account::class);
|
return $this->hasMany(Models\Account::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The agents that this users manages
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
public function agents() {
|
public function agents() {
|
||||||
return $this->hasMany(static::class,'parent_id','id')->with('agents');
|
return $this->hasMany(static::class,'parent_id','id')->with('agents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The clients that this user has
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
public function clients() {
|
public function clients() {
|
||||||
return $this->hasMany(static::class,'parent_id','id')->with('clients');
|
return $this
|
||||||
|
->hasMany(static::class,'parent_id','id')
|
||||||
|
->with('clients');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This users language configuration
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
public function language()
|
public function language()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Models\Language::class);
|
return $this->belongsTo(Models\Language::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**b
|
||||||
|
* This users invoices
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||||
|
*/
|
||||||
public function invoices()
|
public function invoices()
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Models\Invoice::class,Models\Account::class);
|
return $this->hasManyThrough(Models\Invoice::class,Models\Account::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payments this user has made
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||||
|
*/
|
||||||
public function payments()
|
public function payments()
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Models\Payment::class,Models\Account::class);
|
return $this->hasManyThrough(Models\Payment::class,Models\Account::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function site()
|
/**
|
||||||
{
|
* THe services this user has
|
||||||
return $this->belongsTo(Site::class);
|
*
|
||||||
}
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||||
|
*/
|
||||||
public function services()
|
public function services()
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Models\Service::class,Models\Account::class);
|
return $this->hasManyThrough(Models\Service::class,Models\Account::class)
|
||||||
|
->with(['account','product','invoices.items.tax','type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This users supplier/reseller
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
protected function supplier()
|
protected function supplier()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(static::class,'parent_id','id');
|
return $this->belongsTo(static::class,'parent_id','id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Who this user supplies to
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
protected function suppliers() {
|
protected function suppliers() {
|
||||||
return $this->hasMany(static::class,'parent_id','id');
|
return $this->hasMany(static::class,'parent_id','id');
|
||||||
}
|
}
|
||||||
@ -116,11 +164,16 @@ class User extends Authenticatable
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFullNameAttribute()
|
public function getFullNameAttribute(): string
|
||||||
{
|
{
|
||||||
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()
|
public function getInvoicesDueAttribute()
|
||||||
{
|
{
|
||||||
return $this->invoices
|
return $this->invoices
|
||||||
@ -131,9 +184,17 @@ class User extends Authenticatable
|
|||||||
->filter();
|
->filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the users language
|
||||||
|
*
|
||||||
|
* For non logged in users we need to populate with a default language
|
||||||
|
* @param $value
|
||||||
|
* @return mixed
|
||||||
|
* @todo This doesnt appear to be used?
|
||||||
|
*/
|
||||||
public function getLanguageAttribute($value)
|
public function getLanguageAttribute($value)
|
||||||
{
|
{
|
||||||
if (is_null($this->language_id))
|
if (is_null($value))
|
||||||
return config('SITE_SETUP')->language;
|
return config('SITE_SETUP')->language;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +202,8 @@ class User extends Authenticatable
|
|||||||
* Return a Carbon Date if it has a value.
|
* Return a Carbon Date if it has a value.
|
||||||
*
|
*
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return \Leenooks\Carbon
|
* @return Carbon
|
||||||
|
* @throws \Exception
|
||||||
* @todo This attribute is not in the schema
|
* @todo This attribute is not in the schema
|
||||||
*/
|
*/
|
||||||
public function getLastAccessAttribute($value)
|
public function getLastAccessAttribute($value)
|
||||||
@ -159,6 +221,12 @@ class User extends Authenticatable
|
|||||||
return $this->full_name;
|
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()
|
public function getPaymentHistoryAttribute()
|
||||||
{
|
{
|
||||||
return $this->payments
|
return $this->payments
|
||||||
@ -166,11 +234,18 @@ class User extends Authenticatable
|
|||||||
->reverse();
|
->reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The users active services
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function getServicesActiveAttribute()
|
public function getServicesActiveAttribute()
|
||||||
{
|
{
|
||||||
return $this->services->filter(function($item) {
|
return $this->services
|
||||||
return $item->isActive();
|
->filter(function($item)
|
||||||
});
|
{
|
||||||
|
return $item->isActive();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getServicesCountHtmlAttribute()
|
public function getServicesCountHtmlAttribute()
|
||||||
@ -198,6 +273,11 @@ class User extends Authenticatable
|
|||||||
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->user_id);
|
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Users password reset email notification
|
||||||
|
*
|
||||||
|
* @param string $token
|
||||||
|
*/
|
||||||
public function sendPasswordResetNotification($token)
|
public function sendPasswordResetNotification($token)
|
||||||
{
|
{
|
||||||
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
|
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
|
||||||
@ -213,7 +293,7 @@ class User extends Authenticatable
|
|||||||
/**
|
/**
|
||||||
* Search for a record
|
* Search for a record
|
||||||
*
|
*
|
||||||
* @param $query
|
* @param $query
|
||||||
* @param string $term
|
* @param string $term
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -253,12 +333,12 @@ class User extends Authenticatable
|
|||||||
* @param $id
|
* @param $id
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isAdmin($id)
|
public function isAdmin($id): bool
|
||||||
{
|
{
|
||||||
return $id AND $this->isReseller() AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
|
return $id AND $this->isReseller() AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Functions */
|
/** FUNCTIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of accounts for the clients of this user
|
* Get a list of accounts for the clients of this user
|
||||||
@ -337,13 +417,17 @@ class User extends Authenticatable
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all the agents, including agents of agents
|
/**
|
||||||
|
* List of all this users agents, recursively
|
||||||
|
*
|
||||||
|
* @param int $level
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
public function all_agents($level=0)
|
public function all_agents($level=0)
|
||||||
{
|
{
|
||||||
$result = collect();
|
$result = collect();
|
||||||
|
|
||||||
foreach ($this->agents as $o)
|
foreach ($this->agents as $o) {
|
||||||
{
|
|
||||||
if (! $o->active OR ! $o->agents->count())
|
if (! $o->active OR ! $o->agents->count())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -363,16 +447,56 @@ class User extends Authenticatable
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isReseller()
|
public function isReseller(): bool
|
||||||
{
|
{
|
||||||
return in_array($this->role(),['wholesaler','reseller']);
|
return in_array($this->role(),['wholesaler','reseller']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isWholesaler()
|
/**
|
||||||
|
* Determine if the logged in user is a wholesaler
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isWholesaler(): bool
|
||||||
{
|
{
|
||||||
return in_array($this->role(),['wholesaler']);
|
return in_array($this->role(),['wholesaler']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the items for the next invoice
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function next_invoice_items(bool $future=FALSE): DatabaseCollection
|
||||||
|
{
|
||||||
|
$result = new DatabaseCollection;
|
||||||
|
$this->load([
|
||||||
|
'services.charges',
|
||||||
|
'services.invoice_items'
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($this->services as $o) {
|
||||||
|
if ($future) {
|
||||||
|
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isPast())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isFuture())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($o->next_invoice_items() as $oo)
|
||||||
|
$result->push($oo);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result->load([
|
||||||
|
'product.descriptions',
|
||||||
|
'service.type',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
6
composer.lock
generated
6
composer.lock
generated
@ -2336,11 +2336,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "leenooks/laravel",
|
"name": "leenooks/laravel",
|
||||||
"version": "6.0.14",
|
"version": "6.0.15",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://dev.leenooks.net/leenooks/laravel",
|
"url": "https://dev.leenooks.net/leenooks/laravel",
|
||||||
"reference": "176f680ff740d41b6e66723557e2e64721e0d51f"
|
"reference": "96a6830e61a612dbff396a041bc0263f2308a324"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"creativeorange/gravatar": "^1.0",
|
"creativeorange/gravatar": "^1.0",
|
||||||
@ -2377,7 +2377,7 @@
|
|||||||
"laravel",
|
"laravel",
|
||||||
"leenooks"
|
"leenooks"
|
||||||
],
|
],
|
||||||
"time": "2020-01-22T09:48:42+00:00"
|
"time": "2020-02-08T06:52:13+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
|
@ -242,4 +242,5 @@ return [
|
|||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'invoice_inadvance'=>30,
|
||||||
];
|
];
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<th class="text-right">Outstanding</th>
|
<th class="text-right">Outstanding</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($o->invoices as $io)
|
@foreach ($o->invoices as $io)
|
||||||
<tr>
|
<tr>
|
||||||
@ -32,15 +33,15 @@
|
|||||||
@js('/plugin/dataTables/dataTables.bootstrap4.js','dt-bootstrap4-js','jq-dt-js')
|
@js('/plugin/dataTables/dataTables.bootstrap4.js','dt-bootstrap4-js','jq-dt-js')
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#invoices').DataTable( {
|
$('#invoices').DataTable( {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
order: [1, 'desc']
|
order: [1, 'desc']
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#invoices tbody').on('click','tr', function () {
|
$('#invoices tbody').on('click','tr', function () {
|
||||||
$(this).toggleClass('selected');
|
$(this).toggleClass('selected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@append
|
@append
|
@ -33,8 +33,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@section('page-scripts')
|
@section('page-scripts')
|
||||||
@css('//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css','jq-dt-css','jquery');
|
@css('//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css','jq-dt-css','jquery')
|
||||||
@js('//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js','jq-dt-js','jquery');
|
@js('//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js','jq-dt-js','jquery')
|
||||||
@css('//cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css','dt-responsive-css','jq-dt-css')
|
@css('//cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css','dt-responsive-css','jq-dt-css')
|
||||||
@js('//cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js','dt-responsive-js','jq-dt-js')
|
@js('//cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js','dt-responsive-js','jq-dt-js')
|
||||||
@css('/plugin/dataTables/dataTables.bootstrap4.css','dt-bootstrap4-css','jq-dt-css')
|
@css('/plugin/dataTables/dataTables.bootstrap4.css','dt-bootstrap4-css','jq-dt-css')
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|
||||||
<div class="card-header p-2">
|
<div class="card-header p-2">
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
<li class="nav-item"><a class="nav-link active" href="#tab-services" data-toggle="tab">Services</a></li>
|
<li class="nav-item"><a class="nav-link active" href="#tab-services" data-toggle="tab">Services</a></li>
|
||||||
@ -63,6 +62,7 @@
|
|||||||
@include('r.clients')
|
@include('r.clients')
|
||||||
</div>
|
</div>
|
||||||
--}}
|
--}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@section('page-scripts')
|
@section('page-scripts')
|
||||||
@css('//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css','jq-dt-css','jquery');
|
@css('//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css','jq-dt-css','jquery')
|
||||||
@js('//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js','jq-dt-js','jquery');
|
@js('//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js','jq-dt-js','jquery')
|
||||||
@css('//cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css','dt-responsive-css','jq-dt-css')
|
@css('//cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css','dt-responsive-css','jq-dt-css')
|
||||||
@js('//cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js','dt-responsive-js','jq-dt-js')
|
@js('//cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js','dt-responsive-js','jq-dt-js')
|
||||||
@css('//cdn.datatables.net/rowgroup/1.0.2/css/rowGroup.dataTables.min.css','dt-rowgroup-css','jq-dt-css')
|
@css('//cdn.datatables.net/rowgroup/1.0.2/css/rowGroup.dataTables.min.css','dt-rowgroup-css','jq-dt-css')
|
||||||
|
@ -15,19 +15,53 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('main-content')
|
@section('main-content')
|
||||||
<div class="content">
|
<div class="row">
|
||||||
<div class="row">
|
@include('common.account.widget.summary')
|
||||||
@include('common.account.widget.summary')
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-7">
|
<div class="col-md-12">
|
||||||
@include('common.service.widget.active')
|
<div class="card">
|
||||||
</div>
|
<div class="card-header p-2">
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
<li class="nav-item"><a class="nav-link active" href="#tab-services" data-toggle="tab">Services</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#tab-nextinvoice" data-toggle="tab">Next Invoice</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#tab-futureinvoice" data-toggle="tab">Future Invoice</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-5">
|
<div class="card-body">
|
||||||
@include('common.invoice.widget.due')
|
<div class="tab-content">
|
||||||
@include('common.payment.widget.history')
|
<div class="active tab-pane" id="tab-services">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-7">
|
||||||
|
@include('common.service.widget.active')
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-5">
|
||||||
|
@include('common.invoice.widget.due')
|
||||||
|
@include('common.payment.widget.history')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="tab-nextinvoice">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
@include('r.invoice.widget.next',['future'=>FALSE])
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="tab-futureinvoice">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
@include('r.invoice.widget.next',['future'=>TRUE])
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<table class="table table-sm">
|
<table class="table table-sm">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Address</th>
|
<th>Address</th>
|
||||||
<td class="text-uppercase">{{ $o->service_description }}</td>
|
<td>{{ $o->service_description }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Service Number</th>
|
<th>Service Number</th>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<th>Billed</th>
|
<th>Billed</th>
|
||||||
<td>{{ $o->billing_period }}</td>
|
<td>{{ $o->billing_period }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@if($o->active)
|
@if($o->active AND $o->invoice_to)
|
||||||
<tr>
|
<tr>
|
||||||
<th>Invoiced To</th>
|
<th>Invoiced To</th>
|
||||||
<td>{{ $o->invoice_to->format('Y-m-d') }}</td>
|
<td>{{ $o->invoice_to->format('Y-m-d') }}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user