feat(billing): ensure finalized invoice for confirmed appointments with payments

This commit is contained in:
hamed
2026-08-10 11:10:37 +03:30
parent 505ab412a3
commit 8a18457751
4 changed files with 170 additions and 1 deletions
+11 -1
View File
@@ -43,10 +43,20 @@ class SessionBillingService
}
if ($synced !== null) {
// صورتحسابِ پیش‌نویسِ مراجعه‌ای که پول گرفته، در فهرست پرداخت‌ها دیده نمی‌شود؛
// آن فهرست فقط finalized/paid را می‌آورد.
if ($synced->getStatus() === Invoice::STATUS_DRAFT && $session->getPaidTotalRials() > 0) {
$this->invoiceService->finalize($synced);
}
return $synced;
}
if ($session->getInsuranceBaseId() === null && $session->getInsuranceSupplementaryId() === null) {
// مراجعهٔ بدون بیمه و بدون پرداخت سندی لازم ندارد. ولی به‌محض ثبت پول، باید
// صورتحساب داشته باشد: فهرست «پرداخت‌ها» صورتحساب‌محور است و بدون آن، پولِ
// ثبت‌شده هیچ‌جا دیده نمی‌شد.
$uninsured = $session->getInsuranceBaseId() === null && $session->getInsuranceSupplementaryId() === null;
if ($uninsured && $session->getPaidTotalRials() <= 0) {
return null;
}
+10
View File
@@ -715,6 +715,16 @@ class PatientService
$this->logSessionChange($session, 'payment', \App\Patient\Entity\SessionAuditLog::OP_CREATE, null, (string) $amountRials, $actor, 'ثبت پرداخت');
// پولی که ثبت شد باید در فهرست پرداخت‌ها دیده شود، و آن فهرست صورتحساب‌محور
// است. تنها جای این تضمین همین‌جاست تا هر سه مسیرِ ثبت پرداخت — قطعی‌کردن
// نوبت، صفحهٔ پرداخت مراجعه، و ثبت دستی — یک رفتار داشته باشند.
$recordOwner = $session->getRecord();
$this->sessionBilling->ensureFinalizedInvoice(
$session,
$recordOwner->getEntityType(),
$recordOwner->getEntityId(),
);
return $payment;
}
}