77 lines
2 KiB
PHP
77 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Wiederverwendbare Angebots-Vorlage (Modul 6).
|
|
*
|
|
* Liefert Default-Texte + Default-Positionen für neue Angebote.
|
|
* `default_items` ist ein JSON-Array von Positionen im Schema
|
|
* [{title, description, type, price_per_unit, quantity}, …].
|
|
*
|
|
* @property int $id
|
|
* @property int|null $branch_id
|
|
* @property string $name
|
|
* @property string|null $description
|
|
* @property string|null $default_headline
|
|
* @property string|null $default_intro
|
|
* @property string|null $default_itinerary
|
|
* @property string|null $default_closing
|
|
* @property array|null $default_items
|
|
* @property bool $is_active
|
|
* @property int $created_by
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property Carbon|null $deleted_at
|
|
* @property-read Branch|null $branch
|
|
* @property-read User $creator
|
|
*/
|
|
class OfferTemplate extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $table = 'offer_templates';
|
|
|
|
protected $fillable = [
|
|
'branch_id',
|
|
'name',
|
|
'description',
|
|
'default_headline',
|
|
'default_intro',
|
|
'default_itinerary',
|
|
'default_closing',
|
|
'default_items',
|
|
'is_active',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'branch_id' => 'int',
|
|
'default_items' => 'array',
|
|
'is_active' => 'bool',
|
|
'created_by' => 'int',
|
|
];
|
|
|
|
public function branch(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Branch::class);
|
|
}
|
|
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function scopeActive(Builder $q): Builder
|
|
{
|
|
return $q->where('is_active', true);
|
|
}
|
|
}
|