osb/app/Models/InvoiceItem.php

46 lines
697 B
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class InvoiceItem extends Model
{
protected $table = 'ab_invoice_item';
protected $with = ['taxes'];
private $_tax = 0;
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
public function taxes()
{
return $this->hasMany(InvoiceItemTax::class);
}
public function getSubTotalAttribute()
{
return $this->quantity * $this->price_base;
}
public function getTaxAttribute()
{
if (! $this->_tax)
{
foreach ($this->taxes as $o)
{
$this->_tax += $o->amount;
}
}
return $this->_tax;
}
public function getTotalAttribute()
{
return $this->tax + $this->sub_total;
}
}