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')];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user