U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester
CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
98df5e9e3b
commit
7e22e12cac
80 files changed
+4628
-445
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Modules\Loyalty;
|
||||
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Pricing\PriceQuote;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\ContributesToPrice;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\Module;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Support\Money;
|
||||
|
||||
/**
|
||||
* Architecture proof (decision E7): a returning guest's discount as a Discount line before the price is fixed. Tester
|
||||
* only. Test assumptions (E5/E6, not released business rules): a percentage of the rent with a cap; no discount when the
|
||||
* quote already has a special offer discount; once the offer is made the line is frozen in the quote and never
|
||||
* recalculated (also not when the booking changes).
|
||||
*/
|
||||
final class LoyaltyDiscount extends Module implements ContributesToPrice
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'pricing.loyalty_discount';
|
||||
}
|
||||
|
||||
public static function definition(): ModuleDefinition
|
||||
{
|
||||
return new ModuleDefinition(
|
||||
label: 'Stammgastrabatt',
|
||||
purpose: 'Gewährt Stammgästen einen Rabatt auf die Miete, bevor der Preis festgelegt wird (Architekturnachweis, nur im Prozess-Tester).',
|
||||
phase: 'P02',
|
||||
requires: [Dependency::hard('guest.loyalty_status')],
|
||||
effects: [],
|
||||
parameters: ['percent', 'max'],
|
||||
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
|
||||
points: ['before_price_fixing'],
|
||||
readsContractData: true,
|
||||
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
|
||||
);
|
||||
}
|
||||
|
||||
public function priceLines(CaseContext $case, PriceQuote $quote): array
|
||||
{
|
||||
$status = app(LoyaltyStatusCheck::class)->status($case);
|
||||
if ($status['status'] !== LoyaltyStatusCheck::QUALIFIED || $quote->discount() > 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$percent = (int) ($case->parameter(self::key(), 'percent') ?? 5);
|
||||
$max = (int) ($case->parameter(self::key(), 'max') ?? 10000);
|
||||
$amount = min($max, (int) round($quote->rent() * $percent / 100));
|
||||
if ($amount <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [new QuoteLine(QuoteLineType::Discount, 'Stammgastrabatt '.$percent.' % ('.count($status['stays']).' frühere Aufenthalte)', 1, -$amount, -$amount)];
|
||||
}
|
||||
|
||||
public function activities(CaseContext $case): array
|
||||
{
|
||||
$line = collect((array) ($case->booking->quote['lines'] ?? []))->first(fn (array $line): bool => str_starts_with((string) ($line['label'] ?? ''), 'Stammgastrabatt'));
|
||||
|
||||
return [new Activity('loyalty_discount', 'Stammgastrabatt', ActivityState::Done, $line !== null ? Money::format(-(int) $line['amount']).' im Angebot' : 'kein Rabatt im Angebot')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Modules\Loyalty;
|
||||
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Models\Booking;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\Module;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Modules\StepState;
|
||||
|
||||
/**
|
||||
* Architecture proof (decision E7, docs/Prozessarchitektur/Architektur/02 §6): whether the guest is a returning guest –
|
||||
* completed, not cancelled stays of the same guest e-mail at the same landlord within the look-back. Tester only: never
|
||||
* part of a real case's plan. The status is derived from the stays on every evaluation (no second truth); the rules
|
||||
* (count, look-back) are test assumptions, not released business rules.
|
||||
*/
|
||||
final class LoyaltyStatusCheck extends Module
|
||||
{
|
||||
public const QUALIFIED = 'qualified';
|
||||
|
||||
public const NOT_QUALIFIED = 'not_qualified';
|
||||
|
||||
public const UNKNOWN = 'unknown';
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'guest.loyalty_status';
|
||||
}
|
||||
|
||||
public static function definition(): ModuleDefinition
|
||||
{
|
||||
return new ModuleDefinition(
|
||||
label: 'Stammgaststatus feststellen',
|
||||
purpose: 'Stellt fest, ob der Gast schon bei Ihnen zu Gast war (Architekturnachweis, nur im Prozess-Tester).',
|
||||
phase: 'P01',
|
||||
requires: [Dependency::hard('guest.details')],
|
||||
triggers: ['facts.applied'],
|
||||
parameters: ['min_stays', 'lookback_years'],
|
||||
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
|
||||
events: ['facts'],
|
||||
points: ['after_guest_identified'],
|
||||
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, stays: list<string>}
|
||||
*/
|
||||
public function status(CaseContext $case): array
|
||||
{
|
||||
$email = mb_strtolower(trim((string) $case->booking->guest?->email));
|
||||
if ($email === '') {
|
||||
return ['status' => self::UNKNOWN, 'stays' => []];
|
||||
}
|
||||
|
||||
$years = (int) ($case->parameter(self::key(), 'lookback_years') ?? 5);
|
||||
$minimum = (int) ($case->parameter(self::key(), 'min_stays') ?? 1);
|
||||
$stays = Booking::query()
|
||||
->whereKeyNot($case->booking->id)
|
||||
->where('status', BookingStatus::Completed)
|
||||
->whereDate('departure', '>=', $case->today->subYears($years))
|
||||
->whereHas('guest', fn ($query) => $query->whereRaw('lower(email) = ?', [$email]))
|
||||
->orderBy('arrival')
|
||||
->get()
|
||||
->map(fn (Booking $stay): string => (string) $stay->reference)
|
||||
->all();
|
||||
|
||||
return ['status' => count($stays) >= $minimum ? self::QUALIFIED : self::NOT_QUALIFIED, 'stays' => $stays];
|
||||
}
|
||||
|
||||
public function activities(CaseContext $case): array
|
||||
{
|
||||
$status = $this->status($case);
|
||||
|
||||
return [new Activity('loyalty_status', 'Stammgaststatus feststellen', ActivityState::Done, match ($status['status']) {
|
||||
self::QUALIFIED => 'Stammgast: '.count($status['stays']).' frühere Aufenthalte ('.implode(', ', $status['stays']).')',
|
||||
self::NOT_QUALIFIED => 'kein Stammgast',
|
||||
default => 'Status nicht feststellbar (keine E-Mail-Adresse) – kein Rabatt',
|
||||
})];
|
||||
}
|
||||
|
||||
public function state(CaseContext $case): ?StepState
|
||||
{
|
||||
return StepState::Done;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user