73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\LogsActivity;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class WebDesignQuote extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'web_design_quotes';
|
|
|
|
protected $fillable = [
|
|
'quote_number',
|
|
'status',
|
|
'customer_name',
|
|
'customer_email',
|
|
'customer_phone',
|
|
'customer_company',
|
|
'website_name',
|
|
'website_category',
|
|
'description',
|
|
'requirements',
|
|
'reference_websites',
|
|
'platform',
|
|
'frontend_framework',
|
|
'custom_admin',
|
|
'items',
|
|
'subtotal',
|
|
'discount',
|
|
'vat_percent',
|
|
'total',
|
|
'currency',
|
|
'valid_until',
|
|
'note',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'reference_websites' => 'array',
|
|
'items' => 'array',
|
|
'custom_admin' => 'boolean',
|
|
'subtotal' => 'float',
|
|
'discount' => 'float',
|
|
'vat_percent' => 'float',
|
|
'total' => 'float',
|
|
'valid_until' => 'date',
|
|
];
|
|
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public static function generateQuoteNumber(): string
|
|
{
|
|
$prefix = 'BG-WEB-' . now()->format('Ym') . '-';
|
|
|
|
$last = static::withTrashed()
|
|
->where('quote_number', 'like', $prefix . '%')
|
|
->orderByDesc('quote_number')
|
|
->value('quote_number');
|
|
|
|
$next = $last ? ((int) substr($last, strlen($prefix))) + 1 : 1;
|
|
|
|
return $prefix . str_pad((string) $next, 4, '0', STR_PAD_LEFT);
|
|
}
|
|
}
|