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 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-17 15:34:41 +03:30
co-authored by Claude Fable 5
parent f2ea2ff262
commit 142d653c68
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -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,
+5
View File
@@ -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;
}
}