56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Catalog;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class OfferLine extends Model
|
|
{
|
|
protected $fillable = [
|
|
'offer_version_id',
|
|
'position',
|
|
'license_article_id',
|
|
'bundle_version_id',
|
|
'rights_profile_version_id',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (OfferLine $line): void {
|
|
$status = OfferVersion::query()->whereKey($line->offer_version_id)->value('status');
|
|
|
|
if (in_array(StatusValue::of($status), [
|
|
OfferStatus::Aktiv->value,
|
|
OfferStatus::Beendet->value,
|
|
], true)) {
|
|
throw new DomainRuleException('Eine aktivierte Angebotsfassung nimmt keine weiteren Positionen auf.');
|
|
}
|
|
});
|
|
|
|
static::updating(function (): void {
|
|
throw new DomainRuleException('Positionen einer Angebotsfassung sind unveränderlich.');
|
|
});
|
|
}
|
|
|
|
public function offerVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(OfferVersion::class);
|
|
}
|
|
|
|
public function article(): BelongsTo
|
|
{
|
|
return $this->belongsTo(LicenseArticle::class, 'license_article_id');
|
|
}
|
|
|
|
public function bundleVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BundleVersion::class);
|
|
}
|
|
|
|
public function rights(): BelongsTo
|
|
{
|
|
return $this->belongsTo(RightsProfileVersion::class, 'rights_profile_version_id');
|
|
}
|
|
}
|