Initial refactoring work
This commit is contained in:
46
app/Models/InvoiceItem.php
Normal file
46
app/Models/InvoiceItem.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user