Account next invoice, and authorisations

This commit is contained in:
Deon George
2019-07-04 14:55:05 +10:00
parent 59a8ef2476
commit 21ea60c4f9
26 changed files with 532 additions and 102 deletions

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class InvoiceItem extends Model
{
protected $dates = ['date_start','date_stop'];
public $dateFormat = 'U';
protected $table = 'ab_invoice_item';
protected $with = ['taxes'];
@@ -32,6 +33,8 @@ class InvoiceItem extends Model
return $this->hasMany(InvoiceItemTax::class);
}
/** ATTRIBUTES **/
public function getItemTypeNameAttribute()
{
$types = [
@@ -69,22 +72,10 @@ class InvoiceItem extends Model
}
}
public function module_text()
{
switch ($this->module_id)
{
// Charges Module
case 30: return Charge::findOrFail($this->module_ref)->name;
default: abort(500,'Unable to handle '.$this->module_id);
}
}
public function getSubTotalAttribute()
{
return $this->quantity * $this->price_base;
}
public function getTaxAttribute()
{
if (! $this->_tax)
@@ -102,4 +93,36 @@ class InvoiceItem extends Model
{
return $this->tax + $this->sub_total;
}
/** FUNCTIONS **/
/**
* Add taxes to this record
*/
public function addTaxes()
{
// 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)
{
$iit = new InvoiceItemTax;
$iit->tax_id = $to->id;
$iit->amount = round($this->quantity*$this->price_base*$to->rate,3);
$this->taxes->push($iit);
}
}
public function module_text()
{
switch ($this->module_id)
{
// Charges Module
case 30: return Charge::findOrFail($this->module_ref)->name;
default: abort(500,'Unable to handle '.$this->module_id);
}
}
}