40 lines
950 B
PHP
40 lines
950 B
PHP
<?php
|
|
|
|
namespace Modules\FinancialManagement\Models;
|
|
|
|
use App\Traits\HasPublicIdentifier;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class InvoiceLineItem extends Model
|
|
{
|
|
use HasPublicIdentifier;
|
|
|
|
protected $table = 'financial_invoice_line_items';
|
|
|
|
protected $fillable = [
|
|
'invoice_id', 'description', 'quantity', 'unit_price', 'total', 'sort_order',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'quantity' => 'decimal:2',
|
|
'unit_price' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function invoice(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FinancialInvoice::class, 'invoice_id');
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (self $item) {
|
|
$item->total = (float) $item->quantity * (float) $item->unit_price;
|
|
});
|
|
}
|
|
}
|