Files
fewo-stommer/app/Process/Modules/Loyalty/LoyaltyDiscount.php
T
LarsandClaude Opus 5.5 7e22e12cac 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>
2026-11-04 14:49:44 +01:00

70 lines
2.8 KiB
PHP

<?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')];
}
}