Paket 1: eine aktive Angebotsfassung und Bestellbezeichnung
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8cd382c357
commit
7820bececb
13 files changed
+529
-25
No files matched your search
@@ -8,6 +8,20 @@ class OfferService
|
||||
{
|
||||
public function __construct(private readonly BundleService $bundles) {}
|
||||
|
||||
public function currentActiveVersion(Offer $offer): OfferVersion
|
||||
{
|
||||
$version = $offer->versions()
|
||||
->where('status', OfferStatus::Aktiv)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
|
||||
if ($version === null) {
|
||||
throw new DomainRuleException('Das Angebot hat keine aktive Fassung.');
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $capabilities
|
||||
* @param array<string, mixed> $options
|
||||
@@ -77,6 +91,13 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of
|
||||
$scope = $this->scopeFor($lines);
|
||||
|
||||
return DB::transaction(function () use ($offer, $lines, $attributes, $scope): OfferVersion {
|
||||
$offer = Offer::query()->lockForUpdate()->findOrFail($offer->id);
|
||||
|
||||
OfferVersion::query()
|
||||
->where('offer_id', $offer->id)
|
||||
->where('status', OfferStatus::Aktiv)
|
||||
->update(['status' => OfferStatus::Beendet->value]);
|
||||
|
||||
$version = $offer->versions()->create([
|
||||
'number' => ((int) $offer->versions()->max('number')) + 1,
|
||||
'status' => OfferStatus::Entwurf,
|
||||
|
||||
@@ -34,11 +34,24 @@ protected function casts(): array
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::updating(function (OfferVersion $version): void {
|
||||
if (in_array(StatusValue::of($version->getOriginal('status')), [
|
||||
OfferStatus::Aktiv->value,
|
||||
OfferStatus::Beendet->value,
|
||||
], true)) {
|
||||
throw new DomainRuleException('Eine aktivierte Angebotsfassung ist unveränderlich.');
|
||||
$original = StatusValue::of($version->getOriginal('status'));
|
||||
$next = StatusValue::of($version->status);
|
||||
|
||||
if ($original === OfferStatus::Beendet->value) {
|
||||
throw new DomainRuleException('Eine beendete Angebotsfassung ist unveränderlich.');
|
||||
}
|
||||
|
||||
if ($original === OfferStatus::Aktiv->value) {
|
||||
if ($next !== OfferStatus::Beendet->value) {
|
||||
throw new DomainRuleException('Eine aktive Angebotsfassung lässt sich nur durch Beendigung schließen.');
|
||||
}
|
||||
|
||||
$dirty = $version->getDirty();
|
||||
unset($dirty['status'], $dirty['updated_at']);
|
||||
|
||||
if ($dirty !== []) {
|
||||
throw new DomainRuleException('Eine aktive Angebotsfassung lässt sich nur durch Beendigung schließen.');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user