Resolve a service's duration and price from the resource that performs it
The chain the spec asks for, plus the branch level that already has data: resource+option, resource+service, branch override, then the item's own value. Duration and price resolve independently. If they resolved together the first override would silently swallow the other value — a resource that only differs in how long it takes would also drop the branch's tariff. Each resolved value carries where it came from. Without that, the panel cannot label a number "from the branch" or "service default", and "why this number?" becomes a four-table investigation. Two rules worth stating: null means inherit while zero is a real value, so a free service keeps its zero instead of inheriting the parent's price; and an inactive offering is skipped whole, since "this resource does not perform this right now" is not the same as "I have no opinion on the numbers". The parent service is passed in rather than looked up from the item's group. The booking flow already holds both, and a reverse query would be a second way to answer a question that already has an answer in hand. Eight tests: one per level with the other levels populated so the winner is provable, plus independent resolution, the inactive skip, zero, and resolving the service itself without a parent. Suite 1272 green, phpstan at its 14-error baseline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\ClinicService\ValueObject;
|
||||
|
||||
/**
|
||||
* مدت و قیمتِ حلشدهٔ یک سرویس برای یک منبع مشخص — بههمراه اینکه هر عدد **از کجا** آمده.
|
||||
*
|
||||
* منبعِ هر مقدار بخشی از نتیجه است نه اطلاعات اضافه: پنل باید بتواند کنار عدد بنویسد
|
||||
* «از شعبه» یا «پیشفرض سرویس»، و وقتی کلینیک میپرسد «چرا این عدد؟» جواب بدون خواندن
|
||||
* چهار جدول در دسترس باشد.
|
||||
*/
|
||||
final readonly class ResolvedServiceSpec
|
||||
{
|
||||
/** ردیف `resource_service_offerings` برای همان گزینهای که بیمار انتخاب کرده. */
|
||||
public const SOURCE_RESOURCE_OPTION = 'resource_option';
|
||||
|
||||
/** ردیف همان منبع ولی روی سرویسِ والد — وقتی گزینه مقدار خودش را ندارد. */
|
||||
public const SOURCE_RESOURCE_SERVICE = 'resource_service';
|
||||
|
||||
/** `ServiceBranchOverride` — تنظیم این شعبه، مستقل از اینکه کدام منبع کار را میکند. */
|
||||
public const SOURCE_BRANCH = 'branch';
|
||||
|
||||
/** مقدار خودِ `ServiceItem`. */
|
||||
public const SOURCE_SERVICE_DEFAULT = 'service_default';
|
||||
|
||||
public function __construct(
|
||||
public ?int $durationMinutes,
|
||||
public int $priceRials,
|
||||
/** یکی از ثابتهای `SOURCE_*`؛ `null` یعنی هیچ سطحی مدتی تعریف نکرده. */
|
||||
public ?string $durationSource,
|
||||
public string $priceSource,
|
||||
) {}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'duration_minutes' => $this->durationMinutes,
|
||||
'price_rials' => $this->priceRials,
|
||||
'duration_source' => $this->durationSource,
|
||||
'price_source' => $this->priceSource,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user