fix(patient): populate auto-created session from the confirmed appointment
When an appointment is confirmed, the auto-created PatientSession was saved empty: session_at null, visit_price_rials 0, no service line items, totals 0. Now it copies the visit datetime from the appointment slot, the visit price (falling back to the tenant free-visit price), a SessionService line per appointment service (price snapshot from the service), and computes services_total_rials / final_price_rials. Verified end-to-end. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -131,7 +131,34 @@ class PatientService
|
||||
}
|
||||
|
||||
$session = new PatientSession($record, $appointment);
|
||||
|
||||
// زمان مراجعه = زمان واقعی نوبت.
|
||||
$session->setSessionAt($appointment->getSlotStart());
|
||||
|
||||
// هزینه ویزیت: از نوبت، در نبود آن از «قیمت ویزیت آزاد» تنظیمات همین tenant.
|
||||
$visitPrice = (int) ($appointment->getVisitPriceRials()
|
||||
?? $this->pricingRepo->findOneForInsurance($entityType, $entityId, null)?->getPatientShareRials()
|
||||
?? 0);
|
||||
$session->setVisitPriceRials($visitPrice);
|
||||
|
||||
// خطوط هزینهی سرویس (قیمت snapshot از خود سرویس، بدون ورود دستی).
|
||||
$servicesTotal = 0;
|
||||
$lines = [];
|
||||
foreach ($appointment->getServiceItems() as $item) {
|
||||
$line = new SessionService($session, $item, null, 1);
|
||||
$lines[] = $line;
|
||||
$servicesTotal += $line->getLineTotalRials();
|
||||
}
|
||||
|
||||
$session->setServicesTotalRials($servicesTotal);
|
||||
$session->setFinalPriceRials($servicesTotal + $visitPrice);
|
||||
|
||||
$this->sessionRepo->save($session);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$this->sessionServiceRepo->save($line);
|
||||
$session->addService($line);
|
||||
}
|
||||
}
|
||||
|
||||
public function createSession(
|
||||
|
||||
Reference in New Issue
Block a user