Every one of the fourteen named events now has an emit point. The four that
were missing all sat on paths owned by earlier tasks:
- AppointmentCompleted fires from both status-change routes, after the row is
saved. A rejected transition or a version conflict leaves no event; otherwise
the completed count runs ahead of the appointments themselves.
- AppointmentRescheduled is a third event, not a replacement. A rebook is a
confirm plus a cancel, and a consumer that only hears the cancel messages a
patient who still has an appointment.
- ResourceBlocked / ResourceReleased are a pair. Capacity coming back has to be
as audible as capacity going away, or the resource reads as permanently taken.
Publishing is now on the scheduler rather than an unregistered command: the
logic moved out of PublishDomainEventsCommand into OutboxPublisher so the
recurring message and the manual command share it, and the existing
worker-scheduler container consumes it. The scheduler message carries no data
on purpose — what to publish is read from the table, so an event recorded
between two ticks is not skipped. DomainEventMessage routes to async, since a
slow consumer was otherwise slowing the drain itself and its failure marked a
row failed that had in fact been delivered.
Panel work that these paths made reachable:
- Cancelling from the appointment page now goes through the policy-aware
endpoint and shows the penalty preview before the confirm, so the operator
does not discover the patient's penalty after the fact. The cancellation
service writes the timeline entry itself and accepts a reason, which that
path previously dropped on the floor.
- Rescheduling reuses the booking page under ?rebook=<uuid> — the search and
hold steps are identical and only the final step differs. The doctor picker
is hidden there: a reschedule is not an invitation to change doctors.
- A new GET /appointment/{uuid}/segments exposes the recorded plan. An empty
list is not an error, it means the appointment is slot-based, and that is
exactly what gates the resource-mode reschedule button.
AppointmentInvoiceCard no longer crashes the whole detail page when an older
invoice has no discount breakdown.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
112 lines
4.4 KiB
TypeScript
112 lines
4.4 KiB
TypeScript
import React from 'react';
|
||
import { formatDate, formatRial } from '../lib/utils';
|
||
import { useAppointmentInvoice } from '../hooks/usePriceLists';
|
||
|
||
interface Props {
|
||
appointmentUuid: string;
|
||
}
|
||
|
||
/**
|
||
* فاکتور تفکیکشدهٔ نوبت.
|
||
*
|
||
* اعدادش snapshot لحظهٔ ثبتاند، نه محاسبهٔ امروز: تغییر تعرفه هرگز فاکتور صادرشده را
|
||
* عوض نمیکند (قانون پنجم مستند). همین جمله زیر کارت هم نوشته میشود، چون کاربری که
|
||
* قیمت را دیروز عوض کرده و امروز عدد قدیمی میبیند وگرنه فکر میکند سیستم خراب است.
|
||
*/
|
||
export default function AppointmentInvoiceCard({ appointmentUuid }: Props) {
|
||
const { invoice, loading, missing } = useAppointmentInvoice(appointmentUuid);
|
||
|
||
if (loading) {
|
||
return (
|
||
<div className="card" style={{ fontSize: 13, color: 'var(--text-3)' }}>
|
||
در حال بارگذاری فاکتور…
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// نبودِ فاکتور خطا نیست: نوبتی که هنوز ثبت نهایی نشده، فاکتوری هم ندارد.
|
||
if (missing || !invoice) {
|
||
return (
|
||
<div className="card" style={{ fontSize: 13, color: 'var(--text-3)' }}>
|
||
برای این نوبت فاکتوری ثبت نشده است.
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const rows: { label: string; value: number; muted?: boolean }[] = [
|
||
{ label: 'قیمت پایه', value: invoice.base_rials },
|
||
{ label: 'آیتمهای اضافه', value: invoice.items_rials },
|
||
{ label: 'تخفیف', value: -invoice.discount_rials },
|
||
{ label: 'سهم بیمهٔ پایه', value: -invoice.insurance_base_rials },
|
||
{ label: 'سهم بیمهٔ تکمیلی', value: -invoice.insurance_supplementary_rials },
|
||
{ label: 'مالیات', value: invoice.tax_rials },
|
||
];
|
||
|
||
return (
|
||
<div className="card" style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||
<h3 style={{ fontSize: 15, margin: 0 }}>فاکتور</h3>
|
||
{invoice.created_at !== undefined && (
|
||
<span style={{ fontSize: 12, color: 'var(--text-3)' }}>
|
||
ثبتشده در {formatDate(invoice.created_at)}
|
||
</span>
|
||
)}
|
||
</div>
|
||
|
||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||
{rows
|
||
.filter((row) => row.value !== 0)
|
||
.map((row) => (
|
||
<div
|
||
key={row.label}
|
||
style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13 }}
|
||
>
|
||
<span style={{ color: 'var(--text-2)' }}>{row.label}</span>
|
||
<span style={{ color: row.value < 0 ? 'var(--success)' : undefined }}>
|
||
{formatRial(Math.abs(row.value))}
|
||
{row.value < 0 ? ' −' : ''}
|
||
</span>
|
||
</div>
|
||
))}
|
||
|
||
{/* فاکتور قدیمی ممکن است ریز تخفیف نداشته باشد؛ نبودنش نباید کل صفحه را ببندد. */}
|
||
{(invoice.breakdown?.discounts ?? []).map((line, index) => (
|
||
<div
|
||
key={index}
|
||
style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, color: 'var(--text-3)' }}
|
||
>
|
||
<span>{line.label}</span>
|
||
<span>{formatRial(Math.abs(line.rials))}</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
<div
|
||
style={{
|
||
borderTop: '1px solid var(--border)',
|
||
paddingTop: 10,
|
||
display: 'flex',
|
||
justifyContent: 'space-between',
|
||
fontSize: 15,
|
||
fontWeight: 600,
|
||
}}
|
||
>
|
||
<span>مبلغ نهایی</span>
|
||
<span>{formatRial(invoice.final_rials)}</span>
|
||
</div>
|
||
|
||
{invoice.deposit_rials > 0 && (
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13 }}>
|
||
<span style={{ color: 'var(--text-2)' }}>بیعانه</span>
|
||
<span>{formatRial(invoice.deposit_rials)}</span>
|
||
</div>
|
||
)}
|
||
|
||
<span style={{ fontSize: 12, color: 'var(--text-3)' }}>
|
||
قیمتها بر اساس تاریخ همین نوبت محاسبه و ثبت شدهاند؛ تغییر بعدی تعرفه این فاکتور
|
||
را عوض نمیکند.
|
||
</span>
|
||
</div>
|
||
);
|
||
}
|