- 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.
29 lines
1.0 KiB
PHP
29 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Billing\Service;
|
|
|
|
/**
|
|
* وضعیت پرداخت یک صورتحساب.
|
|
*
|
|
* ستون `invoices.status` چرخهی حیات صورتحساب را نگه میدارد (draft → finalized → void)
|
|
* و هرگز به `paid` نمیرود؛ پول واقعی در `session_payments` ثبت میشود. بنابراین وضعیت
|
|
* پرداخت **مشتق** است: مجموع پرداختهای مراجعه در برابر سهم بیمار (`patient_rials`).
|
|
* همینجا تنها مرجع این قاعده است تا نماها از هم واگرا نشوند.
|
|
*/
|
|
final class InvoicePaymentStatus
|
|
{
|
|
public const PAID = 'paid';
|
|
public const PARTIAL = 'partial';
|
|
public const UNSETTLED = 'unsettled';
|
|
|
|
/** @return self::PAID|self::PARTIAL|self::UNSETTLED */
|
|
public static function resolve(int $dueRials, int $paidRials): string
|
|
{
|
|
if ($paidRials >= $dueRials) {
|
|
return self::PAID;
|
|
}
|
|
|
|
return $paidRials > 0 ? self::PARTIAL : self::UNSETTLED;
|
|
}
|
|
}
|