feat: enhance payment status handling and summary in MyPaymentsPage

- Added support for 'partial' payment status in MyPaymentsPage and related components.
- Updated API responses to include 'paid_rials' and 'summary' for invoices.
- Introduced InvoicePaymentStatus service to derive payment status based on actual payments.
- Enhanced tests to cover new payment scenarios including partial payments and payment methods.
- Updated documentation to reflect changes in payment status and API responses.
This commit is contained in:
hamed
2026-07-19 10:38:29 +03:30
parent 5c8fe8ece4
commit 357adb1d14
18 changed files with 620 additions and 188 deletions
+21 -5
View File
@@ -2,8 +2,11 @@ import { useQuery } from '@tanstack/react-query';
import { api } from '../lib/api';
import type { ApiResponse, PaginatedResponse } from '../lib/api';
/** Two-state invoice status shown on both the list (node 1) and detail (node 2). */
export type PaymentRowStatus = 'paid' | 'unsettled';
/**
* وضعیت پرداخت صورتحساب — مشتق از مجموع پرداخت‌های مراجعه در برابر سهم بیمار،
* نه ستون `invoices.status` (که فقط چرخه‌ی حیات را نگه می‌دارد).
*/
export type PaymentRowStatus = 'paid' | 'partial' | 'unsettled';
/** One recorded invoice on the flat payments list (node 1). */
export interface PaymentRow {
@@ -13,33 +16,46 @@ export interface PaymentRow {
national_code: string | null;
issued_at: number;
amount_rials: number;
paid_rials: number;
status: PaymentRowStatus;
}
export interface PaymentFilters {
page: number;
national_code?: string;
status?: string; // paid | unsettled
status?: string; // paid | partial | unsettled
from?: number; // unix seconds
to?: number; // unix seconds
}
/** A single invoice status on the detail table (node 2) — two-state. */
export type InvoiceRowStatus = 'paid' | 'unsettled';
/** همان وضعیت مشتق‌شده، روی جدول جزئیات بیمار (node 2). */
export type InvoiceRowStatus = PaymentRowStatus;
export interface PatientInvoiceRow {
uuid: string;
number: number;
issued_at: number;
total_rials: number;
patient_rials: number;
paid_rials: number;
status: InvoiceRowStatus;
service_title: string | null;
items: Array<{ uuid: string; title: string; quantity: number; total_rials: number; patient_rials: number }>;
payments: InvoicePaymentRow[];
}
/** یک پرداخت ثبت‌شده روی مراجعه‌ی همان صورتحساب. */
export interface InvoicePaymentRow {
method: string;
amount_rials: number;
paid_at: number;
created_by_name: string | null;
}
export interface PatientInvoicesPayload {
patient: { uuid: string; name: string | null; national_code: string | null };
data: PatientInvoiceRow[];
summary: PaymentsSummary;
meta: { totalRecords: number; totalPages: number; currentPage: number };
}