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
@@ -81,10 +81,10 @@ class ResourceServiceResolverTest extends ApiTestCase
return $offering;
}
private function branchOverride(ServiceItem $item, ?int $minutes, ?int $price): void
private function branchOverride(ServiceItem $item, ?int $minutes): void
{
$override = new ServiceBranchOverride($item, $this->address);
$override->setSoloDurationMinutes($minutes)->setPriceRials($price);
$override->setSoloDurationMinutes($minutes);
$this->em->persist($override);
$this->em->flush();
}
@@ -100,7 +100,7 @@ class ResourceServiceResolverTest extends ApiTestCase
{
$this->offer($this->option, 15, 9_500_000);
$this->offer($this->service, 40, 12_000_000);
$this->branchOverride($this->option, 50, 11_000_000);
$this->branchOverride($this->option, 50);
$spec = $this->resolve();
@@ -113,7 +113,7 @@ class ResourceServiceResolverTest extends ApiTestCase
public function testLevelTwoResourcePlusServiceWinsWhenTheOptionHasNothing(): void
{
$this->offer($this->service, 40, 12_000_000);
$this->branchOverride($this->option, 50, 11_000_000);
$this->branchOverride($this->option, 50);
$spec = $this->resolve();
@@ -122,15 +122,17 @@ class ResourceServiceResolverTest extends ApiTestCase
self::assertSame(ResolvedServiceSpec::SOURCE_RESOURCE_SERVICE, $spec->durationSource);
}
public function testLevelThreeBranchWinsWhenTheResourceHasNothing(): void
/** شعبه فقط مدت می‌دهد؛ قیمتش را از خودِ سرویس می‌گیرد. */
public function testLevelThreeBranchWinsForDurationOnly(): void
{
$this->branchOverride($this->option, 50, 11_000_000);
$this->branchOverride($this->option, 50);
$spec = $this->resolve();
self::assertSame(50, $spec->durationMinutes);
self::assertSame(11_000_000, $spec->priceRials);
self::assertSame(ResolvedServiceSpec::SOURCE_BRANCH, $spec->durationSource);
self::assertSame(8_000_000, $spec->priceRials);
self::assertSame(ResolvedServiceSpec::SOURCE_SERVICE_DEFAULT, $spec->priceSource);
}
public function testLevelFourFallsBackToTheItemItself(): void
@@ -147,17 +149,17 @@ class ResourceServiceResolverTest extends ApiTestCase
public function testDurationAndPriceResolveIndependently(): void
{
// منبع فقط مدت را می‌گوید؛ قیمت باید تا سطح شعبه پایین برود.
// منبع فقط مدت را می‌گوید؛ قیمت باید تا خودِ سرویس پایین برود.
$this->offer($this->option, 15, null);
$this->branchOverride($this->option, null, 11_000_000);
$this->branchOverride($this->option, null);
$spec = $this->resolve();
self::assertSame(15, $spec->durationMinutes);
self::assertSame(ResolvedServiceSpec::SOURCE_RESOURCE_OPTION, $spec->durationSource);
self::assertSame(11_000_000, $spec->priceRials);
self::assertSame(ResolvedServiceSpec::SOURCE_BRANCH, $spec->priceSource);
self::assertSame(8_000_000, $spec->priceRials);
self::assertSame(ResolvedServiceSpec::SOURCE_SERVICE_DEFAULT, $spec->priceSource);
}
public function testAnInactiveOfferingIsSkippedEntirely(): void
+3 -3
View File
@@ -255,7 +255,8 @@ class ServiceSelectionTest extends ApiTestCase
self::assertStringContainsString('حلقه', $body['errors'][0]['message']);
}
public function testBranchOverrideChangesPriceAndDuration(): void
/** شعبه فقط مدت را عوض می‌کند؛ قیمت همیشه از خودِ سرویس است. */
public function testBranchOverrideChangesDurationButNotPrice(): void
{
[$user, , $section, $address] = $this->clinicWithSection();
$face = $this->item($section, 'صورت', 15, 8, 500_000);
@@ -263,7 +264,6 @@ class ServiceSelectionTest extends ApiTestCase
$this->authJson('PUT', "/api/v1/service-item/{$face->getUuid()}/branch-overrides", $user, [
'overrides' => [[
'address_uuid' => $address->getUuid(),
'price_rials' => 900_000,
'solo_duration_minutes' => 25,
]],
]);
@@ -274,7 +274,7 @@ class ServiceSelectionTest extends ApiTestCase
self::assertSame(15, $plain['data']['total_duration_minutes']);
$atBranch = $this->validate($user, [$face->getUuid()], ['branch_uuid' => $address->getUuid()]);
self::assertSame(900_000, $atBranch['data']['total_price_rials']);
self::assertSame(500_000, $atBranch['data']['total_price_rials'], 'قیمت شعبه‌ای وجود ندارد');
self::assertSame(25, $atBranch['data']['total_duration_minutes']);
}