Neustrukturierung Customer / Lead / Booking Phase 2

This commit is contained in:
Kevin Adametz 2026-05-28 17:10:37 +02:00
parent 313f0dbf4e
commit 6df9c401af
69 changed files with 3809 additions and 374 deletions

View file

@ -8,29 +8,31 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Position einer Angebotsversion (Modul 6).
* Eine einzelne Positionszeile einer Angebotsversion (Leistung, Option,
* Rabatt, Versicherung, ). Positionen sind versionsgebunden eine neue
* Version hat ihre eigenen Zeilen.
*
* `travel_program_id` und `fewo_lodging_id` bleiben FK-frei, solange
* Modul 12 (v2-Reiseverwaltung) noch nicht nach Laravel migriert ist.
* `metadata` enthält einen Snapshot der Referenzdaten (Titel, Preis,
* Leistungen) so bleiben Positionen lesbar, auch wenn das Original
* später gelöscht / migriert / umbenannt wird.
* `travel_program_id` und `fewo_lodging_id` bleiben aktuell OHNE
* Foreign-Key, solange die v2-Reiseverwaltung noch nicht nach Laravel
* migriert ist (siehe Risiko R4 im Entwicklungsplan). Ein Snapshot
* relevanter Quelldaten wird zusätzlich in `metadata` gespeichert,
* damit Angebote auch nach einem v2-Schema-Wechsel lesbar bleiben.
*
* @property int $id
* @property int $offer_version_id
* @property int $position
* @property string $type
* @property string $title
* @property string|null $description
* @property int $quantity
* @property float $price_per_unit
* @property float $total_price
* @property int|null $travel_program_id
* @property int|null $fewo_lodging_id
* @property array|null $metadata
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read OfferVersion $version
* @property int $id
* @property int $offer_version_id
* @property int $position
* @property string $type travel|service|option|discount|insurance|custom
* @property string $title
* @property string|null $description
* @property int $quantity
* @property float $price_per_unit
* @property float $total_price
* @property int|null $travel_program_id
* @property int|null $fewo_lodging_id
* @property array|null $metadata
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read OfferVersion $offerVersion
*/
class OfferItem extends Model
{
@ -43,6 +45,16 @@ class OfferItem extends Model
public const TYPE_INSURANCE = 'insurance';
public const TYPE_CUSTOM = 'custom';
public const TYPES = [
self::TYPE_TRAVEL,
self::TYPE_SERVICE,
self::TYPE_OPTION,
self::TYPE_DISCOUNT,
self::TYPE_INSURANCE,
self::TYPE_CUSTOM,
];
protected $connection = 'mysql';
protected $table = 'offer_items';
protected $fillable = [
@ -63,24 +75,25 @@ class OfferItem extends Model
'offer_version_id' => 'int',
'position' => 'int',
'quantity' => 'int',
'price_per_unit' => 'decimal:2',
'total_price' => 'decimal:2',
'travel_program_id' => 'int',
'fewo_lodging_id' => 'int',
'price_per_unit' => 'decimal:2',
'total_price' => 'decimal:2',
'metadata' => 'array',
];
public function version(): BelongsTo
public function offerVersion(): BelongsTo
{
return $this->belongsTo(OfferVersion::class, 'offer_version_id');
}
/**
* Aus Menge × Einzelpreis den Positions-Gesamtpreis berechnen
* (Rabatte negativ gehört in den Service-Layer zur Summierung).
* Berechnet `total_price` aus `quantity * price_per_unit` wird vom
* OfferService vor dem Speichern aufgerufen, damit UI-Aggregate
* und DB-Werte konsistent bleiben.
*/
public function calculateTotal(): float
public function recomputeTotal(): void
{
return round($this->quantity * (float) $this->price_per_unit, 2);
$this->total_price = round($this->quantity * (float) $this->price_per_unit, 2);
}
}