Files
clinicpro/assets/admin/hooks/useAppointmentInvoice.ts
T
hamedandClaude Opus 5 4fe0c4f9bf 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>
2026-08-02 18:00:48 +03:30

39 lines
1.2 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { api, type ApiResponse } from '../lib/api';
export interface PriceSnapshotLine {
label: string;
rials: number;
kind?: string;
}
export interface PriceSnapshot {
base_rials: number;
items_rials: number;
discount_rials: number;
insurance_base_rials: number;
insurance_supplementary_rials: number;
tax_rials: number;
final_rials: number;
deposit_rials: number;
created_at?: number;
breakdown: {
discounts: PriceSnapshotLine[];
sources: Record<string, unknown>;
};
}
/** فاکتور یک نوبت — همان اعداد لحظهٔ ثبت، حتی اگر قیمت سرویس بعداً عوض شده باشد. */
export function useAppointmentInvoice(appointmentUuid: string | undefined) {
const query = useQuery({
queryKey: ['appointment-invoice', appointmentUuid],
queryFn: () =>
api.get<ApiResponse<PriceSnapshot>>(`/api/v1/appointment/${appointmentUuid}/price-snapshot`),
enabled: !!appointmentUuid,
// نوبتِ بدون فاکتور ۴۰۴ می‌دهد و آن خطا نیست، یعنی «هنوز ثبت نشده».
retry: false,
});
return { invoice: query.data?.data, loading: query.isLoading, missing: query.isError };
}