Rework payment tables, enable payment editing

This commit is contained in:
Deon George
2021-07-23 17:25:26 +10:00
parent fa62a47680
commit d463239b17
19 changed files with 352 additions and 116 deletions

View File

@@ -10,6 +10,17 @@ use App\Traits\NextKey;
use App\Traits\PushNew;
use Leenooks\Carbon;
/**
* Class Invoice Items
* Items that belong on an invoice
*
* Attributes for services:
* + date_start : Start date
* + date_stop : End date
* + sub_total : Value of item
* + tax : Total of all taxes
* + total : Total including taxes
*/
class InvoiceItem extends Model
{
use NextKey,PushNew;
@@ -26,7 +37,7 @@ class InvoiceItem extends Model
// Array of items that can be updated with PushNew
protected $pushable = ['taxes'];
private $_tax = 0;
/* RELATIONS */
public function invoice()
{
@@ -53,7 +64,7 @@ class InvoiceItem extends Model
return $this->hasMany(InvoiceItemTax::class);
}
/** ATTRIBUTES **/
/* ATTRIBUTES */
/**
* Start date for the invoice item line
@@ -122,30 +133,37 @@ class InvoiceItem extends Model
}
}
public function getSubTotalAttribute()
/**
* Sub total of item
*
* @return float
*/
public function getSubTotalAttribute(): float
{
return $this->quantity * $this->price_base;
return sprintf('%3.2f',$this->quantity * $this->price_base);
}
public function getTaxAttribute()
/**
* Total of all taxes
*
* @return mixed
*/
public function getTaxAttribute(): float
{
if (! $this->_tax)
{
foreach ($this->taxes as $o)
{
$this->_tax += $o->amount;
}
}
return $this->_tax;
return sprintf('%3.2f',$this->taxes->sum('amount'));
}
public function getTotalAttribute()
/**
* Total including taxes
*
* @return float
*/
public function getTotalAttribute(): float
{
return $this->tax + $this->sub_total;
return sprintf('%3.2f',$this->getSubTotalAttribute()+$this->getTaxAttribute());
}
/** FUNCTIONS **/
/* METHODS */
/**
* Add taxes to this record