From 142d653c6848f22ee91402ec4847837ef7c172ff Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Fri, 17 Jul 2026 15:34:41 +0330 Subject: [PATCH] fix(patient): derive is_paid from remaining, recompute on edit, audit add-payment - is_paid now = remaining_rials == 0 (was payment_method != pending), so adding a service/package after settlement correctly flips the session back to debtor. - updateSessionServices recomputes the cached settlement (payment_method/paid_at) after totals change. - addSessionPayment now records a 'create' audit entry (actor, amount, time). Co-Authored-By: Claude Fable 5 --- src/Patient/Entity/PatientSession.php | 2 +- src/Patient/Service/PatientService.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Patient/Entity/PatientSession.php b/src/Patient/Entity/PatientSession.php index e5a64b80..c36684cd 100644 --- a/src/Patient/Entity/PatientSession.php +++ b/src/Patient/Entity/PatientSession.php @@ -244,7 +244,7 @@ class PatientSession 'services_total_rials' => $this->servicesTotalRials, 'final_price_rials' => $this->finalPriceRials, 'payment_method' => $this->paymentMethod, - 'is_paid' => $this->paymentMethod !== 'pending', + 'is_paid' => $this->getRemainingRials() === 0, 'discount_type' => $this->discountType, 'discount_value' => $this->discountValue, 'discount_rials' => $this->discountRials, diff --git a/src/Patient/Service/PatientService.php b/src/Patient/Service/PatientService.php index 8ce5cb81..6aafbcc5 100644 --- a/src/Patient/Service/PatientService.php +++ b/src/Patient/Service/PatientService.php @@ -369,6 +369,9 @@ class PatientService $session->setFinalPriceRials($priceCalc['final_price_rials'] + $session->getConsumablesTotalRials()); $this->sessionRepo->save($session); + // پس از تغییر مبلغ، وضعیت تسویه بازمحاسبه شود (افزودن سرویس/پکیج → بدهکار). + $this->recomputeSettlement($session); + // ثبت audit برای فیلدهای تغییرکرده $after = [ 'visit_price_rials' => (string) $session->getVisitPriceRials(), @@ -587,6 +590,8 @@ class PatientService } $this->sessionRepo->save($session); + $this->logSessionChange($session, 'payment', \App\Patient\Entity\SessionAuditLog::OP_CREATE, null, (string) $amountRials, $actor, 'ثبت پرداخت'); + return $payment; } }