60 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Quote extends Model
{
use HasFactory;
protected $fillable = [
'customer_id',
'date',
'notes',
];
protected $casts = [
'date' => 'date',
];
protected $appends = [
'total',
];
public function getTotalAttribute(): float
{
$embDigitizingTotal = $this->embroideryEntries()->sum('digitizing_cost');
$embRunChargeTotal = $this->embroideryEntries()->sum('run_charge');
$scpTotal = $this->screenPrintEntries->sum(fn (ScreenPrintEntry $record) => $record->total_price);
$heatTransferTotal = $this->heatTransferEntries()->sum('price');
return $embDigitizingTotal + $embRunChargeTotal + $scpTotal + $heatTransferTotal;
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
public function embroideryEntries(): HasMany
{
return $this->hasMany(EmbroideryEntry::class);
}
public function screenPrintEntries(): HasMany
{
return $this->hasMany(ScreenPrintEntry::class);
}
public function heatTransferEntries(): HasMany
{
return $this->hasMany(HeatTransferEntry::class);
}
}