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:
@@ -244,7 +244,7 @@ class PatientSession
|
|||||||
'services_total_rials' => $this->servicesTotalRials,
|
'services_total_rials' => $this->servicesTotalRials,
|
||||||
'final_price_rials' => $this->finalPriceRials,
|
'final_price_rials' => $this->finalPriceRials,
|
||||||
'payment_method' => $this->paymentMethod,
|
'payment_method' => $this->paymentMethod,
|
||||||
'is_paid' => $this->paymentMethod !== 'pending',
|
'is_paid' => $this->getRemainingRials() === 0,
|
||||||
'discount_type' => $this->discountType,
|
'discount_type' => $this->discountType,
|
||||||
'discount_value' => $this->discountValue,
|
'discount_value' => $this->discountValue,
|
||||||
'discount_rials' => $this->discountRials,
|
'discount_rials' => $this->discountRials,
|
||||||
|
|||||||
@@ -369,6 +369,9 @@ class PatientService
|
|||||||
$session->setFinalPriceRials($priceCalc['final_price_rials'] + $session->getConsumablesTotalRials());
|
$session->setFinalPriceRials($priceCalc['final_price_rials'] + $session->getConsumablesTotalRials());
|
||||||
$this->sessionRepo->save($session);
|
$this->sessionRepo->save($session);
|
||||||
|
|
||||||
|
// پس از تغییر مبلغ، وضعیت تسویه بازمحاسبه شود (افزودن سرویس/پکیج → بدهکار).
|
||||||
|
$this->recomputeSettlement($session);
|
||||||
|
|
||||||
// ثبت audit برای فیلدهای تغییرکرده
|
// ثبت audit برای فیلدهای تغییرکرده
|
||||||
$after = [
|
$after = [
|
||||||
'visit_price_rials' => (string) $session->getVisitPriceRials(),
|
'visit_price_rials' => (string) $session->getVisitPriceRials(),
|
||||||
@@ -587,6 +590,8 @@ class PatientService
|
|||||||
}
|
}
|
||||||
$this->sessionRepo->save($session);
|
$this->sessionRepo->save($session);
|
||||||
|
|
||||||
|
$this->logSessionChange($session, 'payment', \App\Patient\Entity\SessionAuditLog::OP_CREATE, null, (string) $amountRials, $actor, 'ثبت پرداخت');
|
||||||
|
|
||||||
return $payment;
|
return $payment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user