Using datatables to render home dashboard
This commit is contained in:
@@ -8,7 +8,22 @@ class Invoice extends Model
|
||||
{
|
||||
protected $table = 'ab_invoice';
|
||||
protected $dates = ['due_date'];
|
||||
protected $with = ['invoiceitems.taxes','account.country.currency','paymentitems'];
|
||||
protected $with = ['items.taxes','account.country.currency','paymentitems'];
|
||||
|
||||
protected $appends = [
|
||||
'date_due',
|
||||
'due',
|
||||
'invoice_id_url',
|
||||
'total',
|
||||
];
|
||||
|
||||
protected $visible = [
|
||||
'date_due',
|
||||
'due',
|
||||
'id',
|
||||
'invoice_id_url',
|
||||
'total',
|
||||
];
|
||||
|
||||
private $_total = 0;
|
||||
|
||||
@@ -17,7 +32,7 @@ class Invoice extends Model
|
||||
return $this->belongsTo(\App\User::class);
|
||||
}
|
||||
|
||||
public function invoiceitems()
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
@@ -29,7 +44,7 @@ class Invoice extends Model
|
||||
|
||||
public function getDueAttribute()
|
||||
{
|
||||
return $this->currency()->round($this->total - $this->paid);
|
||||
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total - $this->paid);
|
||||
}
|
||||
|
||||
public function getDateDueAttribute()
|
||||
@@ -37,11 +52,16 @@ class Invoice extends Model
|
||||
return $this->due_date->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function getInvoiceNumberAttribute()
|
||||
public function getInvoiceIdAttribute()
|
||||
{
|
||||
return sprintf('%02s-%04s-%04s',$this->site_id,$this->account_id,$this->id);
|
||||
}
|
||||
|
||||
public function getInvoiceIdUrlAttribute()
|
||||
{
|
||||
return sprintf('<a href="/u/invoice/view/%s">%s</a>',$this->id,$this->invoice_id);
|
||||
}
|
||||
|
||||
public function getPaidAttribute()
|
||||
{
|
||||
return $this->currency()->round($this->paymentitems->sum('alloc_amt'));
|
||||
@@ -51,14 +71,14 @@ class Invoice extends Model
|
||||
{
|
||||
if (! $this->_total)
|
||||
{
|
||||
foreach ($this->invoiceitems as $o)
|
||||
foreach ($this->items as $o)
|
||||
{
|
||||
//if ($o->active)
|
||||
if ($o->active)
|
||||
$this->_total += $this->currency()->round($o->total);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_total;
|
||||
return sprintf('%3.'.$this->currency()->rounding.'f',$this->_total);
|
||||
}
|
||||
|
||||
public function currency()
|
||||
|
@@ -8,9 +8,41 @@ class Payment extends Model
|
||||
{
|
||||
protected $table = 'ab_payment';
|
||||
protected $dates = ['date_payment'];
|
||||
protected $with = ['account.country.currency','items'];
|
||||
|
||||
public function getPaymentDateAttribute()
|
||||
protected $appends = [
|
||||
'date_paid',
|
||||
'total',
|
||||
];
|
||||
|
||||
protected $visible = [
|
||||
'date_paid',
|
||||
'id',
|
||||
'total',
|
||||
];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(\App\User::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PaymentItem::class);
|
||||
}
|
||||
|
||||
public function getDatePaidAttribute()
|
||||
{
|
||||
return $this->date_payment->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function getTotalAttribute()
|
||||
{
|
||||
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total_amt);
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->account->country->currency;
|
||||
}
|
||||
}
|
@@ -7,8 +7,30 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Service extends Model
|
||||
{
|
||||
protected $table = 'ab_service';
|
||||
protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl','service_voip'];
|
||||
protected $dates = ['date_last_invoice','date_next_invoice'];
|
||||
protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl'];
|
||||
|
||||
protected $appends = [
|
||||
'category',
|
||||
'next_invoice',
|
||||
'product_name',
|
||||
'service_id',
|
||||
'service_id_url',
|
||||
'service_name',
|
||||
'status',
|
||||
];
|
||||
protected $visible = [
|
||||
'active',
|
||||
'category',
|
||||
'data_orig',
|
||||
'id',
|
||||
'next_invoice',
|
||||
'product_name',
|
||||
'service_id',
|
||||
'service_id_url',
|
||||
'service_name',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function account()
|
||||
{
|
||||
@@ -25,16 +47,34 @@ class Service extends Model
|
||||
return $this->belongsTo(ServiceDomain::class,'id','service_id');
|
||||
}
|
||||
|
||||
public function service_host()
|
||||
{
|
||||
return $this->belongsTo(ServiceHost::class,'id','service_id');
|
||||
}
|
||||
|
||||
public function service_ssl()
|
||||
{
|
||||
return $this->belongsTo(ServiceSsl::class,'id','service_id');
|
||||
}
|
||||
|
||||
public function service_voip()
|
||||
{
|
||||
return $this->belongsTo(ServiceVoip::class,'id','service_id');
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only query active categories
|
||||
*/
|
||||
public function scopeActive()
|
||||
{
|
||||
return $this->where('active',TRUE);
|
||||
}
|
||||
|
||||
public function getCategoryAttribute()
|
||||
{
|
||||
return $this->product->prod_plugin_file;
|
||||
@@ -42,7 +82,12 @@ class Service extends Model
|
||||
|
||||
public function getNextInvoiceAttribute()
|
||||
{
|
||||
return $this->date_next_invoice->format('Y-m-d');
|
||||
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
public function getProductNameAttribute()
|
||||
{
|
||||
return $this->product->name($this->account->language);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,21 +99,40 @@ class Service extends Model
|
||||
{
|
||||
case 'ADSL': return $this->service_adsl;
|
||||
case 'DOMAIN': return $this->service_domain;
|
||||
case 'HOST': return $this->service_host;
|
||||
case 'SSL': return $this->service_ssl;
|
||||
default: abort(500,'Havent handled case for: '.$this->product->prod_plugin_file);
|
||||
case 'VOIP': return $this->service_voip;
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getStatusAttribute()
|
||||
{
|
||||
return $this->active ? 'Active' : 'Inactive';
|
||||
}
|
||||
|
||||
public function getServiceExpireAttribute()
|
||||
{
|
||||
return 'TBA';
|
||||
}
|
||||
|
||||
public function getServiceIdAttribute()
|
||||
{
|
||||
return sprintf('%02s-%05s',$this->site_id,$this->id);
|
||||
}
|
||||
|
||||
public function getServiceIdUrlAttribute()
|
||||
{
|
||||
return sprintf('<a href="/u/service/view/%s">%s</a>',$this->id,$this->service_id);
|
||||
}
|
||||
|
||||
public function getServiceNameAttribute()
|
||||
{
|
||||
if (! isset($this->getServiceDetail()->name)) dd($this,$this->product,$this->getServiceDetail());
|
||||
return sprintf('%s: %s',$this->product->name($this->account->language),$this->getServiceDetail()->name);
|
||||
if (! isset($this->getServiceDetail()->name))
|
||||
return 'Unknown';
|
||||
|
||||
return $this->getServiceDetail()->name;
|
||||
}
|
||||
|
||||
public function getServiceNumberAttribute()
|
||||
|
20
app/Models/ServiceHost.php
Normal file
20
app/Models/ServiceHost.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ServiceHost extends Model
|
||||
{
|
||||
protected $table = 'ab_service__hosting';
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return sprintf('%s',$this->domain_name);
|
||||
}
|
||||
}
|
20
app/Models/ServiceVoip.php
Normal file
20
app/Models/ServiceVoip.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ServiceVoip extends Model
|
||||
{
|
||||
protected $table = 'ab_service__voip';
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->service_number;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user