refactor(pricing): make the service the only price source

Price lists, annual tariffs and per-branch price overrides each answered
"what does this service cost?" differently, so a single date could carry
several answers and nobody could say which one was right. Price now lives
only on ServiceItem.price_rials, edited from the services page.

- drop PriceList/PriceListItem, their repositories and the seven
  /api/v1/price-list(s) endpoints; PricingController keeps only quote and
  the appointment price snapshot
- drop Tariff, TariffRepository, TariffService and the two
  /service-items/{uuid}/tariffs endpoints; creating or repricing a service
  no longer upserts a current-year tariff
- drop price_rials from ServiceBranchOverride; the entity stays for its
  duration columns, which DurationCalculator and ServiceSelectionValidator
  still read
- InvoiceService reads the item price directly
- PricingEngine collapses to a single source; breakdown.sources always
  reports service_item, keeping the response contract intact
- remove the price-lists admin page, its route and settings-menu entry, the
  tariff modal and the service detail tariffs tab; useAppointmentInvoice
  moves to its own hook file

Migration drops price_lists, price_list_items, service_tariffs and the
override price column.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-02 18:00:48 +03:30
co-authored by Claude Opus 5
parent f06efe26c0
commit 4fe0c4f9bf
41 changed files with 208 additions and 1835 deletions
+8 -63
View File
@@ -3,14 +3,8 @@
namespace App\Pricing\Service;
use App\ClinicService\Entity\ServiceItem;
use App\ClinicService\Repository\ServiceBranchOverrideRepository;
use App\ClinicService\Repository\TariffRepository;
use App\Doctor\Entity\DoctorAddress;
use App\Patient\Entity\PatientRecord;
use App\Pricing\Repository\PriceListItemRepository;
use App\Pricing\Repository\PriceListRepository;
use App\Pricing\ValueObject\PriceQuote;
use App\Representation\Service\JalaliDateService;
/**
* زنجیرهٔ قیمت‌گذاری بند ۱۲ مستند.
@@ -19,27 +13,14 @@ use App\Representation\Service\JalaliDateService;
* قیمت پایه → + آیتم‌ها → − تخفیف → − بیمهٔ پایه → − تکمیلی → + مالیات → بیعانه
* ```
*
* ## زنجیرهٔ منبع قیمت
* ## منبع قیمت
*
* برای هر سرویس، اولین چیزی که پیدا شود برنده است:
*
* ۱. override شعبه ({@see \App\ClinicService\Entity\ServiceBranchOverride}) — تسک ۰۴
* ۲. لیست قیمتِ حاکم بر آن تاریخ — همین تسک
* ۳. `Tariff` سال — لایهٔ موجود
* ۴. `ServiceItem::priceRials` — همیشه هست
*
* مرحلهٔ چهارم ضامن است که **هرگز صفر یا خطا** برنگردد: تاریخی که هیچ لیستی نمی‌پوشاند
* باید قیمت بدهد، نه استثنا.
* تنها منبع قیمت، `ServiceItem::priceRials` است — قیمت روی خودِ سرویس مدیریت می‌شود.
* لایه‌های پیشینِ «لیست قیمت»، «تعرفهٔ سالانه» و «قیمت اختصاصی شعبه» حذف شده‌اند تا یک
* تاریخ هرگز دو قیمت نداشته باشد.
*/
final class PricingEngine
{
public function __construct(
private readonly PriceListRepository $priceLists,
private readonly PriceListItemRepository $priceListItems,
private readonly ServiceBranchOverrideRepository $overrides,
private readonly TariffRepository $tariffs,
private readonly JalaliDateService $jalali,
) {}
/**
* @param ServiceItem[] $items آیتم‌های انتخاب‌شده (بدون خودِ سرویس)
@@ -57,18 +38,13 @@ final class PricingEngine
int $at,
array $policy = [],
): PriceQuote {
$entityType = $address->tenantEntityType();
$entityId = $address->tenantEntityId();
$list = $this->priceLists->findCovering($entityType, $entityId, $address, $at);
$sources = [];
$base = $this->priceFor($service, $address, $list, $at, $sources);
$base = $this->priceFor($service, $sources);
$itemsTotal = 0;
foreach ($items as $item) {
$itemsTotal += $this->priceFor($item, $address, $list, $at, $sources);
$itemsTotal += $this->priceFor($item, $sources);
}
$subtotal = $base + $itemsTotal;
@@ -121,39 +97,8 @@ final class PricingEngine
/**
* @param array<string, string> $sources
*/
private function priceFor(
ServiceItem $service,
DoctorAddress $address,
?\App\Pricing\Entity\PriceList $list,
int $at,
array &$sources,
): int {
$override = $this->overrides->mapForAddress([(int) $service->getId()], $address)[(int) $service->getId()] ?? null;
if ($override?->getPriceRials() !== null) {
$sources[$service->getUuid()] = 'branch_override';
return $override->getPriceRials();
}
if ($list !== null) {
$price = $this->priceListItems->priceMap($list, [$service])[(int) $service->getId()] ?? null;
if ($price !== null) {
$sources[$service->getUuid()] = 'price_list';
return $price;
}
}
$tariff = $this->tariffs->findForServiceYear((int) $service->getId(), $this->jalali->jalaliYear($at));
if ($tariff !== null) {
$sources[$service->getUuid()] = 'tariff';
return (int) $tariff->getPriceRials();
}
private function priceFor(ServiceItem $service, array &$sources): int
{
$sources[$service->getUuid()] = 'service_item';
return $service->getPriceRials();