Next/Future invoices for users

This commit is contained in:
Deon George
2020-02-08 22:51:50 +11:00
parent b61e00d80f
commit eb316f65fc
18 changed files with 277 additions and 96 deletions

View File

@@ -2,7 +2,6 @@
namespace App\Models;
use App\User;
use Illuminate\Database\Eloquent\Model;
use App\Traits\NextKey;
@@ -10,9 +9,7 @@ use App\Traits\NextKey;
class Account extends Model
{
use NextKey;
const RECORD_ID = 'account';
public $incrementing = FALSE;
protected $table = 'ab_account';

View File

@@ -8,7 +8,7 @@ class Invoice extends Model
{
protected $table = 'ab_invoice';
protected $dates = ['date_orig','due_date'];
protected $with = ['account.country.currency','items','paymentitems'];
protected $with = ['account.country.currency','items.taxes','paymentitems'];
protected $appends = [
'date_due',

View File

@@ -2,8 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Leenooks\Carbon;
class InvoiceItem extends Model
@@ -11,7 +13,6 @@ class InvoiceItem extends Model
protected $dates = ['date_start','date_stop'];
public $dateFormat = 'U';
protected $table = 'ab_invoice_item';
protected $with = ['taxes'];
private $_tax = 0;
@@ -20,6 +21,11 @@ class InvoiceItem extends Model
return $this->belongsTo(Invoice::class);
}
/**
* Product for this item
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);
@@ -131,13 +137,13 @@ class InvoiceItem extends Model
/**
* Add taxes to this record
*/
public function addTaxes()
public function addTaxes(Collection $taxes)
{
// Refuse to change an existing record
if ($this->exists)
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->tax_id = $to->id;

View File

@@ -191,9 +191,6 @@ class Service extends Model
*/
public function type()
{
if (! $this->model)
abort(500,'Missing Model in',['service'=>$this]);
return $this->morphTo(null,'model','id','service_id');
}
@@ -772,7 +769,7 @@ class Service extends Model
$o->date_stop = $this->invoice_next_end;
$o->quantity = $this->invoice_next_quantity;
$o->addTaxes();
$o->addTaxes($this->account->country->taxes);
$result->push($o);
}
@@ -789,7 +786,7 @@ class Service extends Model
$o->date_stop = $this->invoice_next;
$o->quantity = 1;
$o->addTaxes();
$o->addTaxes($this->account->country->taxes);
$result->push($o);
}
@@ -807,7 +804,7 @@ class Service extends Model
$o->module_id = 30; // @todo This shouldnt be hard coded
$o->module_ref = $oo->id;
$o->addTaxes();
$o->addTaxes($this->account->country->taxes);
$result->push($o);
}

View File

@@ -68,7 +68,7 @@ class Adsl extends ServiceType implements ServiceItem
*/
public function getServiceDescriptionAttribute(): string
{
return $this->service_address ?: 'NO Service Address';
return strtoupper($this->service_address) ?: 'NO Service Address';
}
/**

View File

@@ -2,24 +2,33 @@
namespace App\Models\Service;
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Traits\NextKey;
class Voip extends \App\Models\Base\ServiceType
class Voip extends ServiceType implements ServiceItem
{
use NextKey;
const RECORD_ID = 'service__adsl';
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)
? sprintf('%s: %s',$this->service_number, $this->service_address)
: $this->name;
return $this->service_address ?: 'VOIP';
}
public function getNameAttribute()
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number;
}