fix: issue invoice on demand so view-invoice buttons actually work

The admin SPA never called POST /billing/invoices, so every session had
invoice_uuid = null and the view-invoice buttons on the patient services
tab (and MyPatients visit modal) were permanently disabled. Add a shared
useIssueInvoice hook (idempotent create + finalize when draft) and wire
it into:
- DetailsStep: the wizard's final step now really issues the invoice
- SessionServiceCard / PatientDetailPage: clicking view-invoice on a
  session without an invoice issues it first, then opens the summary
- MyPatientsPage visit modal: same, replacing the dead disabled button

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-16 15:39:02 +03:30
co-authored by Claude Opus 4.8
parent 0ba4bf383b
commit 76bfa5d36f
10 changed files with 204 additions and 18 deletions
@@ -45,11 +45,14 @@ function Row({ label, value, valueStyle }: { label: string; value: string; value
* pixel-for-pixel from tauri files/services/ServiceCard. Paid cards show
* «مشاهده فاکتور», unpaid ones «تکمیل پرداخت».
*/
export default function SessionServiceCard({ session, onSettle, onViewInvoice, settling }: {
export default function SessionServiceCard({ session, onSettle, onViewInvoice, settling, issuing }: {
session: SessionCardData;
onSettle: (uuid: string) => void;
onViewInvoice: (invoiceUuid: string) => void;
/** کل session پاس می‌شود؛ اگر invoice_uuid نداشت، caller فاکتور را می‌سازد. */
onViewInvoice: (session: SessionCardData) => void;
settling?: boolean;
/** true وقتی صدور فاکتور همین لحظه در جریان است (دکمه قفل می‌شود). */
issuing?: boolean;
}) {
const paid = !!session.is_paid;
const names = (session.services ?? []).map((s) => s.service_name || s.name).filter(Boolean) as string[];
@@ -94,11 +97,11 @@ export default function SessionServiceCard({ session, onSettle, onViewInvoice, s
{paid ? (
<button
type="button"
disabled={!session.invoice_uuid}
onClick={() => session.invoice_uuid && onViewInvoice(session.invoice_uuid)}
disabled={issuing}
onClick={() => onViewInvoice(session)}
style={{ marginTop: 8, height: 40, width: '100%', borderRadius: 4, fontSize: 13, fontWeight: 500, cursor: 'pointer', color: '#4F46E5', background: 'transparent', border: '1px solid #5559ce' }}
>
مشاهده فاکتور
{issuing ? 'در حال صدور…' : 'مشاهده فاکتور'}
</button>
) : (
<button